rez_core 1.0.78 → 1.0.79
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/module/meta/controller/entity.controller.d.ts +1 -1
- package/dist/module/meta/controller/entity.controller.js +6 -5
- package/dist/module/meta/controller/entity.controller.js.map +1 -1
- package/dist/module/meta/entity.module.js +3 -0
- package/dist/module/meta/entity.module.js.map +1 -1
- package/dist/module/meta/service/entity-service-impl.service.d.ts +1 -1
- package/dist/module/meta/service/entity-service-impl.service.js +9 -6
- package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
- package/dist/module/meta/service/entity-validation.service.d.ts +17 -0
- package/dist/module/meta/service/entity-validation.service.js +76 -0
- package/dist/module/meta/service/entity-validation.service.js.map +1 -0
- package/dist/module/meta/service/entity.service.d.ts +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/meta/controller/entity.controller.ts +3 -0
- package/src/module/meta/entity.module.ts +3 -0
- package/src/module/meta/service/entity-service-impl.service.ts +20 -14
- package/src/module/meta/service/entity-validation.service.ts +95 -0
- package/src/module/meta/service/entity.service.ts +1 -0
package/package.json
CHANGED
|
@@ -159,15 +159,18 @@ export class EntityController {
|
|
|
159
159
|
@Param('entity_type') entityType: string,
|
|
160
160
|
@Query('list_entity_type') listEntityType: string,
|
|
161
161
|
@Query('display_type') displayType: string,
|
|
162
|
+
@Query('sample_export') sampleExport: boolean,
|
|
162
163
|
@Query() filterCriteria: Record<string, any>,
|
|
163
164
|
@Res() res: Response, // Express Response for file handling
|
|
164
165
|
) {
|
|
165
166
|
try {
|
|
167
|
+
|
|
166
168
|
const filePath = await this.entityService.generateExcelReport(
|
|
167
169
|
entityType,
|
|
168
170
|
filterCriteria,
|
|
169
171
|
listEntityType,
|
|
170
172
|
displayType,
|
|
173
|
+
sampleExport
|
|
171
174
|
);
|
|
172
175
|
|
|
173
176
|
if (!filePath || !fs.existsSync(filePath)) {
|
|
@@ -35,6 +35,7 @@ import { ViewMasterService } from './service/view-master.service';
|
|
|
35
35
|
import { ViewMasterController } from './controller/view-master.controller';
|
|
36
36
|
import { ViewMaterRespository } from './repository/view-master.repository';
|
|
37
37
|
import { MetaController } from './controller/meta.controller';
|
|
38
|
+
import { EntityValidationService } from './service/entity-validation.service';
|
|
38
39
|
|
|
39
40
|
@Module({
|
|
40
41
|
imports: [
|
|
@@ -71,6 +72,7 @@ import { MetaController } from './controller/meta.controller';
|
|
|
71
72
|
SectionMasterService,
|
|
72
73
|
FieldGroupService,
|
|
73
74
|
ViewMaterRespository,
|
|
75
|
+
EntityValidationService,
|
|
74
76
|
{ provide: 'ViewMasterService', useClass: ViewMasterService },
|
|
75
77
|
],
|
|
76
78
|
exports: [
|
|
@@ -79,6 +81,7 @@ import { MetaController } from './controller/meta.controller';
|
|
|
79
81
|
PreferenceService,
|
|
80
82
|
EntityListService,
|
|
81
83
|
EntityTableService,
|
|
84
|
+
EntityValidationService,
|
|
82
85
|
EntityTableColumnService,
|
|
83
86
|
MediaDataService,
|
|
84
87
|
SectionMasterService,
|
|
@@ -186,6 +186,7 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
|
|
|
186
186
|
filterCriteria: Record<string, any>,
|
|
187
187
|
listEntityType: string,
|
|
188
188
|
displayType: string,
|
|
189
|
+
sampleExport: boolean,
|
|
189
190
|
): Promise<string | null> {
|
|
190
191
|
let fileName: string;
|
|
191
192
|
try {
|
|
@@ -196,6 +197,7 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
|
|
|
196
197
|
filterCriteria,
|
|
197
198
|
listEntityType,
|
|
198
199
|
displayType,
|
|
200
|
+
sampleExport
|
|
199
201
|
);
|
|
200
202
|
|
|
201
203
|
const modifiedDate = new Date().toISOString().replace(/[-T:.Z]/g, '');
|
|
@@ -218,19 +220,20 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
|
|
|
218
220
|
filterCriteria: Record<string, any>,
|
|
219
221
|
listEntityType: string,
|
|
220
222
|
displayType: string,
|
|
223
|
+
sampleExport: boolean,
|
|
221
224
|
) {
|
|
222
|
-
const sheet: ExcelsheetData = {
|
|
223
|
-
sheetName: entityType,
|
|
224
|
-
headers: [],
|
|
225
|
-
rowList: [],
|
|
226
|
-
};
|
|
227
|
-
|
|
228
225
|
const entityTable =
|
|
229
226
|
await this.entityTableService.findByEntityTypeAndListTypeAndDisplayType(
|
|
230
227
|
entityType,
|
|
231
228
|
listEntityType,
|
|
232
229
|
displayType,
|
|
233
230
|
);
|
|
231
|
+
const sheet: ExcelsheetData = {
|
|
232
|
+
sheetName: entityTable?.data_source || 'sheet',
|
|
233
|
+
headers: [],
|
|
234
|
+
rowList: [],
|
|
235
|
+
};
|
|
236
|
+
|
|
234
237
|
if (entityTable) {
|
|
235
238
|
const entityTableColumnList =
|
|
236
239
|
await this.entityTableColumnService.findByParentIdAndParentType(
|
|
@@ -243,14 +246,17 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
|
|
|
243
246
|
(col) => col.attribute_key,
|
|
244
247
|
);
|
|
245
248
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
let filteredList: any[] = [];
|
|
250
|
+
if(!sampleExport) {
|
|
251
|
+
filteredList = await this.entityListService.getFilteredList(
|
|
252
|
+
entityTable,
|
|
253
|
+
filterCriteria,
|
|
254
|
+
undefined,
|
|
255
|
+
undefined,
|
|
256
|
+
undefined,
|
|
257
|
+
undefined,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
254
260
|
|
|
255
261
|
sheet.rowList = filteredList.map((item) =>
|
|
256
262
|
attributeList.map((attr) =>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { AttributeMasterService } from 'src/module/meta/service/attribute-master.service';
|
|
3
|
+
import { AttributeMaster } from '../entity/attribute-master.entity';
|
|
4
|
+
import { ReflectionHelper } from 'src/utils/service/reflection-helper.service';
|
|
5
|
+
|
|
6
|
+
interface ValidationError {
|
|
7
|
+
field: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class EntityValidationService {
|
|
13
|
+
constructor(
|
|
14
|
+
private readonly attributeMasterService: AttributeMasterService,
|
|
15
|
+
private readonly reflectionHelper: ReflectionHelper
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Validates required fields based on attribute metadata.
|
|
20
|
+
*/
|
|
21
|
+
validateRequiredFields(
|
|
22
|
+
entityData: Record<string, any>,
|
|
23
|
+
attributeData: AttributeMaster[],
|
|
24
|
+
): ValidationError[] {
|
|
25
|
+
const errors: ValidationError[] = [];
|
|
26
|
+
|
|
27
|
+
attributeData
|
|
28
|
+
.filter(attr => attr.required)
|
|
29
|
+
.forEach(attr => {
|
|
30
|
+
const value = entityData[attr.code];
|
|
31
|
+
if (!this.hasValidValue(value)) {
|
|
32
|
+
errors.push({
|
|
33
|
+
field: attr.code,
|
|
34
|
+
message: `Field "${attr.code}" is required.`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return errors;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Validates uniqueness of fields based on attribute metadata.
|
|
44
|
+
*/
|
|
45
|
+
async validateUniqueFields(
|
|
46
|
+
entityData: Record<string, any>,
|
|
47
|
+
attributeData: AttributeMaster[],
|
|
48
|
+
entityType: string
|
|
49
|
+
): Promise<ValidationError[]> {
|
|
50
|
+
const errors: ValidationError[] = [];
|
|
51
|
+
|
|
52
|
+
const repo = this.reflectionHelper.getRepoService(entityData.entity_type);
|
|
53
|
+
|
|
54
|
+
if (!repo) {
|
|
55
|
+
throw new Error(`Repository service not found for entityType: ${entityType}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const attr of attributeData.filter(a => a.is_unique)) {
|
|
59
|
+
const value = entityData[attr.code];
|
|
60
|
+
if (this.hasValidValue(value)) {
|
|
61
|
+
const existing = await repo.findOne({ where: { [attr.code]: value } });
|
|
62
|
+
if (existing) {
|
|
63
|
+
errors.push({
|
|
64
|
+
field: attr.code,
|
|
65
|
+
message: `Field "${attr.code}" must be unique. Value "${value}" already exists.`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return errors;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Validates both required and unique fields for a given entity type.
|
|
77
|
+
*/
|
|
78
|
+
async validateEntityData(
|
|
79
|
+
entityData: Record<string, any>
|
|
80
|
+
): Promise<ValidationError[]> {
|
|
81
|
+
const attributes = await this.attributeMasterService.findAttributesByMappedEntityType(entityData.entity_type);
|
|
82
|
+
|
|
83
|
+
const requiredErrors = this.validateRequiredFields(entityData, attributes);
|
|
84
|
+
const uniqueErrors = await this.validateUniqueFields(entityData, attributes, entityData.entity_type);
|
|
85
|
+
|
|
86
|
+
return [...requiredErrors, ...uniqueErrors];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
private hasValidValue(value: any): boolean {
|
|
91
|
+
if (value === null || value === undefined) return false;
|
|
92
|
+
if (typeof value === 'string' && value.trim() === '') return false;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|