@things-factory/warehouse-base 4.3.621 → 4.3.636
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/warehouse-base",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.636",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"@things-factory/biz-base": "^4.3.595",
|
|
27
27
|
"@things-factory/id-rule-base": "^4.3.609",
|
|
28
28
|
"@things-factory/integration-accounting": "^4.3.616",
|
|
29
|
-
"@things-factory/integration-powrup": "^4.3.
|
|
29
|
+
"@things-factory/integration-powrup": "^4.3.626",
|
|
30
30
|
"@things-factory/integration-sellercraft": "^4.3.617",
|
|
31
31
|
"@things-factory/marketplace-base": "^4.3.617",
|
|
32
32
|
"@things-factory/product-base": "^4.3.595",
|
|
33
33
|
"@things-factory/setting-base": "^4.3.609"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "876351704622885dd9c6f5980b37cd12d9702b00"
|
|
36
36
|
}
|
|
@@ -7,6 +7,7 @@ import { Domain } from '@things-factory/shell'
|
|
|
7
7
|
import { Location } from '../location/location'
|
|
8
8
|
import { Warehouse } from '../warehouse/warehouse'
|
|
9
9
|
import { LocationPatch, NewLocation } from './location-types'
|
|
10
|
+
import { QueryFailedError } from 'typeorm'
|
|
10
11
|
|
|
11
12
|
@Resolver(Location)
|
|
12
13
|
export class LocationMutation {
|
|
@@ -103,12 +104,24 @@ export class LocationMutation {
|
|
|
103
104
|
@Mutation(returns => Boolean)
|
|
104
105
|
async deleteAllLocations(@Arg('warehouseId') warehouseId: string, @Ctx() context: any) {
|
|
105
106
|
const { tx }: { tx: EntityManager } = context.state
|
|
106
|
-
|
|
107
|
+
const warehouse = await tx.getRepository(Warehouse).findOne(warehouseId)
|
|
108
|
+
|
|
109
|
+
try{
|
|
110
|
+
await tx.getRepository(Location).delete({warehouse})
|
|
111
|
+
return true
|
|
112
|
+
} catch (err: any) {
|
|
113
|
+
if (err instanceof QueryFailedError) {
|
|
114
|
+
if ((err as any).code === '23503') {
|
|
115
|
+
throw new Error (
|
|
116
|
+
"Some locations are still connected to inventory records. Please contact our support to delete."
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
107
120
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
121
|
+
// For any other unknown errors
|
|
122
|
+
console.error('Failed to delete all locations:', err)
|
|
123
|
+
throw new Error('Failed to delete locations. Please try again or contact support.')
|
|
124
|
+
}
|
|
112
125
|
}
|
|
113
126
|
}
|
|
114
127
|
|
|
@@ -240,6 +253,20 @@ export async function deleteLocations(ids: string[], context: any) {
|
|
|
240
253
|
const { tx }: { tx: EntityManager } = context.state
|
|
241
254
|
|
|
242
255
|
const repository: Repository<Location> = tx.getRepository(Location)
|
|
243
|
-
|
|
244
|
-
|
|
256
|
+
|
|
257
|
+
try{
|
|
258
|
+
await repository.delete(ids)
|
|
259
|
+
return true
|
|
260
|
+
} catch (err: any) {
|
|
261
|
+
if (err instanceof QueryFailedError) {
|
|
262
|
+
// Check if it's a foreign key constraint violation
|
|
263
|
+
if ((err as any).code === '23503') {
|
|
264
|
+
throw new Error(`The location is associated with inventory records. Please contact our support to delete.`)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// For all other errors, throw a generic message
|
|
269
|
+
console.error('Failed to delete location: ', err)
|
|
270
|
+
throw new Error('Failed to delete location. Please try again or contact support.')
|
|
271
|
+
}
|
|
245
272
|
}
|