@mbc-cqrs-serverless/master 0.1.66-beta.0 → 0.1.68-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.
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +2 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/interfaces/master-data.interface.d.ts +3 -0
- package/dist/interfaces/master-setting.interface.d.ts +4 -1
- package/dist/services/master-data.service.d.ts +14 -0
- package/dist/services/master-data.service.js +10 -0
- package/dist/services/master-data.service.js.map +1 -1
- package/dist/services/master-setting.service.d.ts +15 -1
- package/dist/services/master-setting.service.js +10 -0
- package/dist/services/master-setting.service.js.map +1 -1
- package/dist/services/master-setting.service.spec.d.ts +1 -0
- package/dist/services/master-setting.service.spec.js +662 -0
- package/dist/services/master-setting.service.spec.js.map +1 -0
- package/dist/update-scheme.js +262 -14
- package/dist/update-scheme.js.map +1 -1
- package/package.json +6 -4
- package/src/templates/custom-task/custom-task.module.ts +18 -0
- package/src/templates/custom-task/event/task-queue-event-factory.ts +26 -0
- package/src/templates/custom-task/my-task.controller.ts +28 -0
- package/src/templates/custom-task/my-task.service.ts +99 -0
- package/src/templates/master/dto/master-copy.dto.ts +73 -0
- package/src/templates/master/dto/master-data-create.dto.ts +20 -0
- package/src/templates/master/dto/master-data-search.dto.ts +20 -0
- package/src/templates/master/dto/master-data-update.dto.ts +25 -0
- package/src/templates/master/dto/master-rds-list.entity.ts +15 -0
- package/src/templates/master/dto/master-rds.entity.ts +77 -0
- package/src/templates/master/dto/master-setting-search.dto.ts +20 -0
- package/src/templates/master/dto/master-setting-update.dto.ts +11 -0
- package/src/templates/master/entity/master-command.entity.ts +11 -0
- package/src/templates/master/entity/master-data-list.entity.ts +13 -0
- package/src/templates/master/entity/master-data.entity.ts +11 -0
- package/src/templates/master/handler/master-rds.handler.ts +75 -0
- package/src/templates/master/handler/master-sfn-task.event.ts +3 -0
- package/src/templates/master/handler/master-sfn-task.handler.ts +334 -0
- package/src/templates/master/helpers/get-order.ts +19 -0
- package/src/templates/master/helpers/id.ts +42 -0
- package/src/templates/master/helpers/index.ts +3 -0
- package/src/templates/master/helpers/key.ts +11 -0
- package/src/templates/master/master-data.controller.ts +98 -0
- package/src/templates/master/master-data.service.ts +181 -0
- package/src/templates/master/master-setting.controller.ts +103 -0
- package/src/templates/master/master-setting.service.ts +201 -0
- package/src/templates/master/master.module.ts +36 -0
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataService,
|
|
3
|
+
DetailDto,
|
|
4
|
+
getUserContext,
|
|
5
|
+
IInvoke,
|
|
6
|
+
UserContext,
|
|
7
|
+
} from '@mbc-cqrs-serverless/core'
|
|
8
|
+
import { MasterDataService } from '@mbc-cqrs-serverless/master'
|
|
9
|
+
import { Injectable, NotFoundException, Param } from '@nestjs/common'
|
|
10
|
+
import { Prisma } from '@prisma/client'
|
|
11
|
+
import { PrismaService } from 'src/prisma'
|
|
12
|
+
import { ulid } from 'ulid'
|
|
13
|
+
|
|
14
|
+
import { MasterDataCreateDto } from './dto/master-data-create.dto'
|
|
15
|
+
import { MasterDataSearchDto } from './dto/master-data-search.dto'
|
|
16
|
+
import { MasterDataUpdateDto } from './dto/master-data-update.dto'
|
|
17
|
+
import { MasterRdsEntity } from './dto/master-rds.entity'
|
|
18
|
+
import { MasterRdsListEntity } from './dto/master-rds-list.entity'
|
|
19
|
+
import { DATA_SK_PREFIX, getOrderBys, SETTING_SK_PREFIX } from './helpers'
|
|
20
|
+
|
|
21
|
+
@Injectable()
|
|
22
|
+
export class CustomMasterDataService {
|
|
23
|
+
constructor(
|
|
24
|
+
private readonly masterDataService: MasterDataService,
|
|
25
|
+
private readonly prismaService: PrismaService,
|
|
26
|
+
private readonly dataService: DataService,
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
async list(searchDto: MasterDataSearchDto, invokeContext: IInvoke) {
|
|
30
|
+
const userContext = getUserContext(invokeContext)
|
|
31
|
+
const deletedSettingData = await this.prismaService.master.findMany({
|
|
32
|
+
where: {
|
|
33
|
+
tenantCode: this.getTenantCode(userContext),
|
|
34
|
+
isDeleted: true,
|
|
35
|
+
masterType: SETTING_SK_PREFIX,
|
|
36
|
+
},
|
|
37
|
+
select: {
|
|
38
|
+
masterCode: true,
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const deletedSettingCode = deletedSettingData.map(
|
|
43
|
+
(setting) => setting.masterCode,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
const where: Prisma.MasterWhereInput = {
|
|
47
|
+
tenantCode: this.getTenantCode(userContext),
|
|
48
|
+
masterType: DATA_SK_PREFIX,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (deletedSettingCode.length > 0) {
|
|
52
|
+
where.masterTypeCode = {
|
|
53
|
+
notIn: deletedSettingCode,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (searchDto.isDeleted === false || searchDto.isDeleted === undefined) {
|
|
58
|
+
where.isDeleted = false
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const andConditions: Prisma.MasterWhereInput[] = []
|
|
62
|
+
|
|
63
|
+
if (searchDto.keyword?.trim()) {
|
|
64
|
+
andConditions.push({
|
|
65
|
+
name: { contains: searchDto.keyword.trim() },
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (searchDto.code?.trim()) {
|
|
70
|
+
andConditions.push({
|
|
71
|
+
masterCode: { contains: searchDto.code.trim() },
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (searchDto.settingCode?.trim()) {
|
|
76
|
+
andConditions.push({
|
|
77
|
+
masterTypeCode: searchDto.settingCode.trim(),
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (andConditions.length) {
|
|
82
|
+
where.AND = andConditions
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
pageSize = 10,
|
|
87
|
+
page = 1,
|
|
88
|
+
orderBys = ['seq', 'masterCode'],
|
|
89
|
+
} = searchDto
|
|
90
|
+
|
|
91
|
+
const [total, items] = await Promise.all([
|
|
92
|
+
this.prismaService.master.count({ where }),
|
|
93
|
+
this.prismaService.master.findMany({
|
|
94
|
+
where,
|
|
95
|
+
take: pageSize,
|
|
96
|
+
skip: pageSize * (page - 1),
|
|
97
|
+
orderBy: getOrderBys<Prisma.MasterOrderByWithRelationInput>(orderBys),
|
|
98
|
+
}),
|
|
99
|
+
])
|
|
100
|
+
|
|
101
|
+
return new MasterRdsListEntity({
|
|
102
|
+
total,
|
|
103
|
+
items: items.map((item) => new MasterRdsEntity(item)),
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async getDetail(@Param() key: DetailDto) {
|
|
108
|
+
const data = await this.dataService.getItem(key)
|
|
109
|
+
|
|
110
|
+
if (!data) throw new NotFoundException()
|
|
111
|
+
|
|
112
|
+
return new MasterRdsEntity(data)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async create(createDto: MasterDataCreateDto, invokeContext: IInvoke) {
|
|
116
|
+
const userContext = getUserContext(invokeContext)
|
|
117
|
+
let seq = createDto?.seq
|
|
118
|
+
if (!seq) {
|
|
119
|
+
const maxSeq = await this.prismaService.master.aggregate({
|
|
120
|
+
_max: {
|
|
121
|
+
seq: true,
|
|
122
|
+
},
|
|
123
|
+
where: {
|
|
124
|
+
tenantCode: userContext.tenantCode,
|
|
125
|
+
masterType: DATA_SK_PREFIX,
|
|
126
|
+
masterTypeCode: createDto.settingCode,
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
seq = (maxSeq._max.seq ?? 0) + 1
|
|
130
|
+
createDto.attributes['seq'] = seq
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return await this.masterDataService.create(
|
|
134
|
+
{
|
|
135
|
+
code: createDto.code ?? ulid(),
|
|
136
|
+
tenantCode: userContext.tenantCode,
|
|
137
|
+
name: createDto.name,
|
|
138
|
+
settingCode: createDto.settingCode,
|
|
139
|
+
attributes: createDto.attributes ?? {},
|
|
140
|
+
seq,
|
|
141
|
+
},
|
|
142
|
+
{ invokeContext },
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async update(
|
|
147
|
+
key: DetailDto,
|
|
148
|
+
updateDto: MasterDataUpdateDto,
|
|
149
|
+
invokeContext: IInvoke,
|
|
150
|
+
) {
|
|
151
|
+
return await this.masterDataService.update(
|
|
152
|
+
key,
|
|
153
|
+
{
|
|
154
|
+
...updateDto,
|
|
155
|
+
},
|
|
156
|
+
{ invokeContext },
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async delete(key: DetailDto, invokeContext: IInvoke) {
|
|
161
|
+
return this.masterDataService.delete(key, { invokeContext })
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async checkExistCode(
|
|
165
|
+
settingCode: string,
|
|
166
|
+
code: string,
|
|
167
|
+
invokeContext: IInvoke,
|
|
168
|
+
) {
|
|
169
|
+
const userContext = getUserContext(invokeContext)
|
|
170
|
+
|
|
171
|
+
return this.masterDataService.checkExistCode(
|
|
172
|
+
userContext.tenantCode,
|
|
173
|
+
settingCode,
|
|
174
|
+
code,
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private getTenantCode(userContext: UserContext): string {
|
|
179
|
+
return userContext.tenantCode
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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'
|
|
20
|
+
import { ApiTags } from '@nestjs/swagger'
|
|
21
|
+
|
|
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
|
+
import { CustomMasterSettingService } from './master-setting.service'
|
|
27
|
+
|
|
28
|
+
@ApiTags('master-setting')
|
|
29
|
+
@Controller('api/master-setting')
|
|
30
|
+
@Injectable()
|
|
31
|
+
export class MasterSettingController {
|
|
32
|
+
constructor(
|
|
33
|
+
private readonly masterSettingService: CustomMasterSettingService,
|
|
34
|
+
) {}
|
|
35
|
+
|
|
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
|
+
@Post('/copy')
|
|
97
|
+
async copyMaster(
|
|
98
|
+
@INVOKE_CONTEXT() invokeContext: IInvoke,
|
|
99
|
+
@Body() masterCopyDto: MasterCopyDto,
|
|
100
|
+
): Promise<any> {
|
|
101
|
+
return this.masterSettingService.copy(masterCopyDto, { invokeContext })
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CommandModule } from '@mbc-cqrs-serverless/core'
|
|
2
|
+
import { MasterModule as CoreMasterModule } from '@mbc-cqrs-serverless/master'
|
|
3
|
+
import { SequencesModule } from '@mbc-cqrs-serverless/sequence'
|
|
4
|
+
import { Module } from '@nestjs/common'
|
|
5
|
+
import { CustomTaskModule } from 'src/custom-task/custom-task.module'
|
|
6
|
+
|
|
7
|
+
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
|
+
|
|
14
|
+
@Module({
|
|
15
|
+
imports: [
|
|
16
|
+
CommandModule.register({
|
|
17
|
+
tableName: 'master',
|
|
18
|
+
dataSyncHandlers: [MasterDataSyncRdsHandler],
|
|
19
|
+
}),
|
|
20
|
+
|
|
21
|
+
CoreMasterModule.register({
|
|
22
|
+
enableController: false,
|
|
23
|
+
dataSyncHandlers: [MasterDataSyncRdsHandler],
|
|
24
|
+
}),
|
|
25
|
+
CustomTaskModule,
|
|
26
|
+
SequencesModule,
|
|
27
|
+
],
|
|
28
|
+
controllers: [MasterDataController, MasterSettingController],
|
|
29
|
+
providers: [
|
|
30
|
+
CustomMasterDataService,
|
|
31
|
+
CustomMasterSettingService,
|
|
32
|
+
MasterSfnTaskEventHandler,
|
|
33
|
+
],
|
|
34
|
+
exports: [CustomMasterSettingService, CoreMasterModule],
|
|
35
|
+
})
|
|
36
|
+
export class MasterModule {}
|