@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
@@ -15,11 +15,7 @@ export class MasterDataSyncRdsHandler implements IDataSyncHandler {
15
15
  private readonly logger = new Logger(MasterDataSyncRdsHandler.name)
16
16
 
17
17
  constructor(private readonly prismaService: PrismaService) {}
18
- // MASTER#9999
19
- // MASTER_SETTING#ABC
20
18
 
21
- // MASTER#9999
22
- // ABC#1
23
19
  async up(cmd: MasterCommandEntity): Promise<any> {
24
20
  const sk = removeSortKeyVersion(cmd.sk)
25
21
  const skSplit = sk.split(KEY_SEPARATOR)
@@ -1,15 +1,9 @@
1
1
  import { CommandModule } from '@mbc-cqrs-serverless/core'
2
2
  import { MasterModule as CoreMasterModule } from '@mbc-cqrs-serverless/master'
3
- import { SequencesModule } from '@mbc-cqrs-serverless/sequence'
4
3
  import { Module } from '@nestjs/common'
5
- import { CustomTaskModule } from 'src/custom-task/custom-task.module'
4
+ import { PrismaService } from 'src/prisma'
6
5
 
7
6
  import { MasterDataSyncRdsHandler } from './handler/master-rds.handler'
8
- import { MasterSfnTaskEventHandler } from './handler/master-sfn-task.handler'
9
- import { MasterDataController } from './master-data.controller'
10
- import { CustomMasterDataService } from './master-data.service'
11
- import { MasterSettingController } from './master-setting.controller'
12
- import { CustomMasterSettingService } from './master-setting.service'
13
7
 
14
8
  @Module({
15
9
  imports: [
@@ -17,20 +11,14 @@ import { CustomMasterSettingService } from './master-setting.service'
17
11
  tableName: 'master',
18
12
  dataSyncHandlers: [MasterDataSyncRdsHandler],
19
13
  }),
20
-
21
14
  CoreMasterModule.register({
22
- enableController: false,
15
+ enableController: true,
16
+ prismaService: PrismaService,
23
17
  dataSyncHandlers: [MasterDataSyncRdsHandler],
24
18
  }),
25
- CustomTaskModule,
26
- SequencesModule,
27
- ],
28
- controllers: [MasterDataController, MasterSettingController],
29
- providers: [
30
- CustomMasterDataService,
31
- CustomMasterSettingService,
32
- MasterSfnTaskEventHandler,
33
19
  ],
34
- exports: [CustomMasterSettingService, CoreMasterModule],
20
+ controllers: [],
21
+ providers: [],
22
+ exports: [],
35
23
  })
36
24
  export class MasterModule {}
@@ -1,18 +0,0 @@
1
- import { TaskModule } from '@mbc-cqrs-serverless/task'
2
- import { Module } from '@nestjs/common'
3
-
4
- import { TaskQueueEventFactory } from './event/task-queue-event-factory'
5
- import { MyTaskController } from './my-task.controller'
6
- import { MyTaskService } from './my-task.service'
7
-
8
- @Module({
9
- imports: [
10
- TaskModule.register({
11
- taskQueueEventFactory: TaskQueueEventFactory,
12
- }),
13
- ],
14
- providers: [MyTaskService],
15
- controllers: [MyTaskController],
16
- exports: [TaskModule],
17
- })
18
- export class CustomTaskModule {}
@@ -1,26 +0,0 @@
1
- import { ITaskQueueEventFactory } from '@mbc-cqrs-serverless/task'
2
- import { StepFunctionTaskEvent } from '@mbc-cqrs-serverless/task'
3
- import { Logger } from '@nestjs/common'
4
-
5
- import { MasterSfnTaskEvent } from '../../master/handler/master-sfn-task.event'
6
-
7
- export class TaskQueueEventFactory implements ITaskQueueEventFactory {
8
- private readonly logger = new Logger(TaskQueueEventFactory.name)
9
-
10
- async transformStepFunctionTask(
11
- event: StepFunctionTaskEvent,
12
- ): Promise<any[]> {
13
- this.logger.debug('Received StepFunctionTaskEvent', event)
14
-
15
- const taskKeySk = event.taskKey.sk
16
- this.logger.debug(`Evaluating taskKey.sk: ${taskKeySk}`)
17
-
18
- if (taskKeySk.startsWith('MASTER_COPY')) {
19
- this.logger.debug(`Matched MASTER_COPY_SK_PREFIX (MASTER_COPY)`)
20
- return [new MasterSfnTaskEvent(event)]
21
- }
22
-
23
- this.logger.debug(`No matching SK prefix found for: ${taskKeySk}`)
24
- return []
25
- }
26
- }
@@ -1,28 +0,0 @@
1
- import { DetailDto, IInvoke, INVOKE_CONTEXT } from '@mbc-cqrs-serverless/core'
2
- import { TaskEntity } from '@mbc-cqrs-serverless/task'
3
- import { Controller, Get, Param, Query } from '@nestjs/common'
4
- import { ApiTags } from '@nestjs/swagger'
5
-
6
- import { MyTaskService } from './my-task.service'
7
-
8
- @Controller('api/tasks')
9
- @ApiTags('tasks')
10
- export class MyTaskController {
11
- constructor(private readonly myTaskService: MyTaskService) {}
12
-
13
- @Get('/sfn-task-parent')
14
- async getSfnTaskParentBySettingCode(
15
- @INVOKE_CONTEXT() invokeContext: IInvoke,
16
- @Query('masterSettingCode') masterSettingCode: string,
17
- ): Promise<TaskEntity[]> {
18
- return this.myTaskService.getSfnTaskParentBySettingCode(
19
- masterSettingCode,
20
- invokeContext,
21
- )
22
- }
23
-
24
- @Get('/:pk/:sk')
25
- async getSfnChildTask(@Param() key: DetailDto): Promise<TaskEntity[]> {
26
- return this.myTaskService.getSfnChildTask(key)
27
- }
28
- }
@@ -1,99 +0,0 @@
1
- import {
2
- DetailKey,
3
- extractInvokeContext,
4
- getAuthorizerClaims,
5
- HEADER_TENANT_CODE,
6
- IInvoke,
7
- KEY_SEPARATOR,
8
- UserContext,
9
- } from '@mbc-cqrs-serverless/core'
10
- import { TaskEntity, TaskService } from '@mbc-cqrs-serverless/task'
11
- import {
12
- BadRequestException,
13
- ExecutionContext,
14
- Injectable,
15
- } from '@nestjs/common'
16
-
17
- @Injectable()
18
- export class MyTaskService {
19
- constructor(private readonly taskService: TaskService) {}
20
-
21
- async getSfnTaskParentBySettingCode(
22
- masterSettingCode: string,
23
- invokeContext: IInvoke,
24
- ) {
25
- const userContext = this.getUserContext(invokeContext)
26
- if (!masterSettingCode) {
27
- throw new BadRequestException('Must provide master setting code')
28
- }
29
- const items = await this.listAllItemsByPk(
30
- userContext.tenantCode,
31
- 'SFN_TASK',
32
- {
33
- sk: {
34
- skExpession: 'begins_with(sk, :code)',
35
- skAttributeValues: {
36
- ':code': `MASTER_COPY_${masterSettingCode}`,
37
- },
38
- },
39
- order: 'desc',
40
- },
41
- )
42
-
43
- return items.filter((item) => this.isParentTask(item.sk))
44
- }
45
-
46
- async getSfnChildTask(key: DetailKey) {
47
- return await this.taskService.getAllSubTask(key)
48
- }
49
-
50
- private async listAllItemsByPk(
51
- tenantCode: string,
52
- type: string,
53
- options?: {
54
- sk?: {
55
- skExpession: string
56
- skAttributeValues: Record<string, string>
57
- skAttributeNames?: Record<string, string>
58
- }
59
- order?: 'asc' | 'desc'
60
- },
61
- ): Promise<TaskEntity[]> {
62
- const allItems: TaskEntity[] = []
63
- let lastSk: string | undefined = undefined
64
-
65
- do {
66
- const result = await this.taskService.listItemsByPk(tenantCode, type, {
67
- ...options,
68
- startFromSk: lastSk,
69
- })
70
-
71
- allItems.push(...result.items)
72
- lastSk = result.lastSk
73
- } while (lastSk)
74
-
75
- return allItems
76
- }
77
-
78
- private isParentTask(sk: string) {
79
- return sk.split(KEY_SEPARATOR).length === 2
80
- }
81
-
82
- getUserContext = (ctx: IInvoke | ExecutionContext): UserContext => {
83
- if ('getHandler' in ctx) {
84
- ctx = extractInvokeContext(ctx)
85
- }
86
- const claims = getAuthorizerClaims(ctx)
87
-
88
- const userId = claims.sub
89
- const tenantCode =
90
- claims['custom:tenant_code'] ||
91
- (ctx?.event?.headers || {})[HEADER_TENANT_CODE]
92
- const tenantRole = claims['custom:user_type']
93
- return {
94
- userId,
95
- tenantRole,
96
- tenantCode,
97
- }
98
- }
99
- }
@@ -1,73 +0,0 @@
1
- import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
2
- import { Type } from 'class-transformer'
3
- import {
4
- IsArray,
5
- IsEnum,
6
- IsNotEmpty,
7
- IsOptional,
8
- IsString,
9
- ValidateNested,
10
- } from 'class-validator'
11
-
12
- export enum CopyType {
13
- SETTING_ONLY = 'SETTING_ONLY',
14
- DATA_ONLY = 'DATA_ONLY',
15
- BOTH = 'BOTH',
16
- }
17
-
18
- export enum DataCopyMode {
19
- ALL = 'ALL',
20
- PARTIAL = 'PARTIAL',
21
- }
22
-
23
- export class DataCopyOptionDto {
24
- @ApiProperty({
25
- enum: DataCopyMode,
26
- description: 'Whether to copy all master_data or only specific ones',
27
- })
28
- @IsEnum(DataCopyMode)
29
- mode: DataCopyMode
30
-
31
- @ApiPropertyOptional({
32
- description:
33
- 'Required only if mode is PARTIAL. List of master_data IDs to copy.',
34
- type: [String],
35
- })
36
- @IsOptional()
37
- @IsArray()
38
- @IsString({ each: true })
39
- id?: string[]
40
- }
41
-
42
- export class MasterCopyDto {
43
- @ApiProperty({
44
- description: 'The ID of the master_setting to copy from',
45
- })
46
- @IsString()
47
- @IsNotEmpty()
48
- masterSettingId: string
49
-
50
- @ApiProperty({
51
- description: 'Target tenants as an array of tenant codes',
52
- example: ['tenant_b', 'tenant_c'],
53
- })
54
- @IsNotEmpty()
55
- targetTenants: string[]
56
-
57
- @ApiProperty({
58
- enum: CopyType,
59
- description: 'What to copy: only setting, only data, or both',
60
- })
61
- @IsEnum(CopyType)
62
- copyType: CopyType
63
-
64
- @ApiPropertyOptional({
65
- type: DataCopyOptionDto,
66
- description:
67
- 'Options for data copy (required when copyType is DATA_ONLY or BOTH)',
68
- })
69
- @IsOptional()
70
- @ValidateNested()
71
- @Type(() => DataCopyOptionDto)
72
- dataCopyOption?: DataCopyOptionDto
73
- }
@@ -1,20 +0,0 @@
1
- import { IsNumber, IsObject, IsOptional, IsString } from 'class-validator'
2
-
3
- export class MasterDataCreateDto {
4
- @IsString()
5
- settingCode: string
6
-
7
- @IsString()
8
- name: string
9
-
10
- @IsOptional()
11
- @IsString()
12
- code?: string
13
-
14
- @IsNumber()
15
- @IsOptional()
16
- seq?: number
17
-
18
- @IsObject()
19
- attributes: object
20
- }
@@ -1,20 +0,0 @@
1
- import { SearchDto } from '@mbc-cqrs-serverless/core'
2
- import { Transform } from 'class-transformer'
3
- import { IsBoolean, IsOptional, IsString } from 'class-validator'
4
-
5
- export class MasterDataSearchDto extends SearchDto {
6
- @IsOptional()
7
- @IsString()
8
- settingCode?: string
9
-
10
- @IsOptional()
11
- @IsString()
12
- code?: string
13
-
14
- @IsBoolean()
15
- @Transform(({ value }) =>
16
- value === 'true' ? true : value === 'false' ? false : value,
17
- )
18
- @IsOptional()
19
- isDeleted?: boolean
20
- }
@@ -1,25 +0,0 @@
1
- import {
2
- IsBoolean,
3
- IsNumber,
4
- IsObject,
5
- IsOptional,
6
- IsString,
7
- } from 'class-validator'
8
-
9
- export class MasterDataUpdateDto {
10
- @IsString()
11
- @IsOptional()
12
- name?: string
13
-
14
- @IsBoolean()
15
- @IsOptional()
16
- isDeleted?: boolean
17
-
18
- @IsNumber()
19
- @IsOptional()
20
- seq?: number
21
-
22
- @IsObject()
23
- @IsOptional()
24
- attributes?: object
25
- }
@@ -1,15 +0,0 @@
1
- import { ApiProperty } from '@nestjs/swagger'
2
-
3
- import { MasterRdsEntity } from './master-rds.entity'
4
-
5
- export class MasterRdsListEntity {
6
- @ApiProperty({ type: Number })
7
- total?: number
8
-
9
- @ApiProperty({ type: MasterRdsEntity, isArray: true })
10
- items: MasterRdsEntity[]
11
-
12
- constructor(data: Partial<MasterRdsListEntity>) {
13
- Object.assign(this, data)
14
- }
15
- }
@@ -1,77 +0,0 @@
1
- import { ApiProperty } from '@nestjs/swagger'
2
- import { Master } from '@prisma/client'
3
-
4
- export class MasterRdsEntity {
5
- @ApiProperty()
6
- id: string
7
-
8
- @ApiProperty()
9
- cpk: string
10
-
11
- @ApiProperty()
12
- csk: string
13
-
14
- @ApiProperty()
15
- pk: string
16
-
17
- @ApiProperty()
18
- sk: string
19
-
20
- @ApiProperty()
21
- masterType: string
22
-
23
- @ApiProperty()
24
- masterTypeCode: string
25
-
26
- @ApiProperty()
27
- masterCode: string
28
-
29
- @ApiProperty()
30
- tenantCode: string
31
-
32
- @ApiProperty()
33
- seq: number
34
-
35
- @ApiProperty()
36
- code: string
37
-
38
- @ApiProperty()
39
- name: string
40
-
41
- @ApiProperty()
42
- version: number
43
-
44
- @ApiProperty()
45
- isDeleted: boolean
46
-
47
- @ApiProperty()
48
- createdBy: string
49
-
50
- @ApiProperty()
51
- createdIp: string
52
-
53
- @ApiProperty()
54
- createdAt: Date
55
-
56
- @ApiProperty()
57
- updatedBy: string
58
-
59
- @ApiProperty()
60
- updatedIp: string
61
-
62
- @ApiProperty()
63
- updatedAt: Date
64
-
65
- @ApiProperty({ required: false })
66
- syncFrom?: string
67
-
68
- @ApiProperty({ required: false })
69
- syncDate?: Date
70
-
71
- @ApiProperty({ type: 'object', required: false })
72
- attributes?: Record<string, any>
73
-
74
- constructor(data: Partial<Master>) {
75
- Object.assign(this, data)
76
- }
77
- }
@@ -1,20 +0,0 @@
1
- import { SearchDto } from '@mbc-cqrs-serverless/core'
2
- import { Transform } from 'class-transformer'
3
- import { IsBoolean, IsOptional, IsString } from 'class-validator'
4
-
5
- export class MasterSettingSearchDto extends SearchDto {
6
- @IsOptional()
7
- @IsString()
8
- code?: string
9
-
10
- @IsOptional()
11
- @IsString()
12
- name?: string
13
-
14
- @IsBoolean()
15
- @Transform(({ value }) =>
16
- value === 'true' ? true : value === 'false' ? false : value,
17
- )
18
- @IsOptional()
19
- isDeleted?: boolean
20
- }
@@ -1,11 +0,0 @@
1
- import { IsObject, IsOptional, IsString } from 'class-validator'
2
-
3
- export class MasterSettingUpdateDto {
4
- @IsString()
5
- @IsOptional()
6
- name?: string
7
-
8
- @IsObject()
9
- @IsOptional()
10
- attributes?: object
11
- }
@@ -1,3 +0,0 @@
1
- import { StepFunctionTaskEvent } from '@mbc-cqrs-serverless/task'
2
-
3
- export class MasterSfnTaskEvent extends StepFunctionTaskEvent {}