@mbc-cqrs-serverless/master 0.1.68-beta.0 → 0.1.70-beta.0

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 (109) hide show
  1. package/dist/constants/index.d.ts +1 -0
  2. package/dist/constants/index.js +2 -1
  3. package/dist/constants/index.js.map +1 -1
  4. package/dist/controllers/master-data.controller.d.ts +6 -0
  5. package/dist/controllers/master-data.controller.js +74 -0
  6. package/dist/controllers/master-data.controller.js.map +1 -1
  7. package/dist/controllers/master-setting.controller.d.ts +8 -0
  8. package/dist/controllers/master-setting.controller.js +98 -0
  9. package/dist/controllers/master-setting.controller.js.map +1 -1
  10. package/dist/custom-task/custom-task.module.d.ts +2 -0
  11. package/dist/custom-task/custom-task.module.js +30 -0
  12. package/dist/custom-task/custom-task.module.js.map +1 -0
  13. package/dist/custom-task/event/task-queue-event-factory.d.ts +6 -0
  14. package/dist/custom-task/event/task-queue-event-factory.js +23 -0
  15. package/dist/custom-task/event/task-queue-event-factory.js.map +1 -0
  16. package/dist/custom-task/my-task.controller.d.ts +9 -0
  17. package/dist/custom-task/my-task.controller.js +56 -0
  18. package/dist/custom-task/my-task.controller.js.map +1 -0
  19. package/dist/custom-task/my-task.service.d.ts +12 -0
  20. package/dist/custom-task/my-task.service.js +76 -0
  21. package/dist/custom-task/my-task.service.js.map +1 -0
  22. package/dist/decorators/index.d.ts +1 -0
  23. package/dist/decorators/index.js +18 -0
  24. package/dist/decorators/index.js.map +1 -0
  25. package/dist/decorators/key.d.ts +1 -0
  26. package/dist/decorators/key.js +34 -0
  27. package/dist/decorators/key.js.map +1 -0
  28. package/dist/dto/index.d.ts +1 -0
  29. package/dist/dto/index.js +1 -0
  30. package/dist/dto/index.js.map +1 -1
  31. package/dist/dto/master-copy/index.d.ts +8 -0
  32. package/dist/dto/master-copy/index.js +25 -0
  33. package/dist/dto/master-copy/index.js.map +1 -0
  34. package/dist/dto/master-copy/master-copy.dto.d.ts +19 -0
  35. package/dist/dto/master-copy/master-copy.dto.js +92 -0
  36. package/dist/dto/master-copy/master-copy.dto.js.map +1 -0
  37. package/dist/dto/master-copy/master-data-create.dto.d.ts +7 -0
  38. package/dist/dto/master-copy/master-data-create.dto.js +43 -0
  39. package/dist/dto/master-copy/master-data-create.dto.js.map +1 -0
  40. package/dist/dto/master-copy/master-data-search.dto.d.ts +6 -0
  41. package/dist/dto/master-copy/master-data-search.dto.js +39 -0
  42. package/dist/dto/master-copy/master-data-search.dto.js.map +1 -0
  43. package/dist/dto/master-copy/master-data-update.dto.d.ts +6 -0
  44. package/dist/dto/master-copy/master-data-update.dto.js +41 -0
  45. package/dist/dto/master-copy/master-data-update.dto.js.map +1 -0
  46. package/dist/dto/master-copy/master-rds-list.entity.d.ts +6 -0
  47. package/dist/dto/master-copy/master-rds-list.entity.js +33 -0
  48. package/dist/dto/master-copy/master-rds-list.entity.js.map +1 -0
  49. package/dist/dto/master-copy/master-rds.entity.d.ts +26 -0
  50. package/dist/dto/master-copy/master-rds.entity.js +116 -0
  51. package/dist/dto/master-copy/master-rds.entity.js.map +1 -0
  52. package/dist/dto/master-copy/master-setting-search.dto.d.ts +6 -0
  53. package/dist/dto/master-copy/master-setting-search.dto.js +39 -0
  54. package/dist/dto/master-copy/master-setting-search.dto.js.map +1 -0
  55. package/dist/dto/master-copy/master-setting-update.dto.d.ts +4 -0
  56. package/dist/dto/master-copy/master-setting-update.dto.js +31 -0
  57. package/dist/dto/master-copy/master-setting-update.dto.js.map +1 -0
  58. package/dist/handler/master-sfn-task.event.d.ts +3 -0
  59. package/dist/handler/master-sfn-task.event.js +8 -0
  60. package/dist/handler/master-sfn-task.event.js.map +1 -0
  61. package/dist/handler/master-sfn-task.handler.d.ts +24 -0
  62. package/dist/handler/master-sfn-task.handler.js +242 -0
  63. package/dist/handler/master-sfn-task.handler.js.map +1 -0
  64. package/dist/helpers/index.d.ts +7 -0
  65. package/dist/helpers/index.js +15 -0
  66. package/dist/helpers/index.js.map +1 -1
  67. package/dist/helpers/rds.d.ts +4 -0
  68. package/dist/helpers/rds.js +19 -0
  69. package/dist/helpers/rds.js.map +1 -0
  70. package/dist/index.d.ts +2 -0
  71. package/dist/index.js +2 -0
  72. package/dist/index.js.map +1 -1
  73. package/dist/interfaces/master-data.interface.d.ts +2 -2
  74. package/dist/master.module-definition.d.ts +2 -0
  75. package/dist/master.module-definition.js +2 -1
  76. package/dist/master.module-definition.js.map +1 -1
  77. package/dist/master.module.js +19 -0
  78. package/dist/master.module.js.map +1 -1
  79. package/dist/services/master-data.service.d.ts +10 -9
  80. package/dist/services/master-data.service.js +112 -4
  81. package/dist/services/master-data.service.js.map +1 -1
  82. package/dist/services/master-setting.service.d.ts +16 -3
  83. package/dist/services/master-setting.service.js +126 -3
  84. package/dist/services/master-setting.service.js.map +1 -1
  85. package/dist/services/master-setting.service.spec.js +16 -0
  86. package/dist/services/master-setting.service.spec.js.map +1 -1
  87. package/dist/update-scheme.js +2 -10
  88. package/dist/update-scheme.js.map +1 -1
  89. package/package.json +6 -4
  90. package/src/templates/master/handler/master-rds.handler.ts +0 -4
  91. package/src/templates/master/master.module.ts +6 -18
  92. package/src/templates/custom-task/custom-task.module.ts +0 -18
  93. package/src/templates/custom-task/event/task-queue-event-factory.ts +0 -26
  94. package/src/templates/custom-task/my-task.controller.ts +0 -28
  95. package/src/templates/custom-task/my-task.service.ts +0 -99
  96. package/src/templates/master/dto/master-copy.dto.ts +0 -73
  97. package/src/templates/master/dto/master-data-create.dto.ts +0 -20
  98. package/src/templates/master/dto/master-data-search.dto.ts +0 -20
  99. package/src/templates/master/dto/master-data-update.dto.ts +0 -25
  100. package/src/templates/master/dto/master-rds-list.entity.ts +0 -15
  101. package/src/templates/master/dto/master-rds.entity.ts +0 -77
  102. package/src/templates/master/dto/master-setting-search.dto.ts +0 -20
  103. package/src/templates/master/dto/master-setting-update.dto.ts +0 -11
  104. package/src/templates/master/handler/master-sfn-task.event.ts +0 -3
  105. package/src/templates/master/handler/master-sfn-task.handler.ts +0 -334
  106. package/src/templates/master/master-data.controller.ts +0 -98
  107. package/src/templates/master/master-data.service.ts +0 -181
  108. package/src/templates/master/master-setting.controller.ts +0 -103
  109. package/src/templates/master/master-setting.service.ts +0 -201
@@ -1,201 +0,0 @@
1
- import {
2
- DataService,
3
- DetailDto,
4
- getUserContext,
5
- IInvoke,
6
- UserContext,
7
- } from '@mbc-cqrs-serverless/core'
8
- import { MasterSettingService } from '@mbc-cqrs-serverless/master'
9
- import { CommonSettingDto } from '@mbc-cqrs-serverless/master/dist/dto'
10
- import { TaskService } from '@mbc-cqrs-serverless/task'
11
- import {
12
- BadRequestException,
13
- Injectable,
14
- Logger,
15
- NotFoundException,
16
- } from '@nestjs/common'
17
- import { Prisma } from '@prisma/client'
18
- import { PrismaService } from 'src/prisma'
19
-
20
- import { DataCopyMode, MasterCopyDto } from './dto/master-copy.dto'
21
- import { MasterRdsEntity } from './dto/master-rds.entity'
22
- import { MasterRdsListEntity } from './dto/master-rds-list.entity'
23
- import { MasterSettingSearchDto } from './dto/master-setting-search.dto'
24
- import { MasterSettingUpdateDto } from './dto/master-setting-update.dto'
25
- import {
26
- getOrderBys,
27
- MASTER_COPY_SK_PREFIX,
28
- parseId,
29
- SETTING_SK_PREFIX,
30
- } from './helpers'
31
-
32
- @Injectable()
33
- export class CustomMasterSettingService {
34
- private readonly logger = new Logger(CustomMasterSettingService.name)
35
-
36
- constructor(
37
- private readonly masterSettingService: MasterSettingService,
38
- private readonly prismaService: PrismaService,
39
- private readonly dataService: DataService,
40
- private readonly taskService: TaskService,
41
- ) {}
42
-
43
- async list(searchDto: MasterSettingSearchDto, invokeContext: IInvoke) {
44
- const userContext = getUserContext(invokeContext)
45
-
46
- const where: Prisma.MasterWhereInput = {
47
- tenantCode: this.getUserTenantCode(userContext),
48
- masterType: SETTING_SK_PREFIX,
49
- }
50
-
51
- if (searchDto.isDeleted === false || searchDto.isDeleted === undefined) {
52
- where.isDeleted = false
53
- }
54
-
55
- const andConditions: Prisma.MasterWhereInput[] = []
56
-
57
- if (searchDto.name?.trim()) {
58
- andConditions.push({
59
- name: { contains: searchDto.name.trim() },
60
- })
61
- }
62
-
63
- if (searchDto.keyword?.trim()) {
64
- andConditions.push({
65
- attributes: {
66
- path: 'description',
67
- string_contains: searchDto.keyword.trim(),
68
- },
69
- })
70
- }
71
-
72
- if (searchDto.code?.trim()) {
73
- andConditions.push({
74
- masterCode: { contains: searchDto.code.trim() },
75
- })
76
- }
77
-
78
- if (andConditions.length) {
79
- where.AND = andConditions
80
- }
81
-
82
- const { pageSize = 10, page = 1, orderBys = ['-createdAt'] } = searchDto
83
-
84
- const [total, items] = await Promise.all([
85
- this.prismaService.master.count({ where }),
86
- this.prismaService.master.findMany({
87
- where,
88
- take: pageSize,
89
- skip: pageSize * (page - 1),
90
- orderBy: getOrderBys<Prisma.MasterOrderByWithRelationInput>(orderBys),
91
- }),
92
- ])
93
-
94
- return new MasterRdsListEntity({
95
- total,
96
- items: items.map((item) => new MasterRdsEntity(item)),
97
- })
98
- }
99
-
100
- async getDetail(key: DetailDto) {
101
- const data = await this.dataService.getItem(key)
102
-
103
- if (!data) throw new NotFoundException()
104
-
105
- return new MasterRdsEntity(data)
106
- }
107
-
108
- async create(createDto: CommonSettingDto, invokeContext: IInvoke) {
109
- const userContext = getUserContext(invokeContext)
110
- return await this.masterSettingService.createTenantSetting(
111
- {
112
- ...createDto,
113
- tenantCode: userContext.tenantCode,
114
- },
115
- { invokeContext },
116
- )
117
- }
118
-
119
- async update(
120
- key: DetailDto,
121
- updateDto: MasterSettingUpdateDto,
122
- invokeContext: IInvoke,
123
- ) {
124
- const code = key.sk.split('#')[1]
125
- const userContext = getUserContext(invokeContext)
126
-
127
- return await this.masterSettingService.updateSetting(
128
- key,
129
- {
130
- code,
131
- tenantCode: userContext.tenantCode,
132
- name: updateDto.name,
133
- settingValue: updateDto.attributes,
134
- },
135
- {
136
- invokeContext,
137
- },
138
- )
139
- }
140
-
141
- async delete(key: DetailDto, invokeContext: IInvoke) {
142
- return this.masterSettingService.deleteSetting(key, { invokeContext })
143
- }
144
-
145
- async checkExistCode(code: string, invokeContext: IInvoke) {
146
- const userContext = getUserContext(invokeContext)
147
-
148
- const item = await this.prismaService.master.findFirst({
149
- where: {
150
- tenantCode: userContext.tenantCode,
151
- masterType: SETTING_SK_PREFIX,
152
- masterCode: code,
153
- },
154
- })
155
-
156
- return !!item && !item.isDeleted
157
- }
158
-
159
- async copy(
160
- masterCopyDto: MasterCopyDto,
161
- opts: { invokeContext: IInvoke },
162
- ): Promise<any> {
163
- this.logger.debug('cmd:', JSON.stringify(masterCopyDto))
164
-
165
- const userContext = getUserContext(opts.invokeContext)
166
-
167
- const { masterSettingId, targetTenants, dataCopyOption } = masterCopyDto
168
-
169
- if (dataCopyOption?.mode === DataCopyMode.PARTIAL) {
170
- if (!dataCopyOption.id?.length) {
171
- throw new BadRequestException('Must provide ID when mode is PARTIAL.')
172
- }
173
- }
174
-
175
- const setting = await this.dataService.getItem(parseId(masterSettingId))
176
-
177
- if (!setting || setting.isDeleted) {
178
- throw new BadRequestException('Master setting does not exist')
179
- }
180
-
181
- const item = targetTenants.map((tenant) => ({
182
- ...masterCopyDto,
183
- targetTenants: [tenant],
184
- }))
185
-
186
- const taskItem = await this.taskService.createStepFunctionTask(
187
- {
188
- input: item,
189
- taskType: `${MASTER_COPY_SK_PREFIX}_${masterSettingId.split('#').at(-1)}`,
190
- tenantCode: userContext.tenantCode,
191
- },
192
- opts,
193
- )
194
-
195
- return taskItem
196
- }
197
-
198
- private getUserTenantCode(userContext: UserContext): string {
199
- return userContext.tenantCode
200
- }
201
- }