@things-factory/warehouse-base 4.3.512 → 4.3.515
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/dist-server/service/inventory-history/inventory-history-query.js +2 -2
- package/dist-server/service/location/location-mutation.js +50 -3
- package/dist-server/service/location/location-mutation.js.map +1 -1
- package/package.json +2 -2
- package/server/service/inventory-history/inventory-history-query.ts +2 -2
- package/server/service/location/location-mutation.ts +65 -18
|
@@ -1525,7 +1525,7 @@ async function massageInventoryPalletSummary(tx, params, bizplace, context) {
|
|
|
1525
1525
|
else 0 end
|
|
1526
1526
|
else 0 end) as opening_qty,
|
|
1527
1527
|
SUM(case when invHistory.created_at >= $1 and invHistory.created_at <= $2 then
|
|
1528
|
-
case when (invHistory.transaction_type = 'UNLOADING' or invHistory.transaction_type = 'NEW') then 1 else 0 end
|
|
1528
|
+
case when (invHistory.transaction_type = 'UNLOADING' or invHistory.transaction_type = 'NEW' or invHistory.transaction_type = 'CANCEL_ORDER') then 1 else 0 end
|
|
1529
1529
|
else 0 end) as total_in_qty,
|
|
1530
1530
|
SUM(case when invHistory.created_at >= $1 and invHistory.created_at <= $2 then
|
|
1531
1531
|
case when invHistory.status = 'TERMINATED' AND invHistory.transaction_type <> 'ADJUSTMENT' then -1 else 0 end
|
|
@@ -1541,7 +1541,7 @@ async function massageInventoryPalletSummary(tx, params, bizplace, context) {
|
|
|
1541
1541
|
prd.sku as product_sku, prd.name as product_name, prd.description as product_description, prd.type AS product_type
|
|
1542
1542
|
from temp_inv_history invh
|
|
1543
1543
|
inner join temp_products prd on prd.id = invh.product_id
|
|
1544
|
-
where (transaction_type = 'UNLOADING' or invh.transaction_type = 'NEW')
|
|
1544
|
+
where (transaction_type = 'UNLOADING' or invh.transaction_type = 'NEW' or invh.transaction_type = 'CANCEL_ORDER')
|
|
1545
1545
|
and invh.created_at >= $1
|
|
1546
1546
|
) as invIn where rn = 1
|
|
1547
1547
|
union all
|
|
@@ -155,7 +155,7 @@ async function createLocation(location, context) {
|
|
|
155
155
|
const { domain, user, tx } = context.state;
|
|
156
156
|
const locationRepository = tx.getRepository(location_1.Location);
|
|
157
157
|
const warehouseRepository = tx.getRepository(warehouse_1.Warehouse);
|
|
158
|
-
const foundLocation = await
|
|
158
|
+
const foundLocation = await locationRepository.findOne({
|
|
159
159
|
where: [
|
|
160
160
|
{
|
|
161
161
|
domain,
|
|
@@ -171,23 +171,70 @@ async function createLocation(location, context) {
|
|
|
171
171
|
zone: location.zone,
|
|
172
172
|
column: location.column,
|
|
173
173
|
shelf: location.shelf
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
domain,
|
|
177
|
+
name: location.name
|
|
174
178
|
}
|
|
175
179
|
]
|
|
176
180
|
});
|
|
181
|
+
//name found in db is the same as the one passed by the user
|
|
182
|
+
if (foundLocation && (foundLocation === null || foundLocation === void 0 ? void 0 : foundLocation.id) && (foundLocation === null || foundLocation === void 0 ? void 0 : foundLocation.name) === (location === null || location === void 0 ? void 0 : location.name)) {
|
|
183
|
+
throw new Error(`Duplicates name found: ${foundLocation.name}`);
|
|
184
|
+
}
|
|
177
185
|
if (foundLocation) {
|
|
178
|
-
throw new Error(
|
|
186
|
+
throw new Error(`Existing location found: ${foundLocation.name}`);
|
|
179
187
|
}
|
|
180
188
|
return await locationRepository.save(Object.assign(Object.assign({}, location), { warehouse: await warehouseRepository.findOne(location.warehouse.id), domain, creator: user, updater: user }));
|
|
181
189
|
}
|
|
182
190
|
exports.createLocation = createLocation;
|
|
183
191
|
async function updateLocation(id, patch, context) {
|
|
184
|
-
|
|
192
|
+
var _a, _b, _c, _d;
|
|
193
|
+
const { user, domain, tx } = context.state;
|
|
185
194
|
const locationRepository = tx.getRepository(location_1.Location);
|
|
186
195
|
const warehouseRepository = tx.getRepository(warehouse_1.Warehouse);
|
|
187
196
|
const location = await locationRepository.findOne(id);
|
|
188
197
|
if (patch.warehouse && patch.warehouse.id) {
|
|
189
198
|
patch.warehouse = await warehouseRepository.findOne(patch.warehouse.id);
|
|
190
199
|
}
|
|
200
|
+
const propertiesValidation = {
|
|
201
|
+
keys: ['zone', 'shelf', 'row', 'column'],
|
|
202
|
+
changeName: false,
|
|
203
|
+
changeZone: false
|
|
204
|
+
};
|
|
205
|
+
Object.keys(patch).forEach(prop => {
|
|
206
|
+
if (propertiesValidation.keys.includes(prop)) {
|
|
207
|
+
location[prop] = patch[prop];
|
|
208
|
+
propertiesValidation.changeZone = true;
|
|
209
|
+
}
|
|
210
|
+
if (['name'].includes(prop)) {
|
|
211
|
+
location[prop] = patch[prop];
|
|
212
|
+
propertiesValidation.changeName = true;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
let queryConditions = '';
|
|
216
|
+
//if got changes to name but no changes to the zone,row,column and shelf
|
|
217
|
+
if (propertiesValidation.changeName) {
|
|
218
|
+
queryConditions += `or (name = $2)`;
|
|
219
|
+
}
|
|
220
|
+
//if name no changes, but have changes to zone,row,column and shelf
|
|
221
|
+
if (propertiesValidation.changeZone) {
|
|
222
|
+
queryConditions += `or (zone = $3 AND "row" = $4 AND "column" = $5 AND shelf = $6)`;
|
|
223
|
+
}
|
|
224
|
+
//validation if no changes to name,zone,row,column,shelf but have changes to type,status
|
|
225
|
+
if (queryConditions !== '') {
|
|
226
|
+
const foundLocation = await tx.query(`Select * from locations
|
|
227
|
+
where domain_id = $1
|
|
228
|
+
and ((name = $2 AND zone = $3 AND "row" = $4 AND "column" = $5 AND shelf = $6) ${queryConditions})
|
|
229
|
+
limit 1
|
|
230
|
+
`, [domain.id, location.name, location.zone, location.row, location.column, location.shelf]);
|
|
231
|
+
if ((foundLocation === null || foundLocation === void 0 ? void 0 : foundLocation.length) > 0 && ((_a = foundLocation[0]) === null || _a === void 0 ? void 0 : _a.name) === (patch === null || patch === void 0 ? void 0 : patch.name) && ((_b = foundLocation[0]) === null || _b === void 0 ? void 0 : _b.id) !== id) {
|
|
232
|
+
throw new Error(`Duplicates name found: ${(_c = foundLocation[0]) === null || _c === void 0 ? void 0 : _c.name}`);
|
|
233
|
+
}
|
|
234
|
+
if ((foundLocation === null || foundLocation === void 0 ? void 0 : foundLocation.length) > 0) {
|
|
235
|
+
throw new Error(`Existing location found: ${(_d = foundLocation[0]) === null || _d === void 0 ? void 0 : _d.name}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
191
238
|
return await locationRepository.save(Object.assign(Object.assign(Object.assign({}, location), patch), { updater: user }));
|
|
192
239
|
}
|
|
193
240
|
exports.updateLocation = updateLocation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location-mutation.js","sourceRoot":"","sources":["../../../server/service/location/location-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"location-mutation.js","sourceRoot":"","sources":["../../../server/service/location/location-mutation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAsE;AAMtE,mDAA+C;AAC/C,sDAAkD;AAClD,qDAA6D;AAGtD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAIrB,AAAN,KAAK,CAAC,cAAc,CAAkB,QAAqB,EAAS,OAAY;QAC9E,OAAO,MAAM,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAChD,CAAC;IAKK,AAAN,KAAK,CAAC,sBAAsB,CACe,OAAwB,EAC1D,OAAY;QAEnB,IAAI,OAAO,GAAG,EAAE,CAAA;QAChB,MAAM,cAAc,GAAG,OAAO;aAC3B,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,GAAG,CAAC;aAC5C,GAAG,CAAC,CAAC,CAAC,EAAE;YACP,OAAO,CAAC,CAAC,EAAE,CAAA;YACX,yBAAY,CAAC,EAAE;QACjB,CAAC,CAAC,CAAA;QAEJ,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;YAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc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AAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAC5B,OAAO,IAAI,CAAA;AACb,CAAC;AAND,0CAMC"}
|
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.515",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"@things-factory/product-base": "^4.3.495",
|
|
33
33
|
"@things-factory/setting-base": "^4.3.452"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "f916cbe75616628eadc2efbeead208978e43b50e"
|
|
36
36
|
}
|
|
@@ -1714,7 +1714,7 @@ async function massageInventoryPalletSummary(tx: EntityManager, params: ListPara
|
|
|
1714
1714
|
else 0 end
|
|
1715
1715
|
else 0 end) as opening_qty,
|
|
1716
1716
|
SUM(case when invHistory.created_at >= $1 and invHistory.created_at <= $2 then
|
|
1717
|
-
case when (invHistory.transaction_type = 'UNLOADING' or invHistory.transaction_type = 'NEW') then 1 else 0 end
|
|
1717
|
+
case when (invHistory.transaction_type = 'UNLOADING' or invHistory.transaction_type = 'NEW' or invHistory.transaction_type = 'CANCEL_ORDER') then 1 else 0 end
|
|
1718
1718
|
else 0 end) as total_in_qty,
|
|
1719
1719
|
SUM(case when invHistory.created_at >= $1 and invHistory.created_at <= $2 then
|
|
1720
1720
|
case when invHistory.status = 'TERMINATED' AND invHistory.transaction_type <> 'ADJUSTMENT' then -1 else 0 end
|
|
@@ -1730,7 +1730,7 @@ async function massageInventoryPalletSummary(tx: EntityManager, params: ListPara
|
|
|
1730
1730
|
prd.sku as product_sku, prd.name as product_name, prd.description as product_description, prd.type AS product_type
|
|
1731
1731
|
from temp_inv_history invh
|
|
1732
1732
|
inner join temp_products prd on prd.id = invh.product_id
|
|
1733
|
-
where (transaction_type = 'UNLOADING' or invh.transaction_type = 'NEW')
|
|
1733
|
+
where (transaction_type = 'UNLOADING' or invh.transaction_type = 'NEW' or invh.transaction_type = 'CANCEL_ORDER')
|
|
1734
1734
|
and invh.created_at >= $1
|
|
1735
1735
|
) as invIn where rn = 1
|
|
1736
1736
|
union all
|
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Ctx,
|
|
4
|
-
Directive,
|
|
5
|
-
Mutation,
|
|
6
|
-
Resolver
|
|
7
|
-
} from 'type-graphql'
|
|
8
|
-
import {
|
|
9
|
-
EntityManager,
|
|
10
|
-
Repository
|
|
11
|
-
} from 'typeorm'
|
|
1
|
+
import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
|
|
2
|
+
import { EntityManager, Repository } from 'typeorm'
|
|
12
3
|
|
|
13
4
|
import { User } from '@things-factory/auth-base'
|
|
14
5
|
import { Domain } from '@things-factory/shell'
|
|
15
6
|
|
|
16
7
|
import { Location } from '../location/location'
|
|
17
8
|
import { Warehouse } from '../warehouse/warehouse'
|
|
18
|
-
import {
|
|
19
|
-
LocationPatch,
|
|
20
|
-
NewLocation
|
|
21
|
-
} from './location-types'
|
|
9
|
+
import { LocationPatch, NewLocation } from './location-types'
|
|
22
10
|
|
|
23
11
|
@Resolver(Location)
|
|
24
12
|
export class LocationMutation {
|
|
@@ -130,7 +118,7 @@ export async function createLocation(location: NewLocation, context: any) {
|
|
|
130
118
|
const locationRepository: Repository<Location> = tx.getRepository(Location)
|
|
131
119
|
const warehouseRepository: Repository<Warehouse> = tx.getRepository(Warehouse)
|
|
132
120
|
|
|
133
|
-
const foundLocation: Location = await
|
|
121
|
+
const foundLocation: Location = await locationRepository.findOne({
|
|
134
122
|
where: [
|
|
135
123
|
{
|
|
136
124
|
domain,
|
|
@@ -146,12 +134,21 @@ export async function createLocation(location: NewLocation, context: any) {
|
|
|
146
134
|
zone: location.zone,
|
|
147
135
|
column: location.column,
|
|
148
136
|
shelf: location.shelf
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
domain,
|
|
140
|
+
name: location.name
|
|
149
141
|
}
|
|
150
142
|
]
|
|
151
143
|
})
|
|
152
144
|
|
|
145
|
+
//name found in db is the same as the one passed by the user
|
|
146
|
+
if (foundLocation && foundLocation?.id && foundLocation?.name === location?.name) {
|
|
147
|
+
throw new Error(`Duplicates name found: ${foundLocation.name}`)
|
|
148
|
+
}
|
|
149
|
+
|
|
153
150
|
if (foundLocation) {
|
|
154
|
-
throw new Error(
|
|
151
|
+
throw new Error(`Existing location found: ${foundLocation.name}`)
|
|
155
152
|
}
|
|
156
153
|
|
|
157
154
|
return await locationRepository.save({
|
|
@@ -164,7 +161,7 @@ export async function createLocation(location: NewLocation, context: any) {
|
|
|
164
161
|
}
|
|
165
162
|
|
|
166
163
|
export async function updateLocation(id: string, patch: LocationPatch, context: any) {
|
|
167
|
-
const { user, tx }: { user: User; tx: EntityManager } = context.state
|
|
164
|
+
const { user, domain, tx }: { user: User; domain: Domain; tx: EntityManager } = context.state
|
|
168
165
|
|
|
169
166
|
const locationRepository: Repository<Location> = tx.getRepository(Location)
|
|
170
167
|
const warehouseRepository: Repository<Warehouse> = tx.getRepository(Warehouse)
|
|
@@ -174,6 +171,56 @@ export async function updateLocation(id: string, patch: LocationPatch, context:
|
|
|
174
171
|
patch.warehouse = await warehouseRepository.findOne(patch.warehouse.id)
|
|
175
172
|
}
|
|
176
173
|
|
|
174
|
+
const propertiesValidation = {
|
|
175
|
+
keys: ['zone', 'shelf', 'row', 'column'],
|
|
176
|
+
changeName: false,
|
|
177
|
+
changeZone: false
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
Object.keys(patch).forEach(prop => {
|
|
181
|
+
if (propertiesValidation.keys.includes(prop)) {
|
|
182
|
+
location[prop] = patch[prop]
|
|
183
|
+
propertiesValidation.changeZone = true
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (['name'].includes(prop)) {
|
|
187
|
+
location[prop] = patch[prop]
|
|
188
|
+
propertiesValidation.changeName = true
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
let queryConditions = ''
|
|
193
|
+
|
|
194
|
+
//if got changes to name but no changes to the zone,row,column and shelf
|
|
195
|
+
if (propertiesValidation.changeName) {
|
|
196
|
+
queryConditions += `or (name = $2)`
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//if name no changes, but have changes to zone,row,column and shelf
|
|
200
|
+
if (propertiesValidation.changeZone) {
|
|
201
|
+
queryConditions += `or (zone = $3 AND "row" = $4 AND "column" = $5 AND shelf = $6)`
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//validation if no changes to name,zone,row,column,shelf but have changes to type,status
|
|
205
|
+
if (queryConditions !== '') {
|
|
206
|
+
const foundLocation = await tx.query(
|
|
207
|
+
`Select * from locations
|
|
208
|
+
where domain_id = $1
|
|
209
|
+
and ((name = $2 AND zone = $3 AND "row" = $4 AND "column" = $5 AND shelf = $6) ${queryConditions})
|
|
210
|
+
limit 1
|
|
211
|
+
`,
|
|
212
|
+
[domain.id, location.name, location.zone, location.row, location.column, location.shelf]
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
if (foundLocation?.length > 0 && foundLocation[0]?.name === patch?.name && foundLocation[0]?.id !== id) {
|
|
216
|
+
throw new Error(`Duplicates name found: ${foundLocation[0]?.name}`)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (foundLocation?.length > 0) {
|
|
220
|
+
throw new Error(`Existing location found: ${foundLocation[0]?.name}`)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
177
224
|
return await locationRepository.save({
|
|
178
225
|
...location,
|
|
179
226
|
...patch,
|