@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.
- 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/controllers/master-data.controller.d.ts +6 -0
- package/dist/controllers/master-data.controller.js +74 -0
- package/dist/controllers/master-data.controller.js.map +1 -1
- package/dist/controllers/master-setting.controller.d.ts +7 -0
- package/dist/controllers/master-setting.controller.js +86 -0
- package/dist/controllers/master-setting.controller.js.map +1 -1
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +18 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/key.d.ts +1 -0
- package/dist/decorators/key.js +34 -0
- package/dist/decorators/key.js.map +1 -0
- package/dist/dto/index.d.ts +1 -0
- package/dist/dto/index.js +1 -0
- package/dist/dto/index.js.map +1 -1
- package/dist/dto/master-copy/index.d.ts +8 -0
- package/dist/dto/master-copy/index.js +25 -0
- package/dist/dto/master-copy/index.js.map +1 -0
- package/dist/dto/master-copy/master-copy.dto.d.ts +19 -0
- package/dist/dto/master-copy/master-copy.dto.js +92 -0
- package/dist/dto/master-copy/master-copy.dto.js.map +1 -0
- package/dist/dto/master-copy/master-data-create.dto.d.ts +7 -0
- package/dist/dto/master-copy/master-data-create.dto.js +43 -0
- package/dist/dto/master-copy/master-data-create.dto.js.map +1 -0
- package/dist/dto/master-copy/master-data-search.dto.d.ts +6 -0
- package/dist/dto/master-copy/master-data-search.dto.js +39 -0
- package/dist/dto/master-copy/master-data-search.dto.js.map +1 -0
- package/dist/dto/master-copy/master-data-update.dto.d.ts +6 -0
- package/dist/dto/master-copy/master-data-update.dto.js +41 -0
- package/dist/dto/master-copy/master-data-update.dto.js.map +1 -0
- package/dist/dto/master-copy/master-rds-list.entity.d.ts +6 -0
- package/dist/dto/master-copy/master-rds-list.entity.js +33 -0
- package/dist/dto/master-copy/master-rds-list.entity.js.map +1 -0
- package/dist/dto/master-copy/master-rds.entity.d.ts +26 -0
- package/dist/dto/master-copy/master-rds.entity.js +116 -0
- package/dist/dto/master-copy/master-rds.entity.js.map +1 -0
- package/dist/dto/master-copy/master-setting-search.dto.d.ts +6 -0
- package/dist/dto/master-copy/master-setting-search.dto.js +39 -0
- package/dist/dto/master-copy/master-setting-search.dto.js.map +1 -0
- package/dist/dto/master-copy/master-setting-update.dto.d.ts +4 -0
- package/dist/dto/master-copy/master-setting-update.dto.js +31 -0
- package/dist/dto/master-copy/master-setting-update.dto.js.map +1 -0
- package/dist/helpers/rds.d.ts +4 -0
- package/dist/helpers/rds.js +19 -0
- package/dist/helpers/rds.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/master-data.interface.d.ts +2 -2
- package/dist/master.module-definition.d.ts +2 -0
- package/dist/master.module-definition.js +2 -1
- package/dist/master.module-definition.js.map +1 -1
- package/dist/master.module.js +10 -0
- package/dist/master.module.js.map +1 -1
- package/dist/services/master-data.service.d.ts +10 -9
- package/dist/services/master-data.service.js +112 -4
- package/dist/services/master-data.service.js.map +1 -1
- package/dist/services/master-setting.service.d.ts +11 -3
- package/dist/services/master-setting.service.js +98 -2
- package/dist/services/master-setting.service.js.map +1 -1
- package/dist/services/master-setting.service.spec.js +11 -0
- package/dist/services/master-setting.service.spec.js.map +1 -1
- package/dist/update-scheme.js +1 -0
- package/dist/update-scheme.js.map +1 -1
- package/package.json +5 -4
- package/src/templates/master/handler/master-sfn-task.handler.ts +4 -6
- package/src/templates/master/master-setting.controller.ts +4 -84
- package/src/templates/master/master-setting.service.ts +4 -150
- package/src/templates/master/master.module.ts +7 -12
- package/src/templates/master/dto/master-copy.dto.ts +0 -73
- package/src/templates/master/dto/master-data-create.dto.ts +0 -20
- package/src/templates/master/dto/master-data-search.dto.ts +0 -20
- package/src/templates/master/dto/master-data-update.dto.ts +0 -25
- package/src/templates/master/dto/master-rds-list.entity.ts +0 -15
- package/src/templates/master/dto/master-rds.entity.ts +0 -77
- package/src/templates/master/dto/master-setting-search.dto.ts +0 -20
- package/src/templates/master/dto/master-setting-update.dto.ts +0 -11
- package/src/templates/master/master-data.controller.ts +0 -98
- package/src/templates/master/master-data.service.ts +0 -181
|
@@ -1,181 +0,0 @@
|
|
|
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
|
-
}
|