@things-factory/warehouse-base 4.1.31 → 4.1.35

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 (46) hide show
  1. package/dist-server/constants/inventory.js +8 -2
  2. package/dist-server/constants/inventory.js.map +1 -1
  3. package/dist-server/service/index.js +5 -0
  4. package/dist-server/service/index.js.map +1 -1
  5. package/dist-server/service/inventory/inventory-query.js +100 -1
  6. package/dist-server/service/inventory/inventory-query.js.map +1 -1
  7. package/dist-server/service/inventory/inventory.js +10 -0
  8. package/dist-server/service/inventory/inventory.js.map +1 -1
  9. package/dist-server/service/inventory-item/index.js +9 -0
  10. package/dist-server/service/inventory-item/index.js.map +1 -0
  11. package/dist-server/service/inventory-item/inventory-item-mutation.js +207 -0
  12. package/dist-server/service/inventory-item/inventory-item-mutation.js.map +1 -0
  13. package/dist-server/service/inventory-item/inventory-item-query.js +150 -0
  14. package/dist-server/service/inventory-item/inventory-item-query.js.map +1 -0
  15. package/dist-server/service/inventory-item/inventory-item-type.js +115 -0
  16. package/dist-server/service/inventory-item/inventory-item-type.js.map +1 -0
  17. package/dist-server/service/inventory-item/inventory-item.js +124 -0
  18. package/dist-server/service/inventory-item/inventory-item.js.map +1 -0
  19. package/dist-server/service/inventory-product/index.js +9 -0
  20. package/dist-server/service/inventory-product/index.js.map +1 -0
  21. package/dist-server/service/inventory-product/inventory-product-mutation.js +120 -0
  22. package/dist-server/service/inventory-product/inventory-product-mutation.js.map +1 -0
  23. package/dist-server/service/inventory-product/inventory-product-query.js +87 -0
  24. package/dist-server/service/inventory-product/inventory-product-query.js.map +1 -0
  25. package/dist-server/service/inventory-product/inventory-product-type.js +95 -0
  26. package/dist-server/service/inventory-product/inventory-product-type.js.map +1 -0
  27. package/dist-server/service/inventory-product/inventory-product.js +107 -0
  28. package/dist-server/service/inventory-product/inventory-product.js.map +1 -0
  29. package/dist-server/utils/inventory-no-generator.js +3 -0
  30. package/dist-server/utils/inventory-no-generator.js.map +1 -1
  31. package/package.json +5 -5
  32. package/server/constants/inventory.ts +8 -1
  33. package/server/service/index.ts +5 -0
  34. package/server/service/inventory/inventory-query.ts +114 -0
  35. package/server/service/inventory/inventory.ts +8 -0
  36. package/server/service/inventory-item/index.ts +6 -0
  37. package/server/service/inventory-item/inventory-item-mutation.ts +210 -0
  38. package/server/service/inventory-item/inventory-item-query.ts +118 -0
  39. package/server/service/inventory-item/inventory-item-type.ts +74 -0
  40. package/server/service/inventory-item/inventory-item.ts +99 -0
  41. package/server/service/inventory-product/index.ts +6 -0
  42. package/server/service/inventory-product/inventory-product-mutation.ts +112 -0
  43. package/server/service/inventory-product/inventory-product-query.ts +43 -0
  44. package/server/service/inventory-product/inventory-product-type.ts +59 -0
  45. package/server/service/inventory-product/inventory-product.ts +88 -0
  46. package/server/utils/inventory-no-generator.ts +4 -0
@@ -0,0 +1,112 @@
1
+ import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { getRepository, In } from 'typeorm'
3
+ import { InventoryProduct } from './inventory-product'
4
+ import { NewInventoryProduct, InventoryProductPatch } from './inventory-product-type'
5
+
6
+ @Resolver(InventoryProduct)
7
+ export class InventoryProductMutation {
8
+ @Directive('@transaction')
9
+ @Mutation(returns => InventoryProduct, { description: 'To create new InventoryProduct' })
10
+ async createInventoryProduct(@Arg('inventoryProduct') inventoryProduct: NewInventoryProduct, @Ctx() context: any): Promise<InventoryProduct> {
11
+ const { domain, user, tx } = context.state
12
+
13
+ return await tx.getRepository(InventoryProduct).save({
14
+ ...inventoryProduct,
15
+ domain,
16
+ creator: user,
17
+ updater: user
18
+ })
19
+ }
20
+
21
+ @Directive('@transaction')
22
+ @Mutation(returns => InventoryProduct, { description: 'To modify InventoryProduct information' })
23
+ async updateInventoryProduct(
24
+ @Arg('id') id: string,
25
+ @Arg('patch') patch: InventoryProductPatch,
26
+ @Ctx() context: any
27
+ ): Promise<InventoryProduct> {
28
+ const { domain, user, tx } = context.state
29
+
30
+ const repository = tx.getRepository(InventoryProduct)
31
+ const inventoryProduct = await repository.findOne({
32
+ where: { domain, id }
33
+ })
34
+
35
+ return await repository.save({
36
+ ...inventoryProduct,
37
+ ...patch,
38
+ updater: user
39
+ })
40
+ }
41
+
42
+ @Directive('@transaction')
43
+ @Mutation(returns => [InventoryProduct], { description: "To modify multiple InventoryProducts' information" })
44
+ async updateMultipleInventoryProduct(
45
+ @Arg('patches', type => [InventoryProductPatch]) patches: InventoryProductPatch[],
46
+ @Ctx() context: any
47
+ ): Promise<InventoryProduct[]> {
48
+ const { domain, user, tx } = context.state
49
+
50
+ let results = []
51
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
52
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
53
+ const inventoryProductRepo = tx.getRepository(InventoryProduct)
54
+
55
+ if (_createRecords.length > 0) {
56
+ for (let i = 0; i < _createRecords.length; i++) {
57
+ const newRecord = _createRecords[i]
58
+
59
+ const result = await inventoryProductRepo.save({
60
+ ...newRecord,
61
+ domain,
62
+ creator: user,
63
+ updater: user
64
+ })
65
+
66
+ results.push({ ...result, cuFlag: '+' })
67
+ }
68
+ }
69
+
70
+ if (_updateRecords.length > 0) {
71
+ for (let i = 0; i < _updateRecords.length; i++) {
72
+ const newRecord = _updateRecords[i]
73
+ const inventoryProduct = await inventoryProductRepo.findOne(newRecord.id)
74
+
75
+ const result = await inventoryProductRepo.save({
76
+ ...inventoryProduct,
77
+ ...newRecord,
78
+ updater: user
79
+ })
80
+
81
+ results.push({ ...result, cuFlag: 'M' })
82
+ }
83
+ }
84
+
85
+ return results
86
+ }
87
+
88
+ @Directive('@transaction')
89
+ @Mutation(returns => Boolean, { description: 'To delete InventoryProduct' })
90
+ async deleteInventoryProduct(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
91
+ const { domain, tx } = context.state
92
+
93
+ await tx.getRepository(InventoryProduct).delete({ domain, id })
94
+ return true
95
+ }
96
+
97
+ @Directive('@transaction')
98
+ @Mutation(returns => Boolean, { description: 'To delete multiple inventoryProducts' })
99
+ async deleteInventoryProducts(
100
+ @Arg('ids', type => [String]) ids: string[],
101
+ @Ctx() context: any
102
+ ): Promise<boolean> {
103
+ const { domain, tx } = context.state
104
+
105
+ await tx.getRepository(InventoryProduct).delete({
106
+ domain,
107
+ id: In(ids)
108
+ })
109
+
110
+ return true
111
+ }
112
+ }
@@ -0,0 +1,43 @@
1
+ import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { getRepository } from 'typeorm'
3
+ import { Domain, ListParam, convertListParams } from '@things-factory/shell'
4
+ import { User } from '@things-factory/auth-base'
5
+ import { InventoryProduct } from './inventory-product'
6
+ import { InventoryProductList } from './inventory-product-type'
7
+
8
+ @Resolver(InventoryProduct)
9
+ export class InventoryProductQuery {
10
+ @Query(returns => InventoryProduct, { description: 'To fetch a InventoryProduct' })
11
+ async inventoryProduct(@Arg('id') id: string, @Ctx() context: any): Promise<InventoryProduct> {
12
+ const { domain } = context.state
13
+
14
+ return await getRepository(InventoryProduct).findOne({
15
+ where: { domain, id }
16
+ })
17
+ }
18
+
19
+ @Query(returns => InventoryProductList, { description: 'To fetch multiple InventoryProducts' })
20
+ async inventoryProducts(@Args() params: ListParam, @Ctx() context: any): Promise<InventoryProductList> {
21
+ const { domain } = context.state
22
+
23
+ const convertedParams = convertListParams(params, domain.id)
24
+ const [items, total] = await getRepository(InventoryProduct).findAndCount(convertedParams)
25
+
26
+ return { items, total }
27
+ }
28
+
29
+ @FieldResolver(type => Domain)
30
+ async domain(@Root() inventoryProduct: InventoryProduct): Promise<Domain> {
31
+ return await getRepository(Domain).findOne(inventoryProduct.domainId)
32
+ }
33
+
34
+ @FieldResolver(type => User)
35
+ async updater(@Root() inventoryProduct: InventoryProduct): Promise<User> {
36
+ return await getRepository(User).findOne(inventoryProduct.updaterId)
37
+ }
38
+
39
+ @FieldResolver(type => User)
40
+ async creator(@Root() inventoryProduct: InventoryProduct): Promise<User> {
41
+ return await getRepository(User).findOne(inventoryProduct.creatorId)
42
+ }
43
+ }
@@ -0,0 +1,59 @@
1
+ import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
2
+
3
+ import { ObjectRef } from '@things-factory/shell'
4
+
5
+ import { InventoryProduct } from './inventory-product'
6
+
7
+ @InputType()
8
+ export class NewInventoryProduct {
9
+ @Field()
10
+ name: string
11
+
12
+ @Field({ nullable: true })
13
+ serialNumber?: string
14
+
15
+ @Field({ nullable: true })
16
+ status?: string
17
+
18
+ @Field(type => ObjectRef, { nullable: true })
19
+ product?: ObjectRef
20
+
21
+ @Field({ nullable: true })
22
+ arrivalNoticeId?: string
23
+
24
+ @Field({ nullable: true })
25
+ releaseGoodId?: string
26
+ }
27
+
28
+ @InputType()
29
+ export class InventoryProductPatch {
30
+ @Field(type => ID, { nullable: true })
31
+ id?: string
32
+
33
+ @Field({ nullable: true })
34
+ name?: string
35
+
36
+ @Field({ nullable: true })
37
+ serialNumber?: string
38
+
39
+ @Field({ nullable: true })
40
+ status?: string
41
+
42
+ @Field({ nullable: true })
43
+ arrivalNoticeId?: string
44
+
45
+ @Field({ nullable: true })
46
+ releaseGoodId?: string
47
+
48
+ @Field()
49
+ cuFlag: string
50
+ }
51
+
52
+ @ObjectType()
53
+ export class InventoryProductList {
54
+ @Field(type => [InventoryProduct])
55
+ items: InventoryProduct[]
56
+
57
+ @Field(type => Int)
58
+ total: number
59
+ }
@@ -0,0 +1,88 @@
1
+ import { Field, ID, ObjectType } from 'type-graphql'
2
+ import {
3
+ Column,
4
+ CreateDateColumn,
5
+ Entity,
6
+ Index,
7
+ ManyToOne,
8
+ PrimaryGeneratedColumn,
9
+ RelationId,
10
+ UpdateDateColumn
11
+ } from 'typeorm'
12
+
13
+ import { User } from '@things-factory/auth-base'
14
+ import { Product } from '@things-factory/product-base'
15
+ import { Domain } from '@things-factory/shell'
16
+
17
+ @Entity()
18
+ @Index(
19
+ 'ix_inventory_product_0',
20
+ (inventoryProduct: InventoryProduct) => [inventoryProduct.domain, inventoryProduct.name],
21
+ { unique: true }
22
+ )
23
+ @ObjectType({ description: 'Entity for InventoryProduct' })
24
+ export class InventoryProduct {
25
+ @PrimaryGeneratedColumn('uuid')
26
+ @Field(type => ID)
27
+ readonly id: string
28
+
29
+ @ManyToOne(type => Domain)
30
+ @Field({ nullable: true })
31
+ domain?: Domain
32
+
33
+ @RelationId((inventoryProduct: InventoryProduct) => inventoryProduct.domain)
34
+ domainId?: string
35
+
36
+ @Column()
37
+ @Field()
38
+ name: string
39
+
40
+ @Column({ nullable: true })
41
+ @Field({ nullable: true })
42
+ serialNumber?: string
43
+
44
+ @Column({ nullable: true })
45
+ @Field({ nullable: true })
46
+ status?: string
47
+
48
+ @Column({ nullable: true })
49
+ @Field({ nullable: true })
50
+ arrivalNoticeId: string
51
+
52
+ @Column({ nullable: true })
53
+ @Field({ nullable: true })
54
+ releaseGoodId: string
55
+
56
+ @ManyToOne(type => Product)
57
+ @Field({ nullable: true })
58
+ product?: Product
59
+
60
+ @RelationId((inventoryProduct: InventoryProduct) => inventoryProduct.product)
61
+ productId?: string
62
+
63
+ @CreateDateColumn()
64
+ @Field({ nullable: true })
65
+ createdAt?: Date
66
+
67
+ @UpdateDateColumn()
68
+ @Field({ nullable: true })
69
+ updatedAt?: Date
70
+
71
+ @ManyToOne(type => User, {
72
+ nullable: true
73
+ })
74
+ @Field({ nullable: true })
75
+ creator?: User
76
+
77
+ @RelationId((inventoryProduct: InventoryProduct) => inventoryProduct.creator)
78
+ creatorId?: string
79
+
80
+ @ManyToOne(type => User, {
81
+ nullable: true
82
+ })
83
+ @Field({ nullable: true })
84
+ updater?: User
85
+
86
+ @RelationId((inventoryProduct: InventoryProduct) => inventoryProduct.creator)
87
+ updaterId?: string
88
+ }
@@ -8,4 +8,8 @@ export class InventoryNoGenerator {
8
8
  static inventoryHistoryName() {
9
9
  return uuid()
10
10
  }
11
+
12
+ static inventoryItemName() {
13
+ return uuid()
14
+ }
11
15
  }