@things-factory/sales-base 7.0.0-alpha.1 → 7.0.0-alpha.13

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/sales-base",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.13",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,17 +24,17 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/attachment-base": "^7.0.0-alpha.1",
28
- "@things-factory/auth-base": "^7.0.0-alpha.1",
29
- "@things-factory/biz-base": "^7.0.0-alpha.1",
30
- "@things-factory/code-base": "^7.0.0-alpha.1",
31
- "@things-factory/integration-sftp": "^7.0.0-alpha.1",
32
- "@things-factory/notification": "^7.0.0-alpha.1",
33
- "@things-factory/product-base": "^7.0.0-alpha.1",
34
- "@things-factory/setting-base": "^7.0.0-alpha.1",
35
- "@things-factory/shell": "^7.0.0-alpha.1",
36
- "@things-factory/transport-base": "^7.0.0-alpha.1",
37
- "@things-factory/warehouse-base": "^7.0.0-alpha.1"
27
+ "@things-factory/attachment-base": "^7.0.0-alpha.9",
28
+ "@things-factory/auth-base": "^7.0.0-alpha.9",
29
+ "@things-factory/biz-base": "^7.0.0-alpha.9",
30
+ "@things-factory/code-base": "^7.0.0-alpha.9",
31
+ "@things-factory/integration-sftp": "^7.0.0-alpha.13",
32
+ "@things-factory/notification": "^7.0.0-alpha.9",
33
+ "@things-factory/product-base": "^7.0.0-alpha.9",
34
+ "@things-factory/setting-base": "^7.0.0-alpha.9",
35
+ "@things-factory/shell": "^7.0.0-alpha.9",
36
+ "@things-factory/transport-base": "^7.0.0-alpha.9",
37
+ "@things-factory/warehouse-base": "^7.0.0-alpha.13"
38
38
  },
39
- "gitHead": "778315d165d7f15e147583a45d5079c3d7cbce38"
39
+ "gitHead": "f4b4bd491776f0a7137bb81862cd6825336716be"
40
40
  }
@@ -5,27 +5,13 @@ import { EntityManager, getConnection, In, Repository } from 'typeorm'
5
5
 
6
6
  import { Attachment, createAttachments } from '@things-factory/attachment-base'
7
7
  import { Role, User } from '@things-factory/auth-base'
8
- import {
9
- Bizplace,
10
- ContactPoint,
11
- getDomainUsers,
12
- getMyBizplace,
13
- getOutletBizplace,
14
- getPermittedBizplaces
15
- } from '@things-factory/biz-base'
8
+ import { Bizplace, ContactPoint, getDomainUsers, getMyBizplace, getOutletBizplace, getPermittedBizplaces } from '@things-factory/biz-base'
16
9
  import { generateId } from '@things-factory/id-rule-base'
17
10
  import { Product } from '@things-factory/product-base'
18
11
  import { PartnerSetting, Setting } from '@things-factory/setting-base'
19
12
  import { Domain, getRepository } from '@things-factory/shell'
20
13
 
21
- import {
22
- ORDER_NUMBER_RULE_TYPE,
23
- ORDER_NUMBER_SETTING_KEY,
24
- ORDER_PRODUCT_STATUS,
25
- ORDER_STATUS,
26
- ORDER_TYPES,
27
- ORDER_VAS_STATUS
28
- } from '../../constants'
14
+ import { ORDER_NUMBER_RULE_TYPE, ORDER_NUMBER_SETTING_KEY, ORDER_PRODUCT_STATUS, ORDER_STATUS, ORDER_TYPES, ORDER_VAS_STATUS } from '../../constants'
29
15
  import { ATTACHMENT_TYPE } from '../../constants/attachment-type'
30
16
  import { ValidationError } from '../../errors'
31
17
  import { OrderNoGenerator } from '../../utils/order-no-generator'
@@ -64,14 +50,7 @@ export class ArrivalNoticeMutation {
64
50
  @Arg('files', type => [GraphQLUpload], { nullable: true }) files?: FileUpload[]
65
51
  ): Promise<ArrivalNotice> {
66
52
  const { tx } = context.state
67
- const createdArrivalNotice: ArrivalNotice = await generateArrivalNoticeFunction(
68
- null,
69
- arrivalNotice,
70
- false,
71
- files,
72
- context,
73
- tx
74
- )
53
+ const createdArrivalNotice: ArrivalNotice = await generateArrivalNoticeFunction(null, arrivalNotice, false, files, context, tx)
75
54
 
76
55
  return createdArrivalNotice
77
56
  }
@@ -223,9 +202,7 @@ export class ArrivalNoticeMutation {
223
202
  @Arg('arrivalNotice', type => ArrivalNoticePatch) arrivalNotice: ArrivalNoticePatch
224
203
  ): Promise<ArrivalNotice> {
225
204
  const { domain, tx } = context.state
226
- let existingArrivalNotice = await tx
227
- .getRepository(ArrivalNotice)
228
- .findOne({ where: { name: arrivalNotice.name, domain: { id: domain.id } } })
205
+ let existingArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({ where: { name: arrivalNotice.name, domain: { id: domain.id } } })
229
206
 
230
207
  if (!existingArrivalNotice) {
231
208
  throw new Error('Existing Arrival Notice not found.')
@@ -252,18 +229,12 @@ export class ArrivalNoticeMutation {
252
229
  let opStatus = ORDER_PRODUCT_STATUS.PENDING_RECEIVE
253
230
  let anStatus = ORDER_STATUS.PENDING_RECEIVE
254
231
 
255
- const foundBizplace: Bizplace = await tx
256
- .getRepository(Bizplace)
257
- .findOne({ where: { id: bizplaceId }, relations: ['domain'] })
232
+ const foundBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({ where: { id: bizplaceId }, relations: ['domain'] })
258
233
 
259
234
  if (!foundBizplace) throw new Error('company not found')
260
235
 
261
236
  // to check whether the raw data are valid
262
- const validatedArrivalNotices: RawArrivalNotice[] = await validateBulkArrivalNoticesFunction(
263
- rawArrivalNotices,
264
- bizplaceId,
265
- tx
266
- )
237
+ const validatedArrivalNotices: RawArrivalNotice[] = await validateBulkArrivalNoticesFunction(rawArrivalNotices, bizplaceId, tx)
267
238
 
268
239
  // check for custom GAN order no setting
269
240
  const ganNoSetting: Setting = await tx.getRepository(Setting).findOne({
@@ -287,9 +258,7 @@ export class ArrivalNoticeMutation {
287
258
 
288
259
  // If status of GAN is PENDING_RECEIVE then directly to assign warehouse
289
260
  if (ganProcessingSetting) {
290
- let setting = !isNaN(partnerGanProcessingSetting?.value)
291
- ? partnerGanProcessingSetting?.value
292
- : ganProcessingSetting.value
261
+ let setting = !isNaN(partnerGanProcessingSetting?.value) ? partnerGanProcessingSetting?.value : ganProcessingSetting.value
293
262
 
294
263
  // CONFIRM to assign if setting value is 1
295
264
  if (setting == 1) {
@@ -326,9 +295,7 @@ export class ArrivalNoticeMutation {
326
295
  // save new arrival notice
327
296
  const createdArrivalNotice: ArrivalNotice = await childTx.getRepository(ArrivalNotice).save({
328
297
  ...arrivalNotices[i],
329
- name: ganNoSetting
330
- ? await generateId({ domain, type: ORDER_NUMBER_RULE_TYPE.GAN_NUMBER, seed: {} })
331
- : OrderNoGenerator.arrivalNotice(),
298
+ name: ganNoSetting ? await generateId({ domain, type: ORDER_NUMBER_RULE_TYPE.GAN_NUMBER, seed: {} }) : OrderNoGenerator.arrivalNotice(),
332
299
  domain,
333
300
  bizplace: foundBizplace,
334
301
  status: ORDER_STATUS.PENDING,
@@ -370,14 +337,10 @@ export class ArrivalNoticeMutation {
370
337
  if (createdArrivalNoticeIds.length && createdOrderProductIds.length) {
371
338
  await getConnection().transaction(async childTx => {
372
339
  // update arrivalNotices status to PENDING_RECEIVE
373
- await childTx
374
- .getRepository(ArrivalNotice)
375
- .update({ id: In(createdArrivalNoticeIds) }, { status: anStatus, updater: user })
340
+ await childTx.getRepository(ArrivalNotice).update({ id: In(createdArrivalNoticeIds) }, { status: anStatus, updater: user })
376
341
 
377
342
  // update orderProducts status to PENDING_RECEIVE
378
- await childTx
379
- .getRepository(OrderProduct)
380
- .update({ id: In(createdOrderProductIds) }, { status: opStatus, updater: user })
343
+ await childTx.getRepository(OrderProduct).update({ id: In(createdOrderProductIds) }, { status: opStatus, updater: user })
381
344
 
382
345
  finalArrivalNoticeList = await childTx.getRepository(ArrivalNotice).find({
383
346
  where: { id: In(createdArrivalNoticeIds) },
@@ -399,12 +362,7 @@ export class ArrivalNoticeMutation {
399
362
  }
400
363
  }
401
364
 
402
- export async function deleteArrivalNotice(
403
- tx: EntityManager,
404
- name: string,
405
- user: User,
406
- domain: Domain
407
- ): Promise<boolean> {
365
+ export async function deleteArrivalNotice(tx: EntityManager, name: string, user: User, domain: Domain): Promise<boolean> {
408
366
  let foundArrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
409
367
  where: { domain: { id: domain.id }, name },
410
368
  relations: ['bizplace', 'releaseGood', 'orderProducts', 'orderVass', 'collectionOrders', 'creator', 'updater']
@@ -492,7 +450,7 @@ export async function generateArrivalNoticeFunction(
492
450
 
493
451
  if (arrivalNotice.supplier) {
494
452
  const supplier: ContactPoint = await tx.getRepository(ContactPoint).findOne({
495
- where: { bizplace: { id: arrivalNotice.supplier.id }, domain: { id: domain.id } },
453
+ where: { id: arrivalNotice.supplier, domain: { id: domain.id } },
496
454
  relations: ['bizplace']
497
455
  })
498
456
 
@@ -579,26 +537,12 @@ export async function generateArrivalNoticeFunction(
579
537
  return createdArrivalNotice
580
538
  }
581
539
 
582
- export async function confirmArrivalNoticeFunction(
583
- name: string,
584
- context: any,
585
- tx?: EntityManager
586
- ): Promise<ArrivalNotice> {
540
+ export async function confirmArrivalNoticeFunction(name: string, context: any, tx?: EntityManager): Promise<ArrivalNotice> {
587
541
  const { user, domain } = context.state
588
542
 
589
543
  const foundArrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
590
544
  where: { domain: { id: domain.id }, name, status: ORDER_STATUS.PENDING },
591
- relations: [
592
- 'bizplace',
593
- 'bizplace.domain',
594
- 'releaseGood',
595
- 'orderProducts',
596
- 'orderProducts.product',
597
- 'orderVass',
598
- 'orderVass.vas',
599
- 'creator',
600
- 'updater'
601
- ]
545
+ relations: ['bizplace', 'bizplace.domain', 'releaseGood', 'orderProducts', 'orderProducts.product', 'orderVass', 'orderVass.vas', 'creator', 'updater']
602
546
  })
603
547
 
604
548
  let foundOPs: OrderProduct[] = foundArrivalNotice.orderProducts
@@ -624,9 +568,7 @@ export async function confirmArrivalNoticeFunction(
624
568
  }
625
569
  })
626
570
 
627
- let setting = !isNaN(partnerGanProcessingSetting?.value)
628
- ? partnerGanProcessingSetting?.value
629
- : ganProcessingSetting.value
571
+ let setting = !isNaN(partnerGanProcessingSetting?.value) ? partnerGanProcessingSetting?.value : ganProcessingSetting.value
630
572
 
631
573
  // CONFIRM to assign if setting value is 1
632
574
  if (setting == 1) {
@@ -706,11 +648,7 @@ export async function confirmArrivalNoticeFunction(
706
648
  return arrivalNotice
707
649
  }
708
650
 
709
- export async function receiveArrivalNoticeFunction(
710
- _: any,
711
- name: string,
712
- context: ResolverContext
713
- ): Promise<ArrivalNotice> {
651
+ export async function receiveArrivalNoticeFunction(_: any, name: string, context: ResolverContext): Promise<ArrivalNotice> {
714
652
  const { user, domain, tx } = context.state
715
653
  try {
716
654
  const foundArrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
@@ -743,9 +681,7 @@ export async function receiveArrivalNoticeFunction(
743
681
  }
744
682
  })
745
683
 
746
- let setting = !isNaN(partnerGanProcessingSetting?.value)
747
- ? partnerGanProcessingSetting?.value
748
- : ganProcessingSetting.value
684
+ let setting = !isNaN(partnerGanProcessingSetting?.value) ? partnerGanProcessingSetting?.value : ganProcessingSetting.value
749
685
 
750
686
  // RECEIVE to assign if setting value is 2
751
687
  if (setting == 2) {
@@ -829,11 +765,7 @@ export async function receiveArrivalNoticeFunction(
829
765
  }
830
766
  }
831
767
 
832
- export async function checkArrivedNoticeFunction(
833
- name: string,
834
- context: any,
835
- tx?: EntityManager
836
- ): Promise<ArrivalNotice> {
768
+ export async function checkArrivedNoticeFunction(name: string, context: any, tx?: EntityManager): Promise<ArrivalNotice> {
837
769
  const { user, domain } = context.state
838
770
  try {
839
771
  const foundArrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
@@ -915,12 +847,7 @@ export async function checkArrivedNoticeFunction(
915
847
  }
916
848
  }
917
849
 
918
- export async function rejectArrivalNotice(
919
- tx: EntityManager,
920
- name: string,
921
- remark: string,
922
- context: any
923
- ): Promise<ArrivalNotice> {
850
+ export async function rejectArrivalNotice(tx: EntityManager, name: string, remark: string, context: any): Promise<ArrivalNotice> {
924
851
  const { user, domain } = context.state
925
852
 
926
853
  const foundArrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
@@ -994,13 +921,7 @@ export async function rejectArrivalNotice(
994
921
  return foundArrivalNotice
995
922
  }
996
923
 
997
- export async function addArrivalNoticeProducts(
998
- domain: Domain,
999
- arrivalNotice: ArrivalNotice,
1000
- newOrderProducts: any[],
1001
- user: User,
1002
- tx?: EntityManager
1003
- ): Promise<void> {
924
+ export async function addArrivalNoticeProducts(domain: Domain, arrivalNotice: ArrivalNotice, newOrderProducts: any[], user: User, tx?: EntityManager): Promise<void> {
1004
925
  const productRepo: Repository<Product> = tx?.getRepository(Product) || getRepository(Product)
1005
926
  const orderProductRepo: Repository<OrderProduct> = tx?.getRepository(OrderProduct) || getRepository(OrderProduct)
1006
927
 
@@ -1029,11 +950,7 @@ export async function addArrivalNoticeProducts(
1029
950
  await orderProductRepo.save(createdOrderProducts)
1030
951
  }
1031
952
 
1032
- export async function editArrivalNoticeProducts(
1033
- existingOrderProducts: (OrderProduct | OrderProductPatch)[],
1034
- user: User,
1035
- tx?: EntityManager
1036
- ): Promise<void> {
953
+ export async function editArrivalNoticeProducts(existingOrderProducts: (OrderProduct | OrderProductPatch)[], user: User, tx?: EntityManager): Promise<void> {
1037
954
  const orderProductRepo: Repository<OrderProduct> = tx?.getRepository(OrderProduct) || getRepository(OrderProduct)
1038
955
 
1039
956
  const updatedOrderProducts: OrderProduct[] = await Promise.all(
@@ -1057,17 +974,7 @@ function extractArrivalNotices(rawArrivalNotices): Partial<ArrivalNotice[]> {
1057
974
 
1058
975
  const idx: number = arrivalNotices.findIndex(an => {
1059
976
  // consider these attributes if they are exist in "item"
1060
- const comparison = [
1061
- 'refNo2',
1062
- 'refNo3',
1063
- 'truckNo',
1064
- 'ownTransport',
1065
- 'container',
1066
- 'containerNo',
1067
- 'containerSize',
1068
- 'looseItem',
1069
- 'importCargo'
1070
- ]
977
+ const comparison = ['refNo2', 'refNo3', 'truckNo', 'ownTransport', 'container', 'containerNo', 'containerSize', 'looseItem', 'importCargo']
1071
978
 
1072
979
  let a: any = {},
1073
980
  b: any = {}
@@ -1103,11 +1010,7 @@ function extractArrivalNotices(rawArrivalNotices): Partial<ArrivalNotice[]> {
1103
1010
 
1104
1011
  if (idx >= 0) {
1105
1012
  const duplicateSkuIdx: number = arrivalNotices[idx].orderProducts.findIndex(
1106
- op =>
1107
- op.sku === raw.sku &&
1108
- op.packingType === raw.packingType &&
1109
- op.packingSize === raw.packingSize &&
1110
- op.batchId === raw.batchId
1013
+ op => op.sku === raw.sku && op.packingType === raw.packingType && op.packingSize === raw.packingSize && op.batchId === raw.batchId
1111
1014
  )
1112
1015
 
1113
1016
  if (duplicateSkuIdx >= 0) arrivalNotices[idx].orderProducts[duplicateSkuIdx].packQty += raw.packQty