rez_core 1.0.72 → 1.0.73

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "1.0.72",
3
+ "version": "1.0.73",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  BadRequestException,
3
+ Body,
3
4
  Controller,
4
5
  Inject,
5
6
  Param,
@@ -46,13 +47,20 @@ export class MasterController {
46
47
 
47
48
  @Post('uploadEntity/:entityType')
48
49
  @UseInterceptors(FileInterceptor('file'))
49
-
50
- async uploadEntityDataXls(@Param('entityType') entityType: string, @UploadedFile() file: Express.Multer.File,@Req() req: Request & { user: any }) {
50
+ async uploadEntityDataXls(
51
+ @Param('entityType') entityType: string,
52
+ @UploadedFile() file: Express.Multer.File,
53
+ @Req() req: Request & { user: any },
54
+ @Body('duplicateHandling') duplicateHandling: 'skip_duplicates' | 'overwrite_items',
55
+ ) {
51
56
  let requestedUser = req.user;
52
- let loggedInUser = await this.entityService.getEntityData(ENTITYTYPE_USER,requestedUser.id);
57
+ let loggedInUser = await this.entityService.getEntityData(ENTITYTYPE_USER, requestedUser.id);
58
+
53
59
  if (!file) {
54
60
  throw new BadRequestException('File is required');
55
61
  }
56
- return await this.masterService.uploadEntityData(file.buffer,entityType,loggedInUser);
62
+
63
+ return await this.masterService.uploadEntityData(file.buffer, entityType, loggedInUser, duplicateHandling);
57
64
  }
65
+
58
66
  }
@@ -134,7 +134,7 @@ export class MasterService {
134
134
  };
135
135
  }
136
136
 
137
- async uploadEntityData(file, entityType, loggedInUser) {
137
+ async uploadEntityData(file, entityType, loggedInUser, duplicateHandling: 'skip_duplicates' | 'overwrite_items') {
138
138
  const data = ExcelUtil.readExcel(file.buffer);
139
139
  const entityMaster = await this.entityMasterService.findByMappedEntityType(entityType);
140
140
  if (!entityMaster) {
@@ -143,22 +143,17 @@ export class MasterService {
143
143
 
144
144
  const tableName = entityMaster.db_table_name;
145
145
  const sheetData = data[tableName];
146
-
147
146
  if (!sheetData) {
148
147
  throw new Error(`Sheet for ${tableName} not found in uploaded file`);
149
148
  }
150
149
 
151
150
  const attributes = await this.attributeMasterService.findAttributesByMappedEntityType(entityType);
152
-
153
- const uniqueFields = attributes
154
- .filter(attr => attr.is_unique)
155
- .map(attr => attr.attribute_key);
151
+ const uniqueFields = attributes.filter(attr => attr.is_unique).map(attr => attr.attribute_key);
156
152
 
157
153
  if (uniqueFields.length === 0) {
158
154
  throw new Error(`No unique fields found for entityType: ${entityType}`);
159
155
  }
160
156
 
161
- // Transform reference fields
162
157
  for (const row of sheetData) {
163
158
  if (row.parent_type && row.parent_id) {
164
159
  await this.resolveParent(row);
@@ -181,11 +176,12 @@ export class MasterService {
181
176
  }
182
177
  }
183
178
 
184
- await this.upsertViaService(entityType, sheetData, attributes, uniqueFields, loggedInUser);
179
+ await this.upsertViaService(entityType, sheetData, attributes, uniqueFields, loggedInUser, duplicateHandling);
185
180
 
186
181
  return { message: 'Entity data uploaded successfully' };
187
182
  }
188
183
 
184
+
189
185
 
190
186
  private isMetaSheet(sheetName: string): boolean {
191
187
  return this.metaSheets.includes(sheetName.toLowerCase());
@@ -272,13 +268,13 @@ export class MasterService {
272
268
  attributes: any[],
273
269
  uniqueFields: string[],
274
270
  loggedInUser: any,
271
+ duplicateHandling: 'skip_duplicates' | 'overwrite_items',
275
272
  ): Promise<void> {
276
273
  const entityMaster = await this.entityMasterService.findByMappedEntityType(entityType);
277
274
  if (!entityMaster) throw new Error(`Entity master not found for ${entityType}`);
278
275
 
279
276
  const serviceName = entityMaster.entity_service;
280
277
  const entityService = await this.reflectionHelper.getBean<EntityServiceImpl>(serviceName);
281
-
282
278
  if (!entityService) throw new Error(`Entity service not found for ${entityType}`);
283
279
 
284
280
  for (const row of data) {
@@ -296,14 +292,20 @@ export class MasterService {
296
292
  .getRawOne();
297
293
 
298
294
  row.entity_type = entityType;
295
+
299
296
  if (existing) {
300
- row.id = existing.id;
301
- await entityService.updateEntity(row, loggedInUser);
297
+ if (duplicateHandling === 'skip_duplicates') {
298
+ continue; // Skip this row
299
+ } else if (duplicateHandling === 'overwrite_items') {
300
+ row.id = existing.id;
301
+ await entityService.updateEntity(row, loggedInUser);
302
+ }
302
303
  } else {
303
304
  await entityService.createEntity(row, loggedInUser);
304
305
  }
305
306
  }
306
307
  }
307
308
 
309
+
308
310
 
309
311
  }