@solidstarters/solid-core 1.2.112 → 1.2.114
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/services/import-transaction.service.d.ts +2 -0
- package/dist/services/import-transaction.service.d.ts.map +1 -1
- package/dist/services/import-transaction.service.js +31 -3
- package/dist/services/import-transaction.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/services/import-transaction.service.ts +39 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidstarters/solid-core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.114",
|
|
4
4
|
"description": "This module is a NestJS module containing all the required core providers required by a Solid application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -248,6 +248,12 @@ export class ImportTransactionService extends CRUDService<ImportTransaction> {
|
|
|
248
248
|
JSON.parse(importTransaction.mapping) as ImportMapping[], // Parse the mapping from the import transaction
|
|
249
249
|
importTransaction.modelMetadata,
|
|
250
250
|
);
|
|
251
|
+
|
|
252
|
+
// Update the import transaction status to 'completed'
|
|
253
|
+
importTransaction.status = 'import_succeeded';
|
|
254
|
+
// Save the import transaction
|
|
255
|
+
await this.repo.save(importTransaction);
|
|
256
|
+
|
|
251
257
|
return {status: importTransaction.status, importedIds: ids}; // Return the IDs of the created records
|
|
252
258
|
}
|
|
253
259
|
|
|
@@ -331,7 +337,7 @@ export class ImportTransactionService extends CRUDService<ImportTransaction> {
|
|
|
331
337
|
): Promise<Array<number>> {
|
|
332
338
|
// Get the model service for the model metadata name
|
|
333
339
|
const modelService = this.getModelService(modelMetadataWithFields.singularName);
|
|
334
|
-
|
|
340
|
+
const createdRecordIds = [];
|
|
335
341
|
// Depending upon the mime type of the file, read the file in pages
|
|
336
342
|
// For CSV files, use the csvService to read the file in pages
|
|
337
343
|
// For Excel files, use the excelService to read the file in pages
|
|
@@ -344,7 +350,9 @@ export class ImportTransactionService extends CRUDService<ImportTransaction> {
|
|
|
344
350
|
const createdRecords = await modelService.insertMany(dtos, [], {});
|
|
345
351
|
// Set the solidRequestContext to null, as this is a background job;
|
|
346
352
|
// Return the IDs of the created records
|
|
347
|
-
|
|
353
|
+
const newIds = createdRecords.map(record => record.id);
|
|
354
|
+
// Add the new IDs to the createdRecordIds array
|
|
355
|
+
createdRecordIds.push(...newIds);
|
|
348
356
|
}
|
|
349
357
|
}
|
|
350
358
|
else if (mimeType === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
|
|
@@ -356,11 +364,13 @@ export class ImportTransactionService extends CRUDService<ImportTransaction> {
|
|
|
356
364
|
const createdRecords = await modelService.insertMany(dtos, [], {});
|
|
357
365
|
// Set the solidRequestContext to null, as this is a background job;
|
|
358
366
|
// Return the IDs of the created records
|
|
359
|
-
|
|
367
|
+
const newIds = createdRecords.map(record => record.id);
|
|
368
|
+
createdRecordIds.push(...newIds);
|
|
360
369
|
}
|
|
361
370
|
} else { // If the file is neither CSV nor Excel, throw an error
|
|
362
371
|
throw new Error(`Unsupported file type: ${mimeType}`);
|
|
363
372
|
}
|
|
373
|
+
return createdRecordIds; // Return the IDs of the created records
|
|
364
374
|
}
|
|
365
375
|
|
|
366
376
|
private getModelService(modelSingularName: string): CRUDService<any> {
|
|
@@ -411,18 +421,43 @@ export class ImportTransactionService extends CRUDService<ImportTransaction> {
|
|
|
411
421
|
const fieldType = fieldMetadata.type;
|
|
412
422
|
// const userKeyFieldName = userKeyField?.name || 'id'; // Default to 'id' if not found
|
|
413
423
|
|
|
424
|
+
// TODO Move this logic to field crud managers i.e add a parse method to the field crud manager interface
|
|
414
425
|
switch (fieldType) {
|
|
415
426
|
case SolidFieldType.relation: {
|
|
416
427
|
return await this.populateDtoForRelations(fieldMetadata, record, key, dtoRecord);
|
|
417
428
|
}
|
|
418
|
-
case SolidFieldType.date:
|
|
429
|
+
case SolidFieldType.date:
|
|
419
430
|
case SolidFieldType.datetime: return this.populateDtoForDate(record, key, fieldMetadata, dtoRecord);
|
|
431
|
+
case SolidFieldType.int:
|
|
432
|
+
case SolidFieldType.bigint:
|
|
433
|
+
case SolidFieldType.decimal:
|
|
434
|
+
return this.populateDtoForNumber(dtoRecord, fieldMetadata, record, key);
|
|
435
|
+
case SolidFieldType.boolean:
|
|
436
|
+
return this.populateDtoForBoolean(dtoRecord, fieldMetadata, record, key);
|
|
420
437
|
default:
|
|
421
438
|
dtoRecord[fieldMetadata.name] = record[key];
|
|
422
439
|
return dtoRecord;
|
|
423
440
|
}
|
|
424
441
|
}
|
|
425
442
|
|
|
443
|
+
private populateDtoForBoolean(dtoRecord: Record<string, any>, fieldMetadata: FieldMetadata, record: Record<string, any>, key: string) {
|
|
444
|
+
const booleanValue = Boolean(record[key]);
|
|
445
|
+
if (typeof booleanValue !== 'boolean') {
|
|
446
|
+
throw new Error(`Invalid boolean value for field ${fieldMetadata.name}: ${record[key]}`);
|
|
447
|
+
}
|
|
448
|
+
dtoRecord[fieldMetadata.name] = booleanValue;
|
|
449
|
+
return dtoRecord;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private populateDtoForNumber(dtoRecord: Record<string, any>, fieldMetadata: FieldMetadata, record: Record<string, any>, key: string) {
|
|
453
|
+
const numberValue = Number(record[key]);
|
|
454
|
+
if (isNaN(numberValue)) {
|
|
455
|
+
throw new Error(`Invalid number value for field ${fieldMetadata.name}: ${record[key]}`);
|
|
456
|
+
}
|
|
457
|
+
dtoRecord[fieldMetadata.name] = numberValue;
|
|
458
|
+
return dtoRecord;
|
|
459
|
+
}
|
|
460
|
+
|
|
426
461
|
private populateDtoForDate(record: Record<string, any>, key: string, fieldMetadata: FieldMetadata, dtoRecord: Record<string, any>) {
|
|
427
462
|
{
|
|
428
463
|
const dateValue = new Date(record[key]);
|