@mbc-cqrs-serverless/master 0.1.68-beta.0 → 0.1.69-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 (82) 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 +7 -0
  8. package/dist/controllers/master-setting.controller.js +86 -0
  9. package/dist/controllers/master-setting.controller.js.map +1 -1
  10. package/dist/decorators/index.d.ts +1 -0
  11. package/dist/decorators/index.js +18 -0
  12. package/dist/decorators/index.js.map +1 -0
  13. package/dist/decorators/key.d.ts +1 -0
  14. package/dist/decorators/key.js +34 -0
  15. package/dist/decorators/key.js.map +1 -0
  16. package/dist/dto/index.d.ts +1 -0
  17. package/dist/dto/index.js +1 -0
  18. package/dist/dto/index.js.map +1 -1
  19. package/dist/dto/master-copy/index.d.ts +8 -0
  20. package/dist/dto/master-copy/index.js +25 -0
  21. package/dist/dto/master-copy/index.js.map +1 -0
  22. package/dist/dto/master-copy/master-copy.dto.d.ts +19 -0
  23. package/dist/dto/master-copy/master-copy.dto.js +92 -0
  24. package/dist/dto/master-copy/master-copy.dto.js.map +1 -0
  25. package/dist/dto/master-copy/master-data-create.dto.d.ts +7 -0
  26. package/dist/dto/master-copy/master-data-create.dto.js +43 -0
  27. package/dist/dto/master-copy/master-data-create.dto.js.map +1 -0
  28. package/dist/dto/master-copy/master-data-search.dto.d.ts +6 -0
  29. package/dist/dto/master-copy/master-data-search.dto.js +39 -0
  30. package/dist/dto/master-copy/master-data-search.dto.js.map +1 -0
  31. package/dist/dto/master-copy/master-data-update.dto.d.ts +6 -0
  32. package/dist/dto/master-copy/master-data-update.dto.js +41 -0
  33. package/dist/dto/master-copy/master-data-update.dto.js.map +1 -0
  34. package/dist/dto/master-copy/master-rds-list.entity.d.ts +6 -0
  35. package/dist/dto/master-copy/master-rds-list.entity.js +33 -0
  36. package/dist/dto/master-copy/master-rds-list.entity.js.map +1 -0
  37. package/dist/dto/master-copy/master-rds.entity.d.ts +26 -0
  38. package/dist/dto/master-copy/master-rds.entity.js +116 -0
  39. package/dist/dto/master-copy/master-rds.entity.js.map +1 -0
  40. package/dist/dto/master-copy/master-setting-search.dto.d.ts +6 -0
  41. package/dist/dto/master-copy/master-setting-search.dto.js +39 -0
  42. package/dist/dto/master-copy/master-setting-search.dto.js.map +1 -0
  43. package/dist/dto/master-copy/master-setting-update.dto.d.ts +4 -0
  44. package/dist/dto/master-copy/master-setting-update.dto.js +31 -0
  45. package/dist/dto/master-copy/master-setting-update.dto.js.map +1 -0
  46. package/dist/helpers/rds.d.ts +4 -0
  47. package/dist/helpers/rds.js +19 -0
  48. package/dist/helpers/rds.js.map +1 -0
  49. package/dist/index.d.ts +2 -0
  50. package/dist/index.js +2 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/interfaces/master-data.interface.d.ts +2 -2
  53. package/dist/master.module-definition.d.ts +2 -0
  54. package/dist/master.module-definition.js +2 -1
  55. package/dist/master.module-definition.js.map +1 -1
  56. package/dist/master.module.js +10 -0
  57. package/dist/master.module.js.map +1 -1
  58. package/dist/services/master-data.service.d.ts +10 -9
  59. package/dist/services/master-data.service.js +112 -4
  60. package/dist/services/master-data.service.js.map +1 -1
  61. package/dist/services/master-setting.service.d.ts +11 -3
  62. package/dist/services/master-setting.service.js +98 -2
  63. package/dist/services/master-setting.service.js.map +1 -1
  64. package/dist/services/master-setting.service.spec.js +11 -0
  65. package/dist/services/master-setting.service.spec.js.map +1 -1
  66. package/dist/update-scheme.js +1 -0
  67. package/dist/update-scheme.js.map +1 -1
  68. package/package.json +5 -4
  69. package/src/templates/master/handler/master-sfn-task.handler.ts +4 -6
  70. package/src/templates/master/master-setting.controller.ts +4 -84
  71. package/src/templates/master/master-setting.service.ts +4 -150
  72. package/src/templates/master/master.module.ts +7 -12
  73. package/src/templates/master/dto/master-copy.dto.ts +0 -73
  74. package/src/templates/master/dto/master-data-create.dto.ts +0 -20
  75. package/src/templates/master/dto/master-data-search.dto.ts +0 -20
  76. package/src/templates/master/dto/master-data-update.dto.ts +0 -25
  77. package/src/templates/master/dto/master-rds-list.entity.ts +0 -15
  78. package/src/templates/master/dto/master-rds.entity.ts +0 -77
  79. package/src/templates/master/dto/master-setting-search.dto.ts +0 -20
  80. package/src/templates/master/dto/master-setting-update.dto.ts +0 -11
  81. package/src/templates/master/master-data.controller.ts +0 -98
  82. package/src/templates/master/master-data.service.ts +0 -181
@@ -1,98 +1,18 @@
1
- import {
2
- DetailDto,
3
- getUserContext,
4
- IInvoke,
5
- INVOKE_CONTEXT,
6
- } from '@mbc-cqrs-serverless/core'
7
- import { CommonSettingDto } from '@mbc-cqrs-serverless/master/dist/dto'
8
- import {
9
- BadRequestException,
10
- Body,
11
- Controller,
12
- Delete,
13
- Get,
14
- Injectable,
15
- Param,
16
- Post,
17
- Put,
18
- Query,
19
- } from '@nestjs/common'
1
+ import { IInvoke, INVOKE_CONTEXT } from '@mbc-cqrs-serverless/core'
2
+ import { MasterCopyDto } from '@mbc-cqrs-serverless/master'
3
+ import { Body, Controller, Injectable, Post } from '@nestjs/common'
20
4
  import { ApiTags } from '@nestjs/swagger'
21
5
 
22
- import { MasterCopyDto } from './dto/master-copy.dto'
23
- import { MasterSettingSearchDto } from './dto/master-setting-search.dto'
24
- import { MasterSettingUpdateDto } from './dto/master-setting-update.dto'
25
- import { parsePk } from './helpers'
26
6
  import { CustomMasterSettingService } from './master-setting.service'
27
7
 
28
8
  @ApiTags('master-setting')
29
9
  @Controller('api/master-setting')
30
10
  @Injectable()
31
- export class MasterSettingController {
11
+ export class CustomMasterSettingController {
32
12
  constructor(
33
13
  private readonly masterSettingService: CustomMasterSettingService,
34
14
  ) {}
35
15
 
36
- @Get('/')
37
- async list(
38
- @Query() searchDto: MasterSettingSearchDto,
39
- @INVOKE_CONTEXT() invokeContext: IInvoke,
40
- ) {
41
- return this.masterSettingService.list(searchDto, invokeContext)
42
- }
43
-
44
- @Get('/:pk/:sk')
45
- async getDetail(@Param() key: DetailDto) {
46
- return this.masterSettingService.getDetail(key)
47
- }
48
-
49
- @Post('/')
50
- async create(
51
- @Body() createDto: CommonSettingDto,
52
- @INVOKE_CONTEXT() invokeContext: IInvoke,
53
- ) {
54
- return this.masterSettingService.create(createDto, invokeContext)
55
- }
56
-
57
- @Put('/:pk/:sk')
58
- async update(
59
- @Param() key: DetailDto,
60
- @Body() updateDto: MasterSettingUpdateDto,
61
- @INVOKE_CONTEXT() invokeContext: IInvoke,
62
- ) {
63
- const userContext = getUserContext(invokeContext)
64
-
65
- const { tenantCode } = parsePk(key.pk)
66
-
67
- if (userContext.tenantCode !== tenantCode) {
68
- throw new BadRequestException('Invalid tenant code')
69
- }
70
- return this.masterSettingService.update(key, updateDto, invokeContext)
71
- }
72
-
73
- @Delete('/:pk/:sk')
74
- async delete(
75
- @Param() key: DetailDto,
76
- @INVOKE_CONTEXT() invokeContext: IInvoke,
77
- ) {
78
- const userContext = getUserContext(invokeContext)
79
-
80
- const { tenantCode } = parsePk(key.pk)
81
-
82
- if (userContext.tenantCode !== tenantCode) {
83
- throw new BadRequestException('Invalid tenant code')
84
- }
85
- return this.masterSettingService.delete(key, invokeContext)
86
- }
87
-
88
- @Post('/check-exist/:code')
89
- async checkExistCode(
90
- @Param('code') code: string,
91
- @INVOKE_CONTEXT() invokeContext: IInvoke,
92
- ) {
93
- return this.masterSettingService.checkExistCode(code, invokeContext)
94
- }
95
-
96
16
  @Post('/copy')
97
17
  async copyMaster(
98
18
  @INVOKE_CONTEXT() invokeContext: IInvoke,
@@ -1,161 +1,19 @@
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'
1
+ import { DataService, getUserContext, IInvoke } from '@mbc-cqrs-serverless/core'
2
+ import { DataCopyMode, MasterCopyDto } from '@mbc-cqrs-serverless/master'
10
3
  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'
4
+ import { BadRequestException, Injectable, Logger } from '@nestjs/common'
19
5
 
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'
6
+ import { MASTER_COPY_SK_PREFIX, parseId } from './helpers'
31
7
 
32
8
  @Injectable()
33
9
  export class CustomMasterSettingService {
34
10
  private readonly logger = new Logger(CustomMasterSettingService.name)
35
11
 
36
12
  constructor(
37
- private readonly masterSettingService: MasterSettingService,
38
- private readonly prismaService: PrismaService,
39
13
  private readonly dataService: DataService,
40
14
  private readonly taskService: TaskService,
41
15
  ) {}
42
16
 
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
17
  async copy(
160
18
  masterCopyDto: MasterCopyDto,
161
19
  opts: { invokeContext: IInvoke },
@@ -194,8 +52,4 @@ export class CustomMasterSettingService {
194
52
 
195
53
  return taskItem
196
54
  }
197
-
198
- private getUserTenantCode(userContext: UserContext): string {
199
- return userContext.tenantCode
200
- }
201
55
  }
@@ -3,12 +3,11 @@ import { MasterModule as CoreMasterModule } from '@mbc-cqrs-serverless/master'
3
3
  import { SequencesModule } from '@mbc-cqrs-serverless/sequence'
4
4
  import { Module } from '@nestjs/common'
5
5
  import { CustomTaskModule } from 'src/custom-task/custom-task.module'
6
+ import { PrismaService } from 'src/prisma'
6
7
 
7
8
  import { MasterDataSyncRdsHandler } from './handler/master-rds.handler'
8
9
  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'
10
+ import { CustomMasterSettingController } from './master-setting.controller'
12
11
  import { CustomMasterSettingService } from './master-setting.service'
13
12
 
14
13
  @Module({
@@ -17,20 +16,16 @@ import { CustomMasterSettingService } from './master-setting.service'
17
16
  tableName: 'master',
18
17
  dataSyncHandlers: [MasterDataSyncRdsHandler],
19
18
  }),
20
-
21
19
  CoreMasterModule.register({
22
- enableController: false,
20
+ enableController: true,
21
+ prismaService: PrismaService,
23
22
  dataSyncHandlers: [MasterDataSyncRdsHandler],
24
23
  }),
25
24
  CustomTaskModule,
26
25
  SequencesModule,
27
26
  ],
28
- controllers: [MasterDataController, MasterSettingController],
29
- providers: [
30
- CustomMasterDataService,
31
- CustomMasterSettingService,
32
- MasterSfnTaskEventHandler,
33
- ],
34
- exports: [CustomMasterSettingService, CoreMasterModule],
27
+ controllers: [CustomMasterSettingController],
28
+ providers: [CustomMasterSettingService, MasterSfnTaskEventHandler],
29
+ exports: [],
35
30
  })
36
31
  export class MasterModule {}
@@ -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,98 +0,0 @@
1
- import {
2
- DetailDto,
3
- getUserContext,
4
- IInvoke,
5
- INVOKE_CONTEXT,
6
- } from '@mbc-cqrs-serverless/core'
7
- import {
8
- BadRequestException,
9
- Body,
10
- Controller,
11
- Delete,
12
- Get,
13
- Injectable,
14
- Param,
15
- Post,
16
- Put,
17
- Query,
18
- } from '@nestjs/common'
19
- import { ApiTags } from '@nestjs/swagger'
20
-
21
- import { MasterDataCreateDto } from './dto/master-data-create.dto'
22
- import { MasterDataSearchDto } from './dto/master-data-search.dto'
23
- import { MasterDataUpdateDto } from './dto/master-data-update.dto'
24
- import { parsePk } from './helpers'
25
- import { CustomMasterDataService } from './master-data.service'
26
-
27
- @ApiTags('master-data')
28
- @Controller('api/master-data')
29
- @Injectable()
30
- export class MasterDataController {
31
- constructor(private readonly masterDataService: CustomMasterDataService) {}
32
-
33
- @Get('/')
34
- async list(
35
- @Query() searchDto: MasterDataSearchDto,
36
- @INVOKE_CONTEXT() invokeContext: IInvoke,
37
- ) {
38
- return this.masterDataService.list(searchDto, invokeContext)
39
- }
40
-
41
- @Get('/:pk/:sk')
42
- async getDetail(@Param() key: DetailDto) {
43
- return this.masterDataService.getDetail(key)
44
- }
45
-
46
- @Post('/')
47
- async create(
48
- @Body() createDto: MasterDataCreateDto,
49
- @INVOKE_CONTEXT() invokeContext: IInvoke,
50
- ) {
51
- return this.masterDataService.create(createDto, invokeContext)
52
- }
53
-
54
- @Put('/:pk/:sk')
55
- async update(
56
- @Param() key: DetailDto,
57
- @Body() updateDto: MasterDataUpdateDto,
58
- @INVOKE_CONTEXT() invokeContext: IInvoke,
59
- ) {
60
- const userContext = getUserContext(invokeContext)
61
-
62
- const { tenantCode } = parsePk(key.pk)
63
-
64
- if (userContext.tenantCode !== tenantCode) {
65
- throw new BadRequestException('Invalid tenant code')
66
- }
67
- return this.masterDataService.update(key, updateDto, invokeContext)
68
- }
69
-
70
- @Delete('/:pk/:sk')
71
- async delete(
72
- @Param() key: DetailDto,
73
- @INVOKE_CONTEXT() invokeContext: IInvoke,
74
- ) {
75
- const userContext = getUserContext(invokeContext)
76
-
77
- const { tenantCode } = parsePk(key.pk)
78
-
79
- if (userContext.tenantCode !== tenantCode) {
80
- throw new BadRequestException('Invalid tenant code')
81
- }
82
-
83
- return this.masterDataService.delete(key, invokeContext)
84
- }
85
-
86
- @Post('/check-exist/:settingCode/:code')
87
- async checkExistCode(
88
- @Param('settingCode') settingCode: string,
89
- @Param('code') code: string,
90
- @INVOKE_CONTEXT() invokeContext: IInvoke,
91
- ) {
92
- return this.masterDataService.checkExistCode(
93
- settingCode,
94
- code,
95
- invokeContext,
96
- )
97
- }
98
- }