@things-factory/sales-base 4.3.239 → 4.3.244

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.
Files changed (61) hide show
  1. package/dist-server/constants/order.js +2 -1
  2. package/dist-server/constants/order.js.map +1 -1
  3. package/dist-server/controllers/ecommerce/index.js +1 -0
  4. package/dist-server/controllers/ecommerce/index.js.map +1 -1
  5. package/dist-server/controllers/ecommerce/powrup-controller.js +211 -0
  6. package/dist-server/controllers/ecommerce/powrup-controller.js.map +1 -0
  7. package/dist-server/index.js +1 -0
  8. package/dist-server/index.js.map +1 -1
  9. package/dist-server/service/delivery-order/delivery-order-query.js +2 -2
  10. package/dist-server/service/delivery-order/delivery-order-query.js.map +1 -1
  11. package/dist-server/service/index.js +4 -0
  12. package/dist-server/service/index.js.map +1 -1
  13. package/dist-server/service/order-inventory/order-inventory-query.js +2 -1
  14. package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
  15. package/dist-server/service/order-vas/order-vas-mutation.js +85 -0
  16. package/dist-server/service/order-vas/order-vas-mutation.js.map +1 -1
  17. package/dist-server/service/order-vas/order-vas-query.js +4 -1
  18. package/dist-server/service/order-vas/order-vas-query.js.map +1 -1
  19. package/dist-server/service/order-vas/order-vas-types.js +54 -10
  20. package/dist-server/service/order-vas/order-vas-types.js.map +1 -1
  21. package/dist-server/service/order-vas/order-vas.js +103 -21
  22. package/dist-server/service/order-vas/order-vas.js.map +1 -1
  23. package/dist-server/service/order-vas-item/index.js +9 -0
  24. package/dist-server/service/order-vas-item/index.js.map +1 -0
  25. package/dist-server/service/order-vas-item/order-vas-item-mutation.js +120 -0
  26. package/dist-server/service/order-vas-item/order-vas-item-mutation.js.map +1 -0
  27. package/dist-server/service/order-vas-item/order-vas-item-query.js +99 -0
  28. package/dist-server/service/order-vas-item/order-vas-item-query.js.map +1 -0
  29. package/dist-server/service/order-vas-item/order-vas-item-type.js +111 -0
  30. package/dist-server/service/order-vas-item/order-vas-item-type.js.map +1 -0
  31. package/dist-server/service/order-vas-item/order-vas-item.js +146 -0
  32. package/dist-server/service/order-vas-item/order-vas-item.js.map +1 -0
  33. package/dist-server/service/release-good/release-good-mutation.js +28 -25
  34. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  35. package/dist-server/service/release-good/release-good-query.js +6 -1
  36. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  37. package/dist-server/service/vas/vas.js +8 -6
  38. package/dist-server/service/vas/vas.js.map +1 -1
  39. package/dist-server/service/vas-order/vas-order-mutation.js +2 -2
  40. package/dist-server/service/vas-order/vas-order-mutation.js.map +1 -1
  41. package/package.json +4 -3
  42. package/server/constants/order.ts +2 -1
  43. package/server/controllers/ecommerce/index.ts +1 -0
  44. package/server/controllers/ecommerce/powrup-controller.ts +301 -0
  45. package/server/index.ts +1 -0
  46. package/server/service/delivery-order/delivery-order-query.ts +19 -19
  47. package/server/service/index.ts +4 -0
  48. package/server/service/order-inventory/order-inventory-query.ts +2 -1
  49. package/server/service/order-vas/order-vas-mutation.ts +94 -1
  50. package/server/service/order-vas/order-vas-query.ts +4 -1
  51. package/server/service/order-vas/order-vas-types.ts +34 -1
  52. package/server/service/order-vas/order-vas.ts +89 -10
  53. package/server/service/order-vas-item/index.ts +6 -0
  54. package/server/service/order-vas-item/order-vas-item-mutation.ts +112 -0
  55. package/server/service/order-vas-item/order-vas-item-query.ts +58 -0
  56. package/server/service/order-vas-item/order-vas-item-type.ts +71 -0
  57. package/server/service/order-vas-item/order-vas-item.ts +128 -0
  58. package/server/service/release-good/release-good-mutation.ts +30 -26
  59. package/server/service/release-good/release-good-query.ts +56 -87
  60. package/server/service/vas/vas.ts +11 -5
  61. package/server/service/vas-order/vas-order-mutation.ts +2 -2
@@ -37,7 +37,7 @@ import {
37
37
  ORDER_VAS_STATUS,
38
38
  PRODUCT_GROUP_TYPE
39
39
  } from '../../constants'
40
- import { EcommerceController, SellercraftController } from '../../controllers'
40
+ import { EcommerceController, SellercraftController, PowrupController } from '../../controllers'
41
41
  import { ValidationError } from '../../errors'
42
42
  import { InventoryUtil, OrderNoGenerator } from '../../utils'
43
43
  import { ArrivalNotice } from '../arrival-notice/arrival-notice'
@@ -51,6 +51,7 @@ import { ShippingOrderPatch } from '../shipping-order/shipping-order-types'
51
51
  import { Vas } from '../vas/vas'
52
52
  import { ReleaseGood } from './release-good'
53
53
  import { bulkReleaseGoodsAvailableItemsFunction } from './release-good-query'
54
+ import { OrderVasItem } from '../order-vas-item/order-vas-item'
54
55
 
55
56
  @Resolver(ReleaseGood)
56
57
  export class ReleaseGoodMutation {
@@ -423,6 +424,8 @@ export async function deleteReleaseGood(tx: EntityManager, name: string, user: U
423
424
  // 2. delete order vass
424
425
  const vasIds = foundOVs.map((vas: OrderVas) => vas.id)
425
426
  if (vasIds.length) {
427
+ await tx.getRepository(OrderVasItem).delete({ orderVas: In(vasIds) })
428
+
426
429
  await tx.getRepository(OrderVas).delete({ id: In(vasIds) })
427
430
  }
428
431
 
@@ -829,6 +832,7 @@ export async function generateReleaseGoodFunction(
829
832
  })
830
833
  }
831
834
 
835
+ // VAS
832
836
  if (orderVass?.length) {
833
837
  orderVass = await Promise.all(
834
838
  orderVass.map(async orderVas => {
@@ -940,18 +944,18 @@ export async function confirmReleaseGood(name: string, context: any, tx?: Entity
940
944
  }
941
945
  }
942
946
 
943
- // const customerBizplaceId: string = foundReleaseGood.bizplace.id
944
- // const companyBizplace: Bizplace = await getCompanyBizplace(domain, null, customerBizplaceId, tx)
945
- // const powrup: Powrup = await tx
946
- // .getRepository(Application)
947
- // .findOne({ domain: companyBizplace.domain, status: 'ACTIVE' })
947
+ const customerBizplaceId: string = foundReleaseGood.bizplace.id
948
+ const companyBizplace: Bizplace = await getCompanyBizplace(domain, null, customerBizplaceId, tx)
949
+ const application: Application = await tx
950
+ .getRepository(Application)
951
+ .findOne({ domain: companyBizplace.domain, status: 'ACTIVE', type: ApplicationType.POWRUP })
948
952
 
949
- // let updatePowrupStock = async powrup => {
950
- // if (powrup) {
951
- // const powrupController: PowrupController = new PowrupController(tx, domain, user)
952
- // await powrupController.updateStock(powrup, foundOPs)
953
- // }
954
- // }
953
+ let updatePowrupStock = async powrup => {
954
+ if (application) {
955
+ const powrupController: PowrupController = new PowrupController()
956
+ await powrupController.updateStock(foundOPs, domain, user, tx)
957
+ }
958
+ }
955
959
 
956
960
  const orderSource: string = foundReleaseGood.source
957
961
  switch (orderSource) {
@@ -1038,9 +1042,9 @@ export async function confirmReleaseGood(name: string, context: any, tx?: Entity
1038
1042
  updateSCStock(sellercraft)
1039
1043
  break
1040
1044
 
1041
- // case ApplicationType.POWRUP:
1042
- // updatePowrupStock(powrup)
1043
- // break
1045
+ case ApplicationType.POWRUP:
1046
+ updatePowrupStock(application)
1047
+ break
1044
1048
 
1045
1049
  default:
1046
1050
  updateSCStock(sellercraft)
@@ -1275,18 +1279,18 @@ export async function rejectReleaseGood(
1275
1279
  }
1276
1280
  break
1277
1281
 
1278
- // case ApplicationType.POWRUP:
1279
- // const customerBizplaceId: string = releaseGood.bizplace.id
1280
- // const companyBizplace: Bizplace = await getCompanyBizplace(domain, null, customerBizplaceId, tx)
1281
- // const powrup: Powrup = await tx
1282
- // .getRepository(Application)
1283
- // .findOne({ domain: companyBizplace.domain, status: 'ACTIVE' })
1282
+ case ApplicationType.POWRUP:
1283
+ const customerBizplaceId: string = releaseGood.bizplace.id
1284
+ const companyBizplace: Bizplace = await getCompanyBizplace(domain, null, customerBizplaceId, tx)
1285
+ const application: Application = await tx
1286
+ .getRepository(Application)
1287
+ .findOne({ domain: companyBizplace.domain, status: 'ACTIVE', type: ApplicationType.POWRUP })
1284
1288
 
1285
- // if (powrup) {
1286
- // const powrupController: PowrupController = new PowrupController(tx, domain, user)
1287
- // await powrupController.updateStock(powrup, foundOPs)
1288
- // }
1289
- // break
1289
+ if (application) {
1290
+ const powrupController: PowrupController = new PowrupController()
1291
+ await powrupController.updateStock(foundOPs, companyBizplace.domain, user, tx)
1292
+ }
1293
+ break
1290
1294
 
1291
1295
  default:
1292
1296
  break
@@ -1,60 +1,19 @@
1
- import {
2
- Arg,
3
- Args,
4
- Ctx,
5
- Directive,
6
- FieldResolver,
7
- Query,
8
- Resolver,
9
- Root
10
- } from 'type-graphql'
11
- import {
12
- EntityManager,
13
- getRepository,
14
- In,
15
- Repository,
16
- SelectQueryBuilder
17
- } from 'typeorm'
1
+ import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
+ import { EntityManager, getRepository, In, Repository, SelectQueryBuilder } from 'typeorm'
18
3
 
19
4
  import { Attachment } from '@things-factory/attachment-base'
20
- import {
21
- checkUserBelongsDomain,
22
- User
23
- } from '@things-factory/auth-base'
24
- import {
25
- Bizplace,
26
- getCompanyBizplace,
27
- getMyBizplace,
28
- getPermittedBizplaceIds
29
- } from '@things-factory/biz-base'
5
+ import { checkUserBelongsDomain, User } from '@things-factory/auth-base'
6
+ import { Bizplace, getCompanyBizplace, getMyBizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
30
7
  import { logger } from '@things-factory/env'
31
- import {
32
- buildQuery,
33
- Domain,
34
- Filter,
35
- ListParam,
36
- Pagination,
37
- Sorting
38
- } from '@things-factory/shell'
39
- import {
40
- Inventory,
41
- LOCATION_TYPE
42
- } from '@things-factory/warehouse-base'
43
-
44
- import {
45
- ATTACHMENT_TYPE,
46
- ORDER_INVENTORY_STATUS,
47
- ORDER_STATUS
48
- } from '../../constants'
8
+ import { buildQuery, Domain, Filter, ListParam, Pagination, Sorting } from '@things-factory/shell'
9
+ import { Inventory, LOCATION_TYPE } from '@things-factory/warehouse-base'
10
+
11
+ import { ATTACHMENT_TYPE, ORDER_INVENTORY_STATUS, ORDER_STATUS } from '../../constants'
49
12
  import { OrderInventory } from '../order-inventory/order-inventory'
50
13
  import { OrderPackage } from '../order-package/order-package'
51
14
  import { ShippingOrder } from '../shipping-order/shipping-order'
52
15
  import { ReleaseGood } from './release-good'
53
- import {
54
- NewReleaseGood,
55
- ReleasableInventoryList,
56
- ReleaseGoodList
57
- } from './release-good-types'
16
+ import { NewReleaseGood, ReleasableInventoryList, ReleaseGoodList } from './release-good-types'
58
17
 
59
18
  @Resolver(ReleaseGood)
60
19
  export class ReleaseGoodQuery {
@@ -227,8 +186,13 @@ export class ReleaseGoodQuery {
227
186
  'orderPackages',
228
187
  'orderVass',
229
188
  'orderVass.vas',
230
- 'orderVass.targetProduct',
189
+ 'orderVass.newProduct',
190
+ 'orderVass.newProductDetail',
191
+ 'orderVass.product',
192
+ 'orderVass.productDetail',
231
193
  'orderVass.inventory',
194
+ 'orderVass.orderVasItems',
195
+ 'orderVass.orderVasItems.vas',
232
196
  'creator',
233
197
  'updater'
234
198
  ]
@@ -475,10 +439,12 @@ export class ReleaseGoodQuery {
475
439
  )
476
440
 
477
441
  if (transporterFilter) {
478
- qb.andWhere(`exists (select id from order_packages op where
442
+ qb.andWhere(
443
+ `exists (select id from order_packages op where
479
444
  op.release_good_id = rg.id
480
- and op.transporter ilike :transporter)`, { transporter: transporterFilter.value })
481
-
445
+ and op.transporter ilike :transporter)`,
446
+ { transporter: transporterFilter.value }
447
+ )
482
448
  }
483
449
 
484
450
  if (skuFilter) {
@@ -558,12 +524,12 @@ export class ReleaseGoodQuery {
558
524
  ...item,
559
525
  transporter: orderPackages?.length
560
526
  ? [
561
- ...new Set(
562
- orderPackages.map(op => {
563
- return op.transporter
564
- })
565
- )
566
- ].join(', ')
527
+ ...new Set(
528
+ orderPackages.map(op => {
529
+ return op.transporter
530
+ })
531
+ )
532
+ ].join(', ')
567
533
  : null,
568
534
  orderRemark: item?.remark ? true : false
569
535
  }
@@ -629,24 +595,27 @@ export class ReleaseGoodQuery {
629
595
  ${batchId ? `AND LOWER(${INV_ALIAS}.batch_id) LIKE '%${batchId.toLowerCase()}%'` : ''}
630
596
  ${packingType ? `AND LOWER(${INV_ALIAS}.packing_type) LIKE '%${packingType.toLowerCase()}%'` : ''}
631
597
  ${containerNo ? `AND LOWER(${GAN_ALIAS}.container_no) LIKE '%${containerNo.toLowerCase()}%'` : ''}
632
- ${product?.length > 0 && product[0]
633
- ? `AND ${PROD_ALIAS}.id IN (${product.map((id: string) => `'${id}'`).join(', ')})`
634
- : product[0] === null
635
- ? `AND ${PROD_ALIAS}.id isnull`
636
- : ''
637
- }
638
- ${inventory?.length > 0
639
- ? `
640
- AND (${INV_ALIAS}.batch_id, ${PROD_ALIAS}.id) ${filters.find((filter: { name: string; operator: string; value: any }) => filter.name === 'inventory')
641
- .operator
642
- } (
598
+ ${
599
+ product?.length > 0 && product[0]
600
+ ? `AND ${PROD_ALIAS}.id IN (${product.map((id: string) => `'${id}'`).join(', ')})`
601
+ : product[0] === null
602
+ ? `AND ${PROD_ALIAS}.id isnull`
603
+ : ''
604
+ }
605
+ ${
606
+ inventory?.length > 0
607
+ ? `
608
+ AND (${INV_ALIAS}.batch_id, ${PROD_ALIAS}.id) ${
609
+ filters.find((filter: { name: string; operator: string; value: any }) => filter.name === 'inventory')
610
+ .operator
611
+ } (
643
612
  ${inventory
644
- .map((inv: { batchId: string; productId: string }) => `('${inv.batchId}', '${inv.productId}')`)
645
- .join(', ')}
613
+ .map((inv: { batchId: string; productId: string }) => `('${inv.batchId}', '${inv.productId}')`)
614
+ .join(', ')}
646
615
  )
647
616
  `
648
- : ''
649
- }
617
+ : ''
618
+ }
650
619
  `
651
620
 
652
621
  // ${product?.length > 0 ? `AND ${PROD_ALIAS}.id IN (${product.map((id: string) => id ? `'${id}'` : null).join(', ')})` : ''}
@@ -1004,18 +973,18 @@ function _extractData(rawData, validatedData) {
1004
973
  !raw.productId || !raw.productDetailId
1005
974
  ? 'inventory or product not found'
1006
975
  : raw.releaseQty <= 0 || raw.releaseQty % 1 != 0
1007
- ? 'invalid release qty'
1008
- : raw.assignedQty < raw.releaseQty
1009
- ? 'insufficient stock'
1010
- : raw.releaseDate == ''
1011
- ? 'release date is empty'
1012
- : releaseDate < _getStdDateStr(new Date())
1013
- ? 'backdate is not allowed'
1014
- : !raw.refNo
1015
- ? 'ref no is empty'
1016
- : !Number.isInteger(raw.packingSize)
1017
- ? 'packing size must be an integer'
1018
- : ''
976
+ ? 'invalid release qty'
977
+ : raw.assignedQty < raw.releaseQty
978
+ ? 'insufficient stock'
979
+ : raw.releaseDate == ''
980
+ ? 'release date is empty'
981
+ : releaseDate < _getStdDateStr(new Date())
982
+ ? 'backdate is not allowed'
983
+ : !raw.refNo
984
+ ? 'ref no is empty'
985
+ : !Number.isInteger(raw.packingSize)
986
+ ? 'packing size must be an integer'
987
+ : ''
1019
988
  }
1020
989
  })
1021
990
  }
@@ -13,7 +13,8 @@ import {
13
13
  } from 'typeorm'
14
14
 
15
15
  @Entity('vass')
16
- @Index('ix_vas_0', (vas: Vas) => [vas.domain, vas.name], { unique: true })
16
+ // name can be the same , thus, removing the validation here
17
+ // @Index('ix_vas_0', (vas: Vas) => [vas.domain, vas.name], { unique: true })
17
18
  @ObjectType()
18
19
  export class Vas {
19
20
  @PrimaryGeneratedColumn('uuid')
@@ -35,10 +36,12 @@ export class Vas {
35
36
  @Field({ nullable: true })
36
37
  description: string
37
38
 
38
- @Column()
39
- @Field()
39
+ //can be removed
40
+ @Column({ nullable: true })
41
+ @Field({ nullable: true })
40
42
  currency: string
41
43
 
44
+ //can be removed
42
45
  @Column({ nullable: true })
43
46
  @Field({ nullable: true })
44
47
  uom: string
@@ -47,14 +50,17 @@ export class Vas {
47
50
  @Field({ nullable: true })
48
51
  type: string
49
52
 
50
- @Column('float')
51
- @Field()
53
+ //can be removed
54
+ @Column('float', { nullable: true })
55
+ @Field({ nullable: true })
52
56
  defaultPrice: number
53
57
 
58
+ //can be removed
54
59
  @Column({ nullable: true })
55
60
  @Field({ nullable: true })
56
61
  operationGuideType: string
57
62
 
63
+ //can be removed
58
64
  @Column({ nullable: true })
59
65
  @Field({ nullable: true })
60
66
  operationGuide: string
@@ -81,8 +81,8 @@ export class VasOrderMutation {
81
81
  // 2. Create VasOrder vas
82
82
  orderVass = await Promise.all(
83
83
  orderVass.map(async (ov: OrderVas) => {
84
- if (ov?.targetProduct?.id) {
85
- ov.targetProduct = await tx.getRepository(Product).findOne(ov.targetProduct.id)
84
+ if (ov?.product?.id) {
85
+ ov.product = await tx.getRepository(Product).findOne(ov.product.id)
86
86
  }
87
87
  return {
88
88
  ...ov,