av6-core 1.0.8 → 1.0.9
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/.prettierignore +4 -0
- package/.prettierrc +6 -0
- package/dist/index.js +96 -262
- package/dist/index.mjs +96 -262
- package/package.json +5 -3
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/dist/index.js
CHANGED
|
@@ -303,9 +303,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
303
303
|
const totalPages = Math.ceil(totalRecords / pageSize);
|
|
304
304
|
const DTOClass = dtoMapping[shortCodeData.shortCode];
|
|
305
305
|
if (shortCodeData.isDTO && DTOClass) {
|
|
306
|
-
const DTOs = await Promise.all(
|
|
307
|
-
results.map((record) => DTOClass(record))
|
|
308
|
-
);
|
|
306
|
+
const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
|
|
309
307
|
return {
|
|
310
308
|
data: DTOs,
|
|
311
309
|
totalRecords,
|
|
@@ -381,10 +379,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
381
379
|
logger.info("exiting::commonSearch::repository");
|
|
382
380
|
return results;
|
|
383
381
|
},
|
|
384
|
-
async commonFetch({
|
|
385
|
-
id,
|
|
386
|
-
shortCodeData
|
|
387
|
-
}) {
|
|
382
|
+
async commonFetch({ id, shortCodeData }) {
|
|
388
383
|
logger.info("entering::commonFetch::repository");
|
|
389
384
|
const tableName = shortCodeData.tableName;
|
|
390
385
|
const model = db[tableName];
|
|
@@ -397,10 +392,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
397
392
|
logger.info("exiting::commonFetch::repository");
|
|
398
393
|
return results;
|
|
399
394
|
},
|
|
400
|
-
async commonDelete({
|
|
401
|
-
id,
|
|
402
|
-
shortCodeData
|
|
403
|
-
}) {
|
|
395
|
+
async commonDelete({ id, shortCodeData }) {
|
|
404
396
|
logger.info("entering::commonDelete::repository");
|
|
405
397
|
const tableName = shortCodeData.tableName;
|
|
406
398
|
const store = requestStorage.getStore();
|
|
@@ -419,11 +411,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
419
411
|
logger.info("exiting::commonDelete::repository");
|
|
420
412
|
return results;
|
|
421
413
|
},
|
|
422
|
-
async commonUpdateStatus({
|
|
423
|
-
id,
|
|
424
|
-
shortCodeData,
|
|
425
|
-
status
|
|
426
|
-
}) {
|
|
414
|
+
async commonUpdateStatus({ id, shortCodeData, status }) {
|
|
427
415
|
logger.info("entering::commonUpdateStatus::repository");
|
|
428
416
|
const tableName = shortCodeData.tableName;
|
|
429
417
|
const model = db[tableName];
|
|
@@ -473,24 +461,17 @@ var commonRepository = (serviceDeps) => {
|
|
|
473
461
|
const rootCondition = {};
|
|
474
462
|
if (fixedSearch) {
|
|
475
463
|
for (const [field, defObj] of Object.entries(fixedSearch)) {
|
|
476
|
-
if (!defObj || !Array.isArray(defObj.value) || defObj.value.length === 0)
|
|
477
|
-
continue;
|
|
464
|
+
if (!defObj || !Array.isArray(defObj.value) || defObj.value.length === 0) continue;
|
|
478
465
|
const fieldPath = field.split(".");
|
|
479
466
|
const fieldType = defObj.type;
|
|
480
467
|
const fieldValues = defObj.value;
|
|
481
|
-
const cond = buildFieldCondition(
|
|
482
|
-
fieldPath,
|
|
483
|
-
fieldType,
|
|
484
|
-
fieldValues,
|
|
485
|
-
false
|
|
486
|
-
);
|
|
468
|
+
const cond = buildFieldCondition(fieldPath, fieldType, fieldValues, false);
|
|
487
469
|
mergeTopLevel(rootCondition, cond);
|
|
488
470
|
}
|
|
489
471
|
}
|
|
490
472
|
if (fixedNotSearch) {
|
|
491
473
|
for (const [field, defObj] of Object.entries(fixedNotSearch)) {
|
|
492
|
-
if (!defObj || !Array.isArray(defObj.value) || defObj.value.length === 0)
|
|
493
|
-
continue;
|
|
474
|
+
if (!defObj || !Array.isArray(defObj.value) || defObj.value.length === 0) continue;
|
|
494
475
|
const fieldPath = field.split(".");
|
|
495
476
|
const fieldType = defObj.type;
|
|
496
477
|
const fieldValues = defObj.value;
|
|
@@ -528,50 +509,24 @@ var commonRepository = (serviceDeps) => {
|
|
|
528
509
|
for (const sc of searchColumns) {
|
|
529
510
|
const { col, type: colType } = sc;
|
|
530
511
|
if (colType === "string") {
|
|
531
|
-
searchOR.push(
|
|
532
|
-
buildNestedConditionForSingleValue(
|
|
533
|
-
col.split("."),
|
|
534
|
-
"string",
|
|
535
|
-
searchText
|
|
536
|
-
)
|
|
537
|
-
);
|
|
512
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "string", searchText));
|
|
538
513
|
} else if (colType === "number") {
|
|
539
514
|
const numVal = parseFloat(searchText);
|
|
540
515
|
if (!isNaN(numVal)) {
|
|
541
|
-
searchOR.push(
|
|
542
|
-
buildNestedConditionForSingleValue(
|
|
543
|
-
col.split("."),
|
|
544
|
-
"number",
|
|
545
|
-
numVal
|
|
546
|
-
)
|
|
547
|
-
);
|
|
516
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "number", numVal));
|
|
548
517
|
}
|
|
549
518
|
} else if (colType === "boolean") {
|
|
550
519
|
const boolVal = searchText.toLowerCase();
|
|
551
520
|
if (boolVal === "true" || boolVal === "false") {
|
|
552
|
-
searchOR.push(
|
|
553
|
-
buildNestedConditionForSingleValue(
|
|
554
|
-
col.split("."),
|
|
555
|
-
"boolean",
|
|
556
|
-
boolVal === "true"
|
|
557
|
-
)
|
|
558
|
-
);
|
|
521
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "boolean", boolVal === "true"));
|
|
559
522
|
}
|
|
560
523
|
} else if (colType === "date") {
|
|
561
524
|
const dt = new Date(searchText);
|
|
562
525
|
if (!isNaN(dt.getTime())) {
|
|
563
|
-
searchOR.push(
|
|
564
|
-
buildNestedConditionForSingleValue(col.split("."), "date", dt)
|
|
565
|
-
);
|
|
526
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "date", dt));
|
|
566
527
|
}
|
|
567
528
|
} else {
|
|
568
|
-
searchOR.push(
|
|
569
|
-
buildNestedConditionForSingleValue(
|
|
570
|
-
col.split("."),
|
|
571
|
-
"string",
|
|
572
|
-
searchText
|
|
573
|
-
)
|
|
574
|
-
);
|
|
529
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "string", searchText));
|
|
575
530
|
}
|
|
576
531
|
}
|
|
577
532
|
searchOR = transformData(searchOR);
|
|
@@ -639,9 +594,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
639
594
|
const totalPages = Math.ceil(totalRecords / pageSize);
|
|
640
595
|
const DTOClass = dtoMapping[shortCodeData.shortCode];
|
|
641
596
|
if (shortCodeData.isDTO && DTOClass) {
|
|
642
|
-
const DTOs = await Promise.all(
|
|
643
|
-
results.map((record) => DTOClass(record))
|
|
644
|
-
);
|
|
597
|
+
const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
|
|
645
598
|
return {
|
|
646
599
|
data: DTOs,
|
|
647
600
|
totalRecords,
|
|
@@ -702,9 +655,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
702
655
|
});
|
|
703
656
|
const DTOClass = dtoMapping[shortCodeData.shortCode];
|
|
704
657
|
if (shortCodeData.isDTO && DTOClass) {
|
|
705
|
-
const DTOs = await Promise.all(
|
|
706
|
-
results.map((record) => DTOClass(record))
|
|
707
|
-
);
|
|
658
|
+
const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
|
|
708
659
|
return {
|
|
709
660
|
data: DTOs,
|
|
710
661
|
totalRecords
|
|
@@ -716,10 +667,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
716
667
|
totalRecords
|
|
717
668
|
};
|
|
718
669
|
},
|
|
719
|
-
async commonExcelImport({
|
|
720
|
-
shortCodeData,
|
|
721
|
-
data
|
|
722
|
-
}) {
|
|
670
|
+
async commonExcelImport({ shortCodeData, data }) {
|
|
723
671
|
logger.info("entering::commonExcelImport::repository");
|
|
724
672
|
const tableName = shortCodeData.tableName;
|
|
725
673
|
const model = db[tableName];
|
|
@@ -727,20 +675,13 @@ var commonRepository = (serviceDeps) => {
|
|
|
727
675
|
throw new ErrorHandler(400, "Invalid mapping table name");
|
|
728
676
|
}
|
|
729
677
|
if (!data || !Array.isArray(data)) {
|
|
730
|
-
throw new ErrorHandler(
|
|
731
|
-
400,
|
|
732
|
-
"No data provided for conversion/insertion."
|
|
733
|
-
);
|
|
678
|
+
throw new ErrorHandler(400, "No data provided for conversion/insertion.");
|
|
734
679
|
}
|
|
735
680
|
const conversionFn = mappingImport[shortCodeData.shortCode];
|
|
736
681
|
if (!conversionFn) {
|
|
737
|
-
throw new Error(
|
|
738
|
-
`No conversion function found for short code: ${shortCodeData.shortCode}`
|
|
739
|
-
);
|
|
682
|
+
throw new Error(`No conversion function found for short code: ${shortCodeData.shortCode}`);
|
|
740
683
|
}
|
|
741
|
-
let convertedData = data.map(
|
|
742
|
-
(row) => conversionFn().mapper(row)
|
|
743
|
-
);
|
|
684
|
+
let convertedData = data.map((row) => conversionFn().mapper(row));
|
|
744
685
|
const errorObjArr = [];
|
|
745
686
|
await Promise.all(
|
|
746
687
|
convertedData.map(async (record, index) => {
|
|
@@ -764,21 +705,13 @@ var commonRepository = (serviceDeps) => {
|
|
|
764
705
|
type: ""
|
|
765
706
|
};
|
|
766
707
|
});
|
|
767
|
-
convertedData = convertedData.filter(
|
|
768
|
-
(data2, index) => !errorObjArr.find((elem) => elem.row === index + 1)
|
|
769
|
-
);
|
|
708
|
+
convertedData = convertedData.filter((data2, index) => !errorObjArr.find((elem) => elem.row === index + 1));
|
|
770
709
|
throw new ErrorHandler(400, errMsg, errors);
|
|
771
710
|
}
|
|
772
|
-
const createOperations = convertedData.map(
|
|
773
|
-
(record) => model.create({ data: record })
|
|
774
|
-
);
|
|
711
|
+
const createOperations = convertedData.map((record) => model.create({ data: record }));
|
|
775
712
|
const results = await Promise.allSettled(createOperations);
|
|
776
|
-
const insertedCount = results.filter(
|
|
777
|
-
|
|
778
|
-
).length;
|
|
779
|
-
const failedCount = results.filter(
|
|
780
|
-
(result) => result.status === "rejected"
|
|
781
|
-
).length;
|
|
713
|
+
const insertedCount = results.filter((result) => result.status === "fulfilled").length;
|
|
714
|
+
const failedCount = results.filter((result) => result.status === "rejected").length;
|
|
782
715
|
logger.info("exiting::commonExcelImport::repository");
|
|
783
716
|
return {
|
|
784
717
|
insertedCount,
|
|
@@ -942,41 +875,31 @@ var commonService = (serviceDeps) => {
|
|
|
942
875
|
return {
|
|
943
876
|
async search(searchParams) {
|
|
944
877
|
logger.info("entering::search::service");
|
|
945
|
-
const commonData = await commonRepositoryFactory.commonSearch(
|
|
946
|
-
searchParams
|
|
947
|
-
);
|
|
878
|
+
const commonData = await commonRepositoryFactory.commonSearch(searchParams);
|
|
948
879
|
logger.info("exiting::search::service");
|
|
949
880
|
return commonData;
|
|
950
881
|
},
|
|
951
882
|
async dropdownSearch(searchParams) {
|
|
952
883
|
logger.info("entering::search::service");
|
|
953
|
-
const commonData = await commonRepositoryFactory.commonDropdownSearch(
|
|
954
|
-
searchParams
|
|
955
|
-
);
|
|
884
|
+
const commonData = await commonRepositoryFactory.commonDropdownSearch(searchParams);
|
|
956
885
|
logger.info("exiting::search::service");
|
|
957
886
|
return commonData;
|
|
958
887
|
},
|
|
959
888
|
async fixedSearch(searchParams) {
|
|
960
889
|
logger.info("entering::fixedSearch::service");
|
|
961
|
-
const commonData = await commonRepositoryFactory.fixedSearch(
|
|
962
|
-
searchParams
|
|
963
|
-
);
|
|
890
|
+
const commonData = await commonRepositoryFactory.fixedSearch(searchParams);
|
|
964
891
|
logger.info("exiting::fixedSearch::service");
|
|
965
892
|
return commonData;
|
|
966
893
|
},
|
|
967
894
|
async fixedSearchWoPaginationService(searchParams) {
|
|
968
895
|
logger.info("entering::fixedSearchWoPaginationService::service");
|
|
969
|
-
const commonData = await commonRepositoryFactory.fixedSearchWoPagination(
|
|
970
|
-
searchParams
|
|
971
|
-
);
|
|
896
|
+
const commonData = await commonRepositoryFactory.fixedSearchWoPagination(searchParams);
|
|
972
897
|
logger.info("exiting::fixedSearchWoPaginationService::service");
|
|
973
898
|
return commonData;
|
|
974
899
|
},
|
|
975
900
|
async commonExcelService(searchParams) {
|
|
976
901
|
logger.info("entering::commonExcelService::service");
|
|
977
|
-
const commonData = await commonRepositoryFactory.fixedSearchWoPagination(
|
|
978
|
-
searchParams
|
|
979
|
-
);
|
|
902
|
+
const commonData = await commonRepositoryFactory.fixedSearchWoPagination(searchParams);
|
|
980
903
|
const wb = new import_exceljs.default.Workbook();
|
|
981
904
|
const ws = wb.addWorksheet(`${searchParams.sheetName}`);
|
|
982
905
|
ws.properties.defaultRowHeight = 18;
|
|
@@ -993,24 +916,10 @@ var commonService = (serviceDeps) => {
|
|
|
993
916
|
} else if (searchParams.type === "GROUPED" && searchParams.detailAccessorKey && searchParams.headerAccessorKey && searchParams.detailedConfig) {
|
|
994
917
|
let rowIndex = 1;
|
|
995
918
|
for (const element of commonData.data) {
|
|
996
|
-
const detailsList = getDynamicValue(
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
)
|
|
1000
|
-
ws.mergeCells(
|
|
1001
|
-
rowIndex,
|
|
1002
|
-
1,
|
|
1003
|
-
rowIndex,
|
|
1004
|
-
searchParams.detailedConfig.length
|
|
1005
|
-
);
|
|
1006
|
-
const title = getDynamicValue(
|
|
1007
|
-
element,
|
|
1008
|
-
searchParams.headerAccessorKey
|
|
1009
|
-
);
|
|
1010
|
-
ws.getCell(
|
|
1011
|
-
rowIndex,
|
|
1012
|
-
1
|
|
1013
|
-
).value = `${searchParams.shortCodeData.shortCode}-#${title}`;
|
|
919
|
+
const detailsList = getDynamicValue(element, searchParams.detailAccessorKey);
|
|
920
|
+
ws.mergeCells(rowIndex, 1, rowIndex, searchParams.detailedConfig.length);
|
|
921
|
+
const title = getDynamicValue(element, searchParams.headerAccessorKey);
|
|
922
|
+
ws.getCell(rowIndex, 1).value = `${searchParams.shortCodeData.shortCode}-#${title}`;
|
|
1014
923
|
ws.getCell(rowIndex, 1).font = { bold: true };
|
|
1015
924
|
rowIndex++;
|
|
1016
925
|
const colLen = searchParams.detailedConfig.length;
|
|
@@ -1021,10 +930,7 @@ var commonService = (serviceDeps) => {
|
|
|
1021
930
|
}),
|
|
1022
931
|
{}
|
|
1023
932
|
);
|
|
1024
|
-
const detailsArr = objectTo2DArray(
|
|
1025
|
-
detail,
|
|
1026
|
-
colLen % 2 === 0 ? colLen : colLen + 1
|
|
1027
|
-
);
|
|
933
|
+
const detailsArr = objectTo2DArray(detail, colLen % 2 === 0 ? colLen : colLen + 1);
|
|
1028
934
|
const oddCols = [];
|
|
1029
935
|
for (let i = 1; i <= colLen; i++) {
|
|
1030
936
|
if (i % 2 !== 0) oddCols.push(i);
|
|
@@ -1044,9 +950,7 @@ var commonService = (serviceDeps) => {
|
|
|
1044
950
|
rowIndex++;
|
|
1045
951
|
continue;
|
|
1046
952
|
}
|
|
1047
|
-
const headers = searchParams.detailedConfig.map(
|
|
1048
|
-
(config) => config.label
|
|
1049
|
-
);
|
|
953
|
+
const headers = searchParams.detailedConfig.map((config) => config.label);
|
|
1050
954
|
ws.addRow(headers).font = { bold: true };
|
|
1051
955
|
for (const element2 of detailsList) {
|
|
1052
956
|
const row = searchParams.detailedConfig.map((config) => {
|
|
@@ -1081,9 +985,7 @@ var commonService = (serviceDeps) => {
|
|
|
1081
985
|
fetchParams.id
|
|
1082
986
|
);
|
|
1083
987
|
if (commonData) {
|
|
1084
|
-
logger.info(
|
|
1085
|
-
`Cache hit for ${shortCodeData.tableName} ID: ` + fetchParams.id
|
|
1086
|
-
);
|
|
988
|
+
logger.info(`Cache hit for ${shortCodeData.tableName} ID: ` + fetchParams.id);
|
|
1087
989
|
} else {
|
|
1088
990
|
logger.error(
|
|
1089
991
|
`Cache hit but not found in cache for short code: ${shortCodeData.shortCode} and id: ${fetchParams.id}`
|
|
@@ -1093,10 +995,7 @@ var commonService = (serviceDeps) => {
|
|
|
1093
995
|
commonData = await commonRepositoryFactory.commonFetch(fetchParams);
|
|
1094
996
|
}
|
|
1095
997
|
if (!commonData) {
|
|
1096
|
-
throw new ErrorHandler(
|
|
1097
|
-
404,
|
|
1098
|
-
generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`)
|
|
1099
|
-
);
|
|
998
|
+
throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`));
|
|
1100
999
|
}
|
|
1101
1000
|
if (shortCodeData.isDTO && dtoMapping[shortCodeData.shortCode]) {
|
|
1102
1001
|
const DtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
|
|
@@ -1142,13 +1041,9 @@ var commonService = (serviceDeps) => {
|
|
|
1142
1041
|
},
|
|
1143
1042
|
async commonExcelExport(exportParams) {
|
|
1144
1043
|
logger.info("entering::commonExcelExport::service");
|
|
1145
|
-
const excelData = await commonRepositoryFactory.commonExcelExport(
|
|
1146
|
-
exportParams
|
|
1147
|
-
);
|
|
1044
|
+
const excelData = await commonRepositoryFactory.commonExcelExport(exportParams);
|
|
1148
1045
|
if (!Array.isArray(excelData)) {
|
|
1149
|
-
throw new Error(
|
|
1150
|
-
"Invalid data format: excelData must be an array of objects."
|
|
1151
|
-
);
|
|
1046
|
+
throw new Error("Invalid data format: excelData must be an array of objects.");
|
|
1152
1047
|
}
|
|
1153
1048
|
const wb = new import_exceljs.default.Workbook();
|
|
1154
1049
|
const ws = wb.addWorksheet(`${exportParams.shortCodeData.tableName}`);
|
|
@@ -1174,19 +1069,14 @@ var commonService = (serviceDeps) => {
|
|
|
1174
1069
|
const shortCodeData = deleteParams.shortCodeData;
|
|
1175
1070
|
await commonRepositoryFactory.commonDelete(deleteParams);
|
|
1176
1071
|
if (shortCodeData.isCacheable) {
|
|
1177
|
-
await deleteCache(
|
|
1178
|
-
`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
|
|
1179
|
-
deleteParams.id
|
|
1180
|
-
);
|
|
1072
|
+
await deleteCache(`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`, deleteParams.id);
|
|
1181
1073
|
}
|
|
1182
1074
|
logger.info("exiting::delete::service");
|
|
1183
1075
|
},
|
|
1184
1076
|
async updateStatus(updateStatusParams) {
|
|
1185
1077
|
logger.info("entering::updateStatus::service");
|
|
1186
1078
|
const shortCodeData = updateStatusParams.shortCodeData;
|
|
1187
|
-
const updatedData = await commonRepositoryFactory.commonUpdateStatus(
|
|
1188
|
-
updateStatusParams
|
|
1189
|
-
);
|
|
1079
|
+
const updatedData = await commonRepositoryFactory.commonUpdateStatus(updateStatusParams);
|
|
1190
1080
|
if (shortCodeData.isCacheable) {
|
|
1191
1081
|
await updateCache(
|
|
1192
1082
|
`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
|
|
@@ -1360,63 +1250,37 @@ var uinConfigServiceValidation = (uinDeps) => {
|
|
|
1360
1250
|
const validIdCheck = (id) => {
|
|
1361
1251
|
logger.info(`entering::validIdCheck id::${id}`);
|
|
1362
1252
|
if (isNaN(id) || !isFinite(id) || id > Number.MAX_SAFE_INTEGER || id < 1 || !Number.isInteger(id)) {
|
|
1363
|
-
throw new ErrorHandler(
|
|
1364
|
-
400,
|
|
1365
|
-
generateErrorMessage("INVALID_ID", id.toString())
|
|
1366
|
-
);
|
|
1253
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_ID", id.toString()));
|
|
1367
1254
|
}
|
|
1368
1255
|
logger.info(`exiting::validIdCheck id::${id}`);
|
|
1369
1256
|
};
|
|
1370
1257
|
const validateIdUinConfig = async (uinConfigId) => {
|
|
1371
1258
|
logger.info("entering::validateIdUinConfig::service::validation");
|
|
1372
1259
|
validIdCheck(uinConfigId);
|
|
1373
|
-
const uinConfig = await commonRepositoryFactory.getUINConfigByIdFromDb(
|
|
1374
|
-
uinConfigId
|
|
1375
|
-
);
|
|
1260
|
+
const uinConfig = await commonRepositoryFactory.getUINConfigByIdFromDb(uinConfigId);
|
|
1376
1261
|
if (!uinConfig || uinConfig.isActive === false) {
|
|
1377
|
-
throw new ErrorHandler(
|
|
1378
|
-
404,
|
|
1379
|
-
generateErrorMessage("NOT_FOUND", "Uin Config")
|
|
1380
|
-
);
|
|
1262
|
+
throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", "Uin Config"));
|
|
1381
1263
|
}
|
|
1382
1264
|
logger.info("exiting::validateIdUinConfig::service::validation");
|
|
1383
1265
|
return uinConfig;
|
|
1384
1266
|
};
|
|
1385
1267
|
const updateIdUinConfigServiceValidation = async (body) => {
|
|
1386
|
-
logger.info(
|
|
1387
|
-
"entering::updateIdUinConfigServiceValidation::service::validation"
|
|
1388
|
-
);
|
|
1268
|
+
logger.info("entering::updateIdUinConfigServiceValidation::service::validation");
|
|
1389
1269
|
const uin = await validateIdUinConfig(body.id);
|
|
1390
|
-
const uinConfig = await commonRepositoryFactory.getUINConfigByShortCodeFromDb(
|
|
1391
|
-
body.shortCode
|
|
1392
|
-
);
|
|
1270
|
+
const uinConfig = await commonRepositoryFactory.getUINConfigByShortCodeFromDb(body.shortCode);
|
|
1393
1271
|
if (uinConfig && uinConfig.id !== body.id) {
|
|
1394
|
-
throw new ErrorHandler(
|
|
1395
|
-
400,
|
|
1396
|
-
generateErrorMessage("DUPLICATE_ITEM", "UinConfig")
|
|
1397
|
-
);
|
|
1272
|
+
throw new ErrorHandler(400, generateErrorMessage("DUPLICATE_ITEM", "UinConfig"));
|
|
1398
1273
|
}
|
|
1399
|
-
logger.info(
|
|
1400
|
-
"exiting::updateIdUinConfigServiceValidation::service::validation"
|
|
1401
|
-
);
|
|
1274
|
+
logger.info("exiting::updateIdUinConfigServiceValidation::service::validation");
|
|
1402
1275
|
return uin;
|
|
1403
1276
|
};
|
|
1404
1277
|
const createUinConfigServiceValidation = async (body) => {
|
|
1405
|
-
logger.info(
|
|
1406
|
-
|
|
1407
|
-
);
|
|
1408
|
-
const uinConfig = await commonRepositoryFactory.getUINConfigByShortCodeFromDb(
|
|
1409
|
-
body.shortCode
|
|
1410
|
-
);
|
|
1278
|
+
logger.info("entering::createUinConfigServiceValidation::service::validation");
|
|
1279
|
+
const uinConfig = await commonRepositoryFactory.getUINConfigByShortCodeFromDb(body.shortCode);
|
|
1411
1280
|
if (uinConfig) {
|
|
1412
|
-
throw new ErrorHandler(
|
|
1413
|
-
400,
|
|
1414
|
-
generateErrorMessage("DUPLICATE_ITEM", "UinConfig Short Code")
|
|
1415
|
-
);
|
|
1281
|
+
throw new ErrorHandler(400, generateErrorMessage("DUPLICATE_ITEM", "UinConfig Short Code"));
|
|
1416
1282
|
}
|
|
1417
|
-
logger.info(
|
|
1418
|
-
"exiting::createUinConfigServiceValidation::service::validation"
|
|
1419
|
-
);
|
|
1283
|
+
logger.info("exiting::createUinConfigServiceValidation::service::validation");
|
|
1420
1284
|
};
|
|
1421
1285
|
return {
|
|
1422
1286
|
validateIdUinConfig,
|
|
@@ -1457,20 +1321,10 @@ function buildFromSegments(segments, seqValue) {
|
|
|
1457
1321
|
var uinConfigService = (uinDeps) => {
|
|
1458
1322
|
const uinConfigShortCode = uinDeps.shortCode;
|
|
1459
1323
|
const ErrorHandler = uinDeps.helpers.ErrorHandler;
|
|
1460
|
-
const {
|
|
1461
|
-
deleteCache,
|
|
1462
|
-
getCacheById,
|
|
1463
|
-
updateCache,
|
|
1464
|
-
addToCache,
|
|
1465
|
-
checkIsCacheable
|
|
1466
|
-
} = uinDeps.cacheAdapter;
|
|
1324
|
+
const { deleteCache, getCacheById, updateCache, addToCache, checkIsCacheable } = uinDeps.cacheAdapter;
|
|
1467
1325
|
const logger = uinDeps.logger;
|
|
1468
1326
|
const uinRepositoryFactory = uinConfigRepository(uinDeps);
|
|
1469
|
-
const {
|
|
1470
|
-
createUinConfigServiceValidation,
|
|
1471
|
-
updateIdUinConfigServiceValidation,
|
|
1472
|
-
validateIdUinConfig
|
|
1473
|
-
} = uinConfigServiceValidation(uinDeps);
|
|
1327
|
+
const { createUinConfigServiceValidation, updateIdUinConfigServiceValidation, validateIdUinConfig } = uinConfigServiceValidation(uinDeps);
|
|
1474
1328
|
const cacheKey = uinDeps.cacheKey;
|
|
1475
1329
|
const prisma = uinDeps.prisma;
|
|
1476
1330
|
import_node_cron.default.schedule("01 0 * * *", async () => {
|
|
@@ -1495,27 +1349,13 @@ var uinConfigService = (uinDeps) => {
|
|
|
1495
1349
|
}
|
|
1496
1350
|
if (!shouldReset) continue;
|
|
1497
1351
|
try {
|
|
1498
|
-
await uinRepositoryFactory.updateSequenceNoAndResetDate(
|
|
1499
|
-
cfg.shortCode,
|
|
1500
|
-
BigInt(0),
|
|
1501
|
-
now
|
|
1502
|
-
);
|
|
1352
|
+
await uinRepositoryFactory.updateSequenceNoAndResetDate(cfg.shortCode, BigInt(0), now);
|
|
1503
1353
|
} catch (error) {
|
|
1504
|
-
logger.error(
|
|
1505
|
-
`Failed to reset sequence for shortCode ${cfg.shortCode}:`,
|
|
1506
|
-
error
|
|
1507
|
-
);
|
|
1354
|
+
logger.error(`Failed to reset sequence for shortCode ${cfg.shortCode}:`, error);
|
|
1508
1355
|
try {
|
|
1509
|
-
await uinRepositoryFactory.updateSequenceNoAndResetDate(
|
|
1510
|
-
cfg.shortCode,
|
|
1511
|
-
BigInt(0),
|
|
1512
|
-
now
|
|
1513
|
-
);
|
|
1356
|
+
await uinRepositoryFactory.updateSequenceNoAndResetDate(cfg.shortCode, BigInt(0), now);
|
|
1514
1357
|
} catch (retryError) {
|
|
1515
|
-
logger.error(
|
|
1516
|
-
`Retry failed for shortCode ${cfg.shortCode}:`,
|
|
1517
|
-
retryError
|
|
1518
|
-
);
|
|
1358
|
+
logger.error(`Retry failed for shortCode ${cfg.shortCode}:`, retryError);
|
|
1519
1359
|
}
|
|
1520
1360
|
}
|
|
1521
1361
|
if (await checkIsCacheable(uinConfigShortCode)) {
|
|
@@ -1544,9 +1384,7 @@ var uinConfigService = (uinDeps) => {
|
|
|
1544
1384
|
const cached = await getCacheById(cacheKey, shortCode);
|
|
1545
1385
|
if (cached) return cached;
|
|
1546
1386
|
}
|
|
1547
|
-
const cfg = await uinRepositoryFactory.getUINConfigByShortCodeFromDb(
|
|
1548
|
-
shortCode
|
|
1549
|
-
);
|
|
1387
|
+
const cfg = await uinRepositoryFactory.getUINConfigByShortCodeFromDb(shortCode);
|
|
1550
1388
|
if (!cfg) throw new ErrorHandler(404, `Invalid shortCode: ${shortCode}`);
|
|
1551
1389
|
if (useCache) {
|
|
1552
1390
|
await addToCache(cacheKey, shortCode, cfg);
|
|
@@ -1581,10 +1419,7 @@ var uinConfigService = (uinDeps) => {
|
|
|
1581
1419
|
logger.info("entering::updateUINConfig::service");
|
|
1582
1420
|
const existingUin = await updateIdUinConfigServiceValidation(req);
|
|
1583
1421
|
const isCacheable = await checkIsCacheable(uinConfigShortCode);
|
|
1584
|
-
const updatedUin = await uinRepositoryFactory.updateUINConfigInDb(
|
|
1585
|
-
req,
|
|
1586
|
-
existingUin
|
|
1587
|
-
);
|
|
1422
|
+
const updatedUin = await uinRepositoryFactory.updateUINConfigInDb(req, existingUin);
|
|
1588
1423
|
if (isCacheable && updatedUin) {
|
|
1589
1424
|
await updateCache(cacheKey, updatedUin.shortCode, updatedUin);
|
|
1590
1425
|
}
|
|
@@ -1690,9 +1525,7 @@ var EmailProvider = class {
|
|
|
1690
1525
|
attachments
|
|
1691
1526
|
// Optional attachments
|
|
1692
1527
|
});
|
|
1693
|
-
this.logger.info(
|
|
1694
|
-
`Email sent to ${recipient.email} with subject: ${subject}`
|
|
1695
|
-
);
|
|
1528
|
+
this.logger.info(`Email sent to ${recipient.email} with subject: ${subject}`);
|
|
1696
1529
|
return {
|
|
1697
1530
|
ok: true,
|
|
1698
1531
|
provider: "EMAIL" /* EMAIL */,
|
|
@@ -1804,34 +1637,43 @@ var NotificationService = class {
|
|
|
1804
1637
|
this.logger.info(
|
|
1805
1638
|
`[NotificationService] No config for event=${evt.eventName} serviceEventId=${evt.serviceEventId}`
|
|
1806
1639
|
);
|
|
1807
|
-
throw new this.helpers.ErrorHandler(
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1640
|
+
throw new this.helpers.ErrorHandler(400, this.helpers.generateErrorMessage("NOT_FOUND", evt.eventName));
|
|
1641
|
+
}
|
|
1642
|
+
let emailTpl = null;
|
|
1643
|
+
if (cfg.allowEmail && cfg.serviceEvent.allowEmail && cfg.serviceEvent.emailTemplateId) {
|
|
1644
|
+
emailTpl = await this.prisma.template.findUnique({
|
|
1645
|
+
where: { id: cfg.serviceEvent.emailTemplateId }
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
let smsTpl = null;
|
|
1649
|
+
if (cfg.allowSms && cfg.serviceEvent.allowSms && cfg.serviceEvent.smsTemplateId) {
|
|
1650
|
+
smsTpl = await this.prisma.template.findUnique({
|
|
1651
|
+
where: { id: cfg.serviceEvent.smsTemplateId }
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
let waTpl = null;
|
|
1655
|
+
if (cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp && cfg.serviceEvent.wpTemplateId) {
|
|
1656
|
+
waTpl = await this.prisma.template.findUnique({
|
|
1657
|
+
where: { id: cfg.serviceEvent.wpTemplateId }
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
let appTpl = null;
|
|
1661
|
+
if (cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification && cfg.serviceEvent.appNotificationTemplateId) {
|
|
1662
|
+
appTpl = await this.prisma.template.findUnique({
|
|
1663
|
+
where: { id: cfg.serviceEvent.appNotificationTemplateId }
|
|
1664
|
+
});
|
|
1811
1665
|
}
|
|
1812
|
-
const
|
|
1813
|
-
subject: "PO {{poNumber}} created",
|
|
1814
|
-
body: "<p>Hello {{vendor}}, PO {{poNumber}} created</p>"
|
|
1815
|
-
} : null;
|
|
1816
|
-
const smsTpl = cfg.allowSms && cfg.serviceEvent.allowSms ? { body: "PO {{poNumber}} created for {{vendor}}" } : null;
|
|
1817
|
-
const waTpl = cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp ? { body: "*PO {{poNumber}}* created for {{vendor}}" } : null;
|
|
1818
|
-
const appTpl = cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification ? {
|
|
1819
|
-
subject: "PO created",
|
|
1820
|
-
body: "PO {{poNumber}} created for {{vendor}}"
|
|
1821
|
-
} : null;
|
|
1822
|
-
const emailProvider = new EmailProvider(
|
|
1823
|
-
this.prisma,
|
|
1824
|
-
this.logger,
|
|
1825
|
-
this.envMode
|
|
1826
|
-
);
|
|
1666
|
+
const emailProvider = new EmailProvider(this.prisma, this.logger, this.envMode);
|
|
1827
1667
|
const smsProvider = new SmsProvider();
|
|
1828
|
-
const waProvider = new WhatsAppProvider(
|
|
1829
|
-
cfg.serviceEvent?.wpApiUrl ?? void 0
|
|
1830
|
-
);
|
|
1668
|
+
const waProvider = new WhatsAppProvider(cfg.serviceEvent?.wpApiUrl ?? void 0);
|
|
1831
1669
|
const appProvider = new AppNotificationProvider();
|
|
1670
|
+
this.logger.info(`[NotificationService] Email Template: ${JSON.stringify(emailTpl)}`);
|
|
1671
|
+
this.logger.info(`[NotificationService] SMS Template: ${JSON.stringify(smsTpl)}`);
|
|
1672
|
+
this.logger.info(`[NotificationService] WhatsApp Template: ${JSON.stringify(waTpl)}`);
|
|
1673
|
+
this.logger.info(`[NotificationService] App Notification Template: ${JSON.stringify(appTpl)}`);
|
|
1832
1674
|
const promises = [];
|
|
1833
1675
|
if (emailTpl) {
|
|
1834
|
-
const msg = renderEmailTemplate(emailTpl, evt.data);
|
|
1676
|
+
const msg = renderEmailTemplate({ body: emailTpl.bodyHtml ?? "", subject: emailTpl.subject ?? "" }, evt.data);
|
|
1835
1677
|
promises.push(
|
|
1836
1678
|
this.sendAndAudit({
|
|
1837
1679
|
providerType: "EMAIL" /* EMAIL */,
|
|
@@ -1844,7 +1686,7 @@ var NotificationService = class {
|
|
|
1844
1686
|
);
|
|
1845
1687
|
}
|
|
1846
1688
|
if (smsTpl) {
|
|
1847
|
-
const msg = renderTemplate(smsTpl.
|
|
1689
|
+
const msg = renderTemplate(smsTpl.bodyText, evt.data);
|
|
1848
1690
|
promises.push(
|
|
1849
1691
|
this.sendAndAudit({
|
|
1850
1692
|
providerType: "SMS" /* SMS */,
|
|
@@ -1856,7 +1698,7 @@ var NotificationService = class {
|
|
|
1856
1698
|
);
|
|
1857
1699
|
}
|
|
1858
1700
|
if (waTpl) {
|
|
1859
|
-
const msg = renderTemplate(waTpl.
|
|
1701
|
+
const msg = renderTemplate(waTpl.bodyText, evt.data);
|
|
1860
1702
|
promises.push(
|
|
1861
1703
|
this.sendAndAudit({
|
|
1862
1704
|
providerType: "WHATSAPP" /* WHATSAPP */,
|
|
@@ -1869,7 +1711,7 @@ var NotificationService = class {
|
|
|
1869
1711
|
}
|
|
1870
1712
|
if (appTpl) {
|
|
1871
1713
|
const subjectRendered = renderTemplate(appTpl.subject ?? "", evt.data);
|
|
1872
|
-
const bodyRendered = renderTemplate(appTpl.
|
|
1714
|
+
const bodyRendered = renderTemplate(appTpl.bodyText, evt.data);
|
|
1873
1715
|
promises.push(
|
|
1874
1716
|
this.sendAndAudit({
|
|
1875
1717
|
providerType: "APP_NOTIFICATION" /* APP_NOTIFICATION */,
|
|
@@ -1931,20 +1773,12 @@ var NotificationEmitter = class {
|
|
|
1931
1773
|
service;
|
|
1932
1774
|
constructor(deps) {
|
|
1933
1775
|
this.emitter = new import_events.EventEmitter();
|
|
1934
|
-
this.service = new NotificationService(
|
|
1935
|
-
deps.prisma,
|
|
1936
|
-
deps.logger ?? console,
|
|
1937
|
-
deps.envMode,
|
|
1938
|
-
deps.helpers
|
|
1939
|
-
);
|
|
1776
|
+
this.service = new NotificationService(deps.prisma, deps.logger ?? console, deps.envMode, deps.helpers);
|
|
1940
1777
|
this.emitter.on("notify", async (payload) => {
|
|
1941
1778
|
try {
|
|
1942
1779
|
await this.service.handleEvent(payload);
|
|
1943
1780
|
} catch (err) {
|
|
1944
|
-
(deps.logger ?? console).error(
|
|
1945
|
-
"[NotificationEmitter] Error handling event",
|
|
1946
|
-
err
|
|
1947
|
-
);
|
|
1781
|
+
(deps.logger ?? console).error("[NotificationEmitter] Error handling event", err);
|
|
1948
1782
|
}
|
|
1949
1783
|
});
|
|
1950
1784
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -257,9 +257,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
257
257
|
const totalPages = Math.ceil(totalRecords / pageSize);
|
|
258
258
|
const DTOClass = dtoMapping[shortCodeData.shortCode];
|
|
259
259
|
if (shortCodeData.isDTO && DTOClass) {
|
|
260
|
-
const DTOs = await Promise.all(
|
|
261
|
-
results.map((record) => DTOClass(record))
|
|
262
|
-
);
|
|
260
|
+
const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
|
|
263
261
|
return {
|
|
264
262
|
data: DTOs,
|
|
265
263
|
totalRecords,
|
|
@@ -335,10 +333,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
335
333
|
logger.info("exiting::commonSearch::repository");
|
|
336
334
|
return results;
|
|
337
335
|
},
|
|
338
|
-
async commonFetch({
|
|
339
|
-
id,
|
|
340
|
-
shortCodeData
|
|
341
|
-
}) {
|
|
336
|
+
async commonFetch({ id, shortCodeData }) {
|
|
342
337
|
logger.info("entering::commonFetch::repository");
|
|
343
338
|
const tableName = shortCodeData.tableName;
|
|
344
339
|
const model = db[tableName];
|
|
@@ -351,10 +346,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
351
346
|
logger.info("exiting::commonFetch::repository");
|
|
352
347
|
return results;
|
|
353
348
|
},
|
|
354
|
-
async commonDelete({
|
|
355
|
-
id,
|
|
356
|
-
shortCodeData
|
|
357
|
-
}) {
|
|
349
|
+
async commonDelete({ id, shortCodeData }) {
|
|
358
350
|
logger.info("entering::commonDelete::repository");
|
|
359
351
|
const tableName = shortCodeData.tableName;
|
|
360
352
|
const store = requestStorage.getStore();
|
|
@@ -373,11 +365,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
373
365
|
logger.info("exiting::commonDelete::repository");
|
|
374
366
|
return results;
|
|
375
367
|
},
|
|
376
|
-
async commonUpdateStatus({
|
|
377
|
-
id,
|
|
378
|
-
shortCodeData,
|
|
379
|
-
status
|
|
380
|
-
}) {
|
|
368
|
+
async commonUpdateStatus({ id, shortCodeData, status }) {
|
|
381
369
|
logger.info("entering::commonUpdateStatus::repository");
|
|
382
370
|
const tableName = shortCodeData.tableName;
|
|
383
371
|
const model = db[tableName];
|
|
@@ -427,24 +415,17 @@ var commonRepository = (serviceDeps) => {
|
|
|
427
415
|
const rootCondition = {};
|
|
428
416
|
if (fixedSearch) {
|
|
429
417
|
for (const [field, defObj] of Object.entries(fixedSearch)) {
|
|
430
|
-
if (!defObj || !Array.isArray(defObj.value) || defObj.value.length === 0)
|
|
431
|
-
continue;
|
|
418
|
+
if (!defObj || !Array.isArray(defObj.value) || defObj.value.length === 0) continue;
|
|
432
419
|
const fieldPath = field.split(".");
|
|
433
420
|
const fieldType = defObj.type;
|
|
434
421
|
const fieldValues = defObj.value;
|
|
435
|
-
const cond = buildFieldCondition(
|
|
436
|
-
fieldPath,
|
|
437
|
-
fieldType,
|
|
438
|
-
fieldValues,
|
|
439
|
-
false
|
|
440
|
-
);
|
|
422
|
+
const cond = buildFieldCondition(fieldPath, fieldType, fieldValues, false);
|
|
441
423
|
mergeTopLevel(rootCondition, cond);
|
|
442
424
|
}
|
|
443
425
|
}
|
|
444
426
|
if (fixedNotSearch) {
|
|
445
427
|
for (const [field, defObj] of Object.entries(fixedNotSearch)) {
|
|
446
|
-
if (!defObj || !Array.isArray(defObj.value) || defObj.value.length === 0)
|
|
447
|
-
continue;
|
|
428
|
+
if (!defObj || !Array.isArray(defObj.value) || defObj.value.length === 0) continue;
|
|
448
429
|
const fieldPath = field.split(".");
|
|
449
430
|
const fieldType = defObj.type;
|
|
450
431
|
const fieldValues = defObj.value;
|
|
@@ -482,50 +463,24 @@ var commonRepository = (serviceDeps) => {
|
|
|
482
463
|
for (const sc of searchColumns) {
|
|
483
464
|
const { col, type: colType } = sc;
|
|
484
465
|
if (colType === "string") {
|
|
485
|
-
searchOR.push(
|
|
486
|
-
buildNestedConditionForSingleValue(
|
|
487
|
-
col.split("."),
|
|
488
|
-
"string",
|
|
489
|
-
searchText
|
|
490
|
-
)
|
|
491
|
-
);
|
|
466
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "string", searchText));
|
|
492
467
|
} else if (colType === "number") {
|
|
493
468
|
const numVal = parseFloat(searchText);
|
|
494
469
|
if (!isNaN(numVal)) {
|
|
495
|
-
searchOR.push(
|
|
496
|
-
buildNestedConditionForSingleValue(
|
|
497
|
-
col.split("."),
|
|
498
|
-
"number",
|
|
499
|
-
numVal
|
|
500
|
-
)
|
|
501
|
-
);
|
|
470
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "number", numVal));
|
|
502
471
|
}
|
|
503
472
|
} else if (colType === "boolean") {
|
|
504
473
|
const boolVal = searchText.toLowerCase();
|
|
505
474
|
if (boolVal === "true" || boolVal === "false") {
|
|
506
|
-
searchOR.push(
|
|
507
|
-
buildNestedConditionForSingleValue(
|
|
508
|
-
col.split("."),
|
|
509
|
-
"boolean",
|
|
510
|
-
boolVal === "true"
|
|
511
|
-
)
|
|
512
|
-
);
|
|
475
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "boolean", boolVal === "true"));
|
|
513
476
|
}
|
|
514
477
|
} else if (colType === "date") {
|
|
515
478
|
const dt = new Date(searchText);
|
|
516
479
|
if (!isNaN(dt.getTime())) {
|
|
517
|
-
searchOR.push(
|
|
518
|
-
buildNestedConditionForSingleValue(col.split("."), "date", dt)
|
|
519
|
-
);
|
|
480
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "date", dt));
|
|
520
481
|
}
|
|
521
482
|
} else {
|
|
522
|
-
searchOR.push(
|
|
523
|
-
buildNestedConditionForSingleValue(
|
|
524
|
-
col.split("."),
|
|
525
|
-
"string",
|
|
526
|
-
searchText
|
|
527
|
-
)
|
|
528
|
-
);
|
|
483
|
+
searchOR.push(buildNestedConditionForSingleValue(col.split("."), "string", searchText));
|
|
529
484
|
}
|
|
530
485
|
}
|
|
531
486
|
searchOR = transformData(searchOR);
|
|
@@ -593,9 +548,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
593
548
|
const totalPages = Math.ceil(totalRecords / pageSize);
|
|
594
549
|
const DTOClass = dtoMapping[shortCodeData.shortCode];
|
|
595
550
|
if (shortCodeData.isDTO && DTOClass) {
|
|
596
|
-
const DTOs = await Promise.all(
|
|
597
|
-
results.map((record) => DTOClass(record))
|
|
598
|
-
);
|
|
551
|
+
const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
|
|
599
552
|
return {
|
|
600
553
|
data: DTOs,
|
|
601
554
|
totalRecords,
|
|
@@ -656,9 +609,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
656
609
|
});
|
|
657
610
|
const DTOClass = dtoMapping[shortCodeData.shortCode];
|
|
658
611
|
if (shortCodeData.isDTO && DTOClass) {
|
|
659
|
-
const DTOs = await Promise.all(
|
|
660
|
-
results.map((record) => DTOClass(record))
|
|
661
|
-
);
|
|
612
|
+
const DTOs = await Promise.all(results.map((record) => DTOClass(record)));
|
|
662
613
|
return {
|
|
663
614
|
data: DTOs,
|
|
664
615
|
totalRecords
|
|
@@ -670,10 +621,7 @@ var commonRepository = (serviceDeps) => {
|
|
|
670
621
|
totalRecords
|
|
671
622
|
};
|
|
672
623
|
},
|
|
673
|
-
async commonExcelImport({
|
|
674
|
-
shortCodeData,
|
|
675
|
-
data
|
|
676
|
-
}) {
|
|
624
|
+
async commonExcelImport({ shortCodeData, data }) {
|
|
677
625
|
logger.info("entering::commonExcelImport::repository");
|
|
678
626
|
const tableName = shortCodeData.tableName;
|
|
679
627
|
const model = db[tableName];
|
|
@@ -681,20 +629,13 @@ var commonRepository = (serviceDeps) => {
|
|
|
681
629
|
throw new ErrorHandler(400, "Invalid mapping table name");
|
|
682
630
|
}
|
|
683
631
|
if (!data || !Array.isArray(data)) {
|
|
684
|
-
throw new ErrorHandler(
|
|
685
|
-
400,
|
|
686
|
-
"No data provided for conversion/insertion."
|
|
687
|
-
);
|
|
632
|
+
throw new ErrorHandler(400, "No data provided for conversion/insertion.");
|
|
688
633
|
}
|
|
689
634
|
const conversionFn = mappingImport[shortCodeData.shortCode];
|
|
690
635
|
if (!conversionFn) {
|
|
691
|
-
throw new Error(
|
|
692
|
-
`No conversion function found for short code: ${shortCodeData.shortCode}`
|
|
693
|
-
);
|
|
636
|
+
throw new Error(`No conversion function found for short code: ${shortCodeData.shortCode}`);
|
|
694
637
|
}
|
|
695
|
-
let convertedData = data.map(
|
|
696
|
-
(row) => conversionFn().mapper(row)
|
|
697
|
-
);
|
|
638
|
+
let convertedData = data.map((row) => conversionFn().mapper(row));
|
|
698
639
|
const errorObjArr = [];
|
|
699
640
|
await Promise.all(
|
|
700
641
|
convertedData.map(async (record, index) => {
|
|
@@ -718,21 +659,13 @@ var commonRepository = (serviceDeps) => {
|
|
|
718
659
|
type: ""
|
|
719
660
|
};
|
|
720
661
|
});
|
|
721
|
-
convertedData = convertedData.filter(
|
|
722
|
-
(data2, index) => !errorObjArr.find((elem) => elem.row === index + 1)
|
|
723
|
-
);
|
|
662
|
+
convertedData = convertedData.filter((data2, index) => !errorObjArr.find((elem) => elem.row === index + 1));
|
|
724
663
|
throw new ErrorHandler(400, errMsg, errors);
|
|
725
664
|
}
|
|
726
|
-
const createOperations = convertedData.map(
|
|
727
|
-
(record) => model.create({ data: record })
|
|
728
|
-
);
|
|
665
|
+
const createOperations = convertedData.map((record) => model.create({ data: record }));
|
|
729
666
|
const results = await Promise.allSettled(createOperations);
|
|
730
|
-
const insertedCount = results.filter(
|
|
731
|
-
|
|
732
|
-
).length;
|
|
733
|
-
const failedCount = results.filter(
|
|
734
|
-
(result) => result.status === "rejected"
|
|
735
|
-
).length;
|
|
667
|
+
const insertedCount = results.filter((result) => result.status === "fulfilled").length;
|
|
668
|
+
const failedCount = results.filter((result) => result.status === "rejected").length;
|
|
736
669
|
logger.info("exiting::commonExcelImport::repository");
|
|
737
670
|
return {
|
|
738
671
|
insertedCount,
|
|
@@ -896,41 +829,31 @@ var commonService = (serviceDeps) => {
|
|
|
896
829
|
return {
|
|
897
830
|
async search(searchParams) {
|
|
898
831
|
logger.info("entering::search::service");
|
|
899
|
-
const commonData = await commonRepositoryFactory.commonSearch(
|
|
900
|
-
searchParams
|
|
901
|
-
);
|
|
832
|
+
const commonData = await commonRepositoryFactory.commonSearch(searchParams);
|
|
902
833
|
logger.info("exiting::search::service");
|
|
903
834
|
return commonData;
|
|
904
835
|
},
|
|
905
836
|
async dropdownSearch(searchParams) {
|
|
906
837
|
logger.info("entering::search::service");
|
|
907
|
-
const commonData = await commonRepositoryFactory.commonDropdownSearch(
|
|
908
|
-
searchParams
|
|
909
|
-
);
|
|
838
|
+
const commonData = await commonRepositoryFactory.commonDropdownSearch(searchParams);
|
|
910
839
|
logger.info("exiting::search::service");
|
|
911
840
|
return commonData;
|
|
912
841
|
},
|
|
913
842
|
async fixedSearch(searchParams) {
|
|
914
843
|
logger.info("entering::fixedSearch::service");
|
|
915
|
-
const commonData = await commonRepositoryFactory.fixedSearch(
|
|
916
|
-
searchParams
|
|
917
|
-
);
|
|
844
|
+
const commonData = await commonRepositoryFactory.fixedSearch(searchParams);
|
|
918
845
|
logger.info("exiting::fixedSearch::service");
|
|
919
846
|
return commonData;
|
|
920
847
|
},
|
|
921
848
|
async fixedSearchWoPaginationService(searchParams) {
|
|
922
849
|
logger.info("entering::fixedSearchWoPaginationService::service");
|
|
923
|
-
const commonData = await commonRepositoryFactory.fixedSearchWoPagination(
|
|
924
|
-
searchParams
|
|
925
|
-
);
|
|
850
|
+
const commonData = await commonRepositoryFactory.fixedSearchWoPagination(searchParams);
|
|
926
851
|
logger.info("exiting::fixedSearchWoPaginationService::service");
|
|
927
852
|
return commonData;
|
|
928
853
|
},
|
|
929
854
|
async commonExcelService(searchParams) {
|
|
930
855
|
logger.info("entering::commonExcelService::service");
|
|
931
|
-
const commonData = await commonRepositoryFactory.fixedSearchWoPagination(
|
|
932
|
-
searchParams
|
|
933
|
-
);
|
|
856
|
+
const commonData = await commonRepositoryFactory.fixedSearchWoPagination(searchParams);
|
|
934
857
|
const wb = new ExcelJs.Workbook();
|
|
935
858
|
const ws = wb.addWorksheet(`${searchParams.sheetName}`);
|
|
936
859
|
ws.properties.defaultRowHeight = 18;
|
|
@@ -947,24 +870,10 @@ var commonService = (serviceDeps) => {
|
|
|
947
870
|
} else if (searchParams.type === "GROUPED" && searchParams.detailAccessorKey && searchParams.headerAccessorKey && searchParams.detailedConfig) {
|
|
948
871
|
let rowIndex = 1;
|
|
949
872
|
for (const element of commonData.data) {
|
|
950
|
-
const detailsList = getDynamicValue(
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
)
|
|
954
|
-
ws.mergeCells(
|
|
955
|
-
rowIndex,
|
|
956
|
-
1,
|
|
957
|
-
rowIndex,
|
|
958
|
-
searchParams.detailedConfig.length
|
|
959
|
-
);
|
|
960
|
-
const title = getDynamicValue(
|
|
961
|
-
element,
|
|
962
|
-
searchParams.headerAccessorKey
|
|
963
|
-
);
|
|
964
|
-
ws.getCell(
|
|
965
|
-
rowIndex,
|
|
966
|
-
1
|
|
967
|
-
).value = `${searchParams.shortCodeData.shortCode}-#${title}`;
|
|
873
|
+
const detailsList = getDynamicValue(element, searchParams.detailAccessorKey);
|
|
874
|
+
ws.mergeCells(rowIndex, 1, rowIndex, searchParams.detailedConfig.length);
|
|
875
|
+
const title = getDynamicValue(element, searchParams.headerAccessorKey);
|
|
876
|
+
ws.getCell(rowIndex, 1).value = `${searchParams.shortCodeData.shortCode}-#${title}`;
|
|
968
877
|
ws.getCell(rowIndex, 1).font = { bold: true };
|
|
969
878
|
rowIndex++;
|
|
970
879
|
const colLen = searchParams.detailedConfig.length;
|
|
@@ -975,10 +884,7 @@ var commonService = (serviceDeps) => {
|
|
|
975
884
|
}),
|
|
976
885
|
{}
|
|
977
886
|
);
|
|
978
|
-
const detailsArr = objectTo2DArray(
|
|
979
|
-
detail,
|
|
980
|
-
colLen % 2 === 0 ? colLen : colLen + 1
|
|
981
|
-
);
|
|
887
|
+
const detailsArr = objectTo2DArray(detail, colLen % 2 === 0 ? colLen : colLen + 1);
|
|
982
888
|
const oddCols = [];
|
|
983
889
|
for (let i = 1; i <= colLen; i++) {
|
|
984
890
|
if (i % 2 !== 0) oddCols.push(i);
|
|
@@ -998,9 +904,7 @@ var commonService = (serviceDeps) => {
|
|
|
998
904
|
rowIndex++;
|
|
999
905
|
continue;
|
|
1000
906
|
}
|
|
1001
|
-
const headers = searchParams.detailedConfig.map(
|
|
1002
|
-
(config) => config.label
|
|
1003
|
-
);
|
|
907
|
+
const headers = searchParams.detailedConfig.map((config) => config.label);
|
|
1004
908
|
ws.addRow(headers).font = { bold: true };
|
|
1005
909
|
for (const element2 of detailsList) {
|
|
1006
910
|
const row = searchParams.detailedConfig.map((config) => {
|
|
@@ -1035,9 +939,7 @@ var commonService = (serviceDeps) => {
|
|
|
1035
939
|
fetchParams.id
|
|
1036
940
|
);
|
|
1037
941
|
if (commonData) {
|
|
1038
|
-
logger.info(
|
|
1039
|
-
`Cache hit for ${shortCodeData.tableName} ID: ` + fetchParams.id
|
|
1040
|
-
);
|
|
942
|
+
logger.info(`Cache hit for ${shortCodeData.tableName} ID: ` + fetchParams.id);
|
|
1041
943
|
} else {
|
|
1042
944
|
logger.error(
|
|
1043
945
|
`Cache hit but not found in cache for short code: ${shortCodeData.shortCode} and id: ${fetchParams.id}`
|
|
@@ -1047,10 +949,7 @@ var commonService = (serviceDeps) => {
|
|
|
1047
949
|
commonData = await commonRepositoryFactory.commonFetch(fetchParams);
|
|
1048
950
|
}
|
|
1049
951
|
if (!commonData) {
|
|
1050
|
-
throw new ErrorHandler(
|
|
1051
|
-
404,
|
|
1052
|
-
generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`)
|
|
1053
|
-
);
|
|
952
|
+
throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", `${shortCodeData.tableName}`));
|
|
1054
953
|
}
|
|
1055
954
|
if (shortCodeData.isDTO && dtoMapping[shortCodeData.shortCode]) {
|
|
1056
955
|
const DtoResult = await dtoMapping[shortCodeData.shortCode](commonData);
|
|
@@ -1096,13 +995,9 @@ var commonService = (serviceDeps) => {
|
|
|
1096
995
|
},
|
|
1097
996
|
async commonExcelExport(exportParams) {
|
|
1098
997
|
logger.info("entering::commonExcelExport::service");
|
|
1099
|
-
const excelData = await commonRepositoryFactory.commonExcelExport(
|
|
1100
|
-
exportParams
|
|
1101
|
-
);
|
|
998
|
+
const excelData = await commonRepositoryFactory.commonExcelExport(exportParams);
|
|
1102
999
|
if (!Array.isArray(excelData)) {
|
|
1103
|
-
throw new Error(
|
|
1104
|
-
"Invalid data format: excelData must be an array of objects."
|
|
1105
|
-
);
|
|
1000
|
+
throw new Error("Invalid data format: excelData must be an array of objects.");
|
|
1106
1001
|
}
|
|
1107
1002
|
const wb = new ExcelJs.Workbook();
|
|
1108
1003
|
const ws = wb.addWorksheet(`${exportParams.shortCodeData.tableName}`);
|
|
@@ -1128,19 +1023,14 @@ var commonService = (serviceDeps) => {
|
|
|
1128
1023
|
const shortCodeData = deleteParams.shortCodeData;
|
|
1129
1024
|
await commonRepositoryFactory.commonDelete(deleteParams);
|
|
1130
1025
|
if (shortCodeData.isCacheable) {
|
|
1131
|
-
await deleteCache(
|
|
1132
|
-
`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
|
|
1133
|
-
deleteParams.id
|
|
1134
|
-
);
|
|
1026
|
+
await deleteCache(`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`, deleteParams.id);
|
|
1135
1027
|
}
|
|
1136
1028
|
logger.info("exiting::delete::service");
|
|
1137
1029
|
},
|
|
1138
1030
|
async updateStatus(updateStatusParams) {
|
|
1139
1031
|
logger.info("entering::updateStatus::service");
|
|
1140
1032
|
const shortCodeData = updateStatusParams.shortCodeData;
|
|
1141
|
-
const updatedData = await commonRepositoryFactory.commonUpdateStatus(
|
|
1142
|
-
updateStatusParams
|
|
1143
|
-
);
|
|
1033
|
+
const updatedData = await commonRepositoryFactory.commonUpdateStatus(updateStatusParams);
|
|
1144
1034
|
if (shortCodeData.isCacheable) {
|
|
1145
1035
|
await updateCache(
|
|
1146
1036
|
`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
|
|
@@ -1314,63 +1204,37 @@ var uinConfigServiceValidation = (uinDeps) => {
|
|
|
1314
1204
|
const validIdCheck = (id) => {
|
|
1315
1205
|
logger.info(`entering::validIdCheck id::${id}`);
|
|
1316
1206
|
if (isNaN(id) || !isFinite(id) || id > Number.MAX_SAFE_INTEGER || id < 1 || !Number.isInteger(id)) {
|
|
1317
|
-
throw new ErrorHandler(
|
|
1318
|
-
400,
|
|
1319
|
-
generateErrorMessage("INVALID_ID", id.toString())
|
|
1320
|
-
);
|
|
1207
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_ID", id.toString()));
|
|
1321
1208
|
}
|
|
1322
1209
|
logger.info(`exiting::validIdCheck id::${id}`);
|
|
1323
1210
|
};
|
|
1324
1211
|
const validateIdUinConfig = async (uinConfigId) => {
|
|
1325
1212
|
logger.info("entering::validateIdUinConfig::service::validation");
|
|
1326
1213
|
validIdCheck(uinConfigId);
|
|
1327
|
-
const uinConfig = await commonRepositoryFactory.getUINConfigByIdFromDb(
|
|
1328
|
-
uinConfigId
|
|
1329
|
-
);
|
|
1214
|
+
const uinConfig = await commonRepositoryFactory.getUINConfigByIdFromDb(uinConfigId);
|
|
1330
1215
|
if (!uinConfig || uinConfig.isActive === false) {
|
|
1331
|
-
throw new ErrorHandler(
|
|
1332
|
-
404,
|
|
1333
|
-
generateErrorMessage("NOT_FOUND", "Uin Config")
|
|
1334
|
-
);
|
|
1216
|
+
throw new ErrorHandler(404, generateErrorMessage("NOT_FOUND", "Uin Config"));
|
|
1335
1217
|
}
|
|
1336
1218
|
logger.info("exiting::validateIdUinConfig::service::validation");
|
|
1337
1219
|
return uinConfig;
|
|
1338
1220
|
};
|
|
1339
1221
|
const updateIdUinConfigServiceValidation = async (body) => {
|
|
1340
|
-
logger.info(
|
|
1341
|
-
"entering::updateIdUinConfigServiceValidation::service::validation"
|
|
1342
|
-
);
|
|
1222
|
+
logger.info("entering::updateIdUinConfigServiceValidation::service::validation");
|
|
1343
1223
|
const uin = await validateIdUinConfig(body.id);
|
|
1344
|
-
const uinConfig = await commonRepositoryFactory.getUINConfigByShortCodeFromDb(
|
|
1345
|
-
body.shortCode
|
|
1346
|
-
);
|
|
1224
|
+
const uinConfig = await commonRepositoryFactory.getUINConfigByShortCodeFromDb(body.shortCode);
|
|
1347
1225
|
if (uinConfig && uinConfig.id !== body.id) {
|
|
1348
|
-
throw new ErrorHandler(
|
|
1349
|
-
400,
|
|
1350
|
-
generateErrorMessage("DUPLICATE_ITEM", "UinConfig")
|
|
1351
|
-
);
|
|
1226
|
+
throw new ErrorHandler(400, generateErrorMessage("DUPLICATE_ITEM", "UinConfig"));
|
|
1352
1227
|
}
|
|
1353
|
-
logger.info(
|
|
1354
|
-
"exiting::updateIdUinConfigServiceValidation::service::validation"
|
|
1355
|
-
);
|
|
1228
|
+
logger.info("exiting::updateIdUinConfigServiceValidation::service::validation");
|
|
1356
1229
|
return uin;
|
|
1357
1230
|
};
|
|
1358
1231
|
const createUinConfigServiceValidation = async (body) => {
|
|
1359
|
-
logger.info(
|
|
1360
|
-
|
|
1361
|
-
);
|
|
1362
|
-
const uinConfig = await commonRepositoryFactory.getUINConfigByShortCodeFromDb(
|
|
1363
|
-
body.shortCode
|
|
1364
|
-
);
|
|
1232
|
+
logger.info("entering::createUinConfigServiceValidation::service::validation");
|
|
1233
|
+
const uinConfig = await commonRepositoryFactory.getUINConfigByShortCodeFromDb(body.shortCode);
|
|
1365
1234
|
if (uinConfig) {
|
|
1366
|
-
throw new ErrorHandler(
|
|
1367
|
-
400,
|
|
1368
|
-
generateErrorMessage("DUPLICATE_ITEM", "UinConfig Short Code")
|
|
1369
|
-
);
|
|
1235
|
+
throw new ErrorHandler(400, generateErrorMessage("DUPLICATE_ITEM", "UinConfig Short Code"));
|
|
1370
1236
|
}
|
|
1371
|
-
logger.info(
|
|
1372
|
-
"exiting::createUinConfigServiceValidation::service::validation"
|
|
1373
|
-
);
|
|
1237
|
+
logger.info("exiting::createUinConfigServiceValidation::service::validation");
|
|
1374
1238
|
};
|
|
1375
1239
|
return {
|
|
1376
1240
|
validateIdUinConfig,
|
|
@@ -1411,20 +1275,10 @@ function buildFromSegments(segments, seqValue) {
|
|
|
1411
1275
|
var uinConfigService = (uinDeps) => {
|
|
1412
1276
|
const uinConfigShortCode = uinDeps.shortCode;
|
|
1413
1277
|
const ErrorHandler = uinDeps.helpers.ErrorHandler;
|
|
1414
|
-
const {
|
|
1415
|
-
deleteCache,
|
|
1416
|
-
getCacheById,
|
|
1417
|
-
updateCache,
|
|
1418
|
-
addToCache,
|
|
1419
|
-
checkIsCacheable
|
|
1420
|
-
} = uinDeps.cacheAdapter;
|
|
1278
|
+
const { deleteCache, getCacheById, updateCache, addToCache, checkIsCacheable } = uinDeps.cacheAdapter;
|
|
1421
1279
|
const logger = uinDeps.logger;
|
|
1422
1280
|
const uinRepositoryFactory = uinConfigRepository(uinDeps);
|
|
1423
|
-
const {
|
|
1424
|
-
createUinConfigServiceValidation,
|
|
1425
|
-
updateIdUinConfigServiceValidation,
|
|
1426
|
-
validateIdUinConfig
|
|
1427
|
-
} = uinConfigServiceValidation(uinDeps);
|
|
1281
|
+
const { createUinConfigServiceValidation, updateIdUinConfigServiceValidation, validateIdUinConfig } = uinConfigServiceValidation(uinDeps);
|
|
1428
1282
|
const cacheKey = uinDeps.cacheKey;
|
|
1429
1283
|
const prisma = uinDeps.prisma;
|
|
1430
1284
|
cron.schedule("01 0 * * *", async () => {
|
|
@@ -1449,27 +1303,13 @@ var uinConfigService = (uinDeps) => {
|
|
|
1449
1303
|
}
|
|
1450
1304
|
if (!shouldReset) continue;
|
|
1451
1305
|
try {
|
|
1452
|
-
await uinRepositoryFactory.updateSequenceNoAndResetDate(
|
|
1453
|
-
cfg.shortCode,
|
|
1454
|
-
BigInt(0),
|
|
1455
|
-
now
|
|
1456
|
-
);
|
|
1306
|
+
await uinRepositoryFactory.updateSequenceNoAndResetDate(cfg.shortCode, BigInt(0), now);
|
|
1457
1307
|
} catch (error) {
|
|
1458
|
-
logger.error(
|
|
1459
|
-
`Failed to reset sequence for shortCode ${cfg.shortCode}:`,
|
|
1460
|
-
error
|
|
1461
|
-
);
|
|
1308
|
+
logger.error(`Failed to reset sequence for shortCode ${cfg.shortCode}:`, error);
|
|
1462
1309
|
try {
|
|
1463
|
-
await uinRepositoryFactory.updateSequenceNoAndResetDate(
|
|
1464
|
-
cfg.shortCode,
|
|
1465
|
-
BigInt(0),
|
|
1466
|
-
now
|
|
1467
|
-
);
|
|
1310
|
+
await uinRepositoryFactory.updateSequenceNoAndResetDate(cfg.shortCode, BigInt(0), now);
|
|
1468
1311
|
} catch (retryError) {
|
|
1469
|
-
logger.error(
|
|
1470
|
-
`Retry failed for shortCode ${cfg.shortCode}:`,
|
|
1471
|
-
retryError
|
|
1472
|
-
);
|
|
1312
|
+
logger.error(`Retry failed for shortCode ${cfg.shortCode}:`, retryError);
|
|
1473
1313
|
}
|
|
1474
1314
|
}
|
|
1475
1315
|
if (await checkIsCacheable(uinConfigShortCode)) {
|
|
@@ -1498,9 +1338,7 @@ var uinConfigService = (uinDeps) => {
|
|
|
1498
1338
|
const cached = await getCacheById(cacheKey, shortCode);
|
|
1499
1339
|
if (cached) return cached;
|
|
1500
1340
|
}
|
|
1501
|
-
const cfg = await uinRepositoryFactory.getUINConfigByShortCodeFromDb(
|
|
1502
|
-
shortCode
|
|
1503
|
-
);
|
|
1341
|
+
const cfg = await uinRepositoryFactory.getUINConfigByShortCodeFromDb(shortCode);
|
|
1504
1342
|
if (!cfg) throw new ErrorHandler(404, `Invalid shortCode: ${shortCode}`);
|
|
1505
1343
|
if (useCache) {
|
|
1506
1344
|
await addToCache(cacheKey, shortCode, cfg);
|
|
@@ -1535,10 +1373,7 @@ var uinConfigService = (uinDeps) => {
|
|
|
1535
1373
|
logger.info("entering::updateUINConfig::service");
|
|
1536
1374
|
const existingUin = await updateIdUinConfigServiceValidation(req);
|
|
1537
1375
|
const isCacheable = await checkIsCacheable(uinConfigShortCode);
|
|
1538
|
-
const updatedUin = await uinRepositoryFactory.updateUINConfigInDb(
|
|
1539
|
-
req,
|
|
1540
|
-
existingUin
|
|
1541
|
-
);
|
|
1376
|
+
const updatedUin = await uinRepositoryFactory.updateUINConfigInDb(req, existingUin);
|
|
1542
1377
|
if (isCacheable && updatedUin) {
|
|
1543
1378
|
await updateCache(cacheKey, updatedUin.shortCode, updatedUin);
|
|
1544
1379
|
}
|
|
@@ -1644,9 +1479,7 @@ var EmailProvider = class {
|
|
|
1644
1479
|
attachments
|
|
1645
1480
|
// Optional attachments
|
|
1646
1481
|
});
|
|
1647
|
-
this.logger.info(
|
|
1648
|
-
`Email sent to ${recipient.email} with subject: ${subject}`
|
|
1649
|
-
);
|
|
1482
|
+
this.logger.info(`Email sent to ${recipient.email} with subject: ${subject}`);
|
|
1650
1483
|
return {
|
|
1651
1484
|
ok: true,
|
|
1652
1485
|
provider: "EMAIL" /* EMAIL */,
|
|
@@ -1758,34 +1591,43 @@ var NotificationService = class {
|
|
|
1758
1591
|
this.logger.info(
|
|
1759
1592
|
`[NotificationService] No config for event=${evt.eventName} serviceEventId=${evt.serviceEventId}`
|
|
1760
1593
|
);
|
|
1761
|
-
throw new this.helpers.ErrorHandler(
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1594
|
+
throw new this.helpers.ErrorHandler(400, this.helpers.generateErrorMessage("NOT_FOUND", evt.eventName));
|
|
1595
|
+
}
|
|
1596
|
+
let emailTpl = null;
|
|
1597
|
+
if (cfg.allowEmail && cfg.serviceEvent.allowEmail && cfg.serviceEvent.emailTemplateId) {
|
|
1598
|
+
emailTpl = await this.prisma.template.findUnique({
|
|
1599
|
+
where: { id: cfg.serviceEvent.emailTemplateId }
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
let smsTpl = null;
|
|
1603
|
+
if (cfg.allowSms && cfg.serviceEvent.allowSms && cfg.serviceEvent.smsTemplateId) {
|
|
1604
|
+
smsTpl = await this.prisma.template.findUnique({
|
|
1605
|
+
where: { id: cfg.serviceEvent.smsTemplateId }
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
let waTpl = null;
|
|
1609
|
+
if (cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp && cfg.serviceEvent.wpTemplateId) {
|
|
1610
|
+
waTpl = await this.prisma.template.findUnique({
|
|
1611
|
+
where: { id: cfg.serviceEvent.wpTemplateId }
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
let appTpl = null;
|
|
1615
|
+
if (cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification && cfg.serviceEvent.appNotificationTemplateId) {
|
|
1616
|
+
appTpl = await this.prisma.template.findUnique({
|
|
1617
|
+
where: { id: cfg.serviceEvent.appNotificationTemplateId }
|
|
1618
|
+
});
|
|
1765
1619
|
}
|
|
1766
|
-
const
|
|
1767
|
-
subject: "PO {{poNumber}} created",
|
|
1768
|
-
body: "<p>Hello {{vendor}}, PO {{poNumber}} created</p>"
|
|
1769
|
-
} : null;
|
|
1770
|
-
const smsTpl = cfg.allowSms && cfg.serviceEvent.allowSms ? { body: "PO {{poNumber}} created for {{vendor}}" } : null;
|
|
1771
|
-
const waTpl = cfg.allowWhatsapp && cfg.serviceEvent.allowWhatsapp ? { body: "*PO {{poNumber}}* created for {{vendor}}" } : null;
|
|
1772
|
-
const appTpl = cfg.allowAppNotification && cfg.serviceEvent.allowAppNotification ? {
|
|
1773
|
-
subject: "PO created",
|
|
1774
|
-
body: "PO {{poNumber}} created for {{vendor}}"
|
|
1775
|
-
} : null;
|
|
1776
|
-
const emailProvider = new EmailProvider(
|
|
1777
|
-
this.prisma,
|
|
1778
|
-
this.logger,
|
|
1779
|
-
this.envMode
|
|
1780
|
-
);
|
|
1620
|
+
const emailProvider = new EmailProvider(this.prisma, this.logger, this.envMode);
|
|
1781
1621
|
const smsProvider = new SmsProvider();
|
|
1782
|
-
const waProvider = new WhatsAppProvider(
|
|
1783
|
-
cfg.serviceEvent?.wpApiUrl ?? void 0
|
|
1784
|
-
);
|
|
1622
|
+
const waProvider = new WhatsAppProvider(cfg.serviceEvent?.wpApiUrl ?? void 0);
|
|
1785
1623
|
const appProvider = new AppNotificationProvider();
|
|
1624
|
+
this.logger.info(`[NotificationService] Email Template: ${JSON.stringify(emailTpl)}`);
|
|
1625
|
+
this.logger.info(`[NotificationService] SMS Template: ${JSON.stringify(smsTpl)}`);
|
|
1626
|
+
this.logger.info(`[NotificationService] WhatsApp Template: ${JSON.stringify(waTpl)}`);
|
|
1627
|
+
this.logger.info(`[NotificationService] App Notification Template: ${JSON.stringify(appTpl)}`);
|
|
1786
1628
|
const promises = [];
|
|
1787
1629
|
if (emailTpl) {
|
|
1788
|
-
const msg = renderEmailTemplate(emailTpl, evt.data);
|
|
1630
|
+
const msg = renderEmailTemplate({ body: emailTpl.bodyHtml ?? "", subject: emailTpl.subject ?? "" }, evt.data);
|
|
1789
1631
|
promises.push(
|
|
1790
1632
|
this.sendAndAudit({
|
|
1791
1633
|
providerType: "EMAIL" /* EMAIL */,
|
|
@@ -1798,7 +1640,7 @@ var NotificationService = class {
|
|
|
1798
1640
|
);
|
|
1799
1641
|
}
|
|
1800
1642
|
if (smsTpl) {
|
|
1801
|
-
const msg = renderTemplate(smsTpl.
|
|
1643
|
+
const msg = renderTemplate(smsTpl.bodyText, evt.data);
|
|
1802
1644
|
promises.push(
|
|
1803
1645
|
this.sendAndAudit({
|
|
1804
1646
|
providerType: "SMS" /* SMS */,
|
|
@@ -1810,7 +1652,7 @@ var NotificationService = class {
|
|
|
1810
1652
|
);
|
|
1811
1653
|
}
|
|
1812
1654
|
if (waTpl) {
|
|
1813
|
-
const msg = renderTemplate(waTpl.
|
|
1655
|
+
const msg = renderTemplate(waTpl.bodyText, evt.data);
|
|
1814
1656
|
promises.push(
|
|
1815
1657
|
this.sendAndAudit({
|
|
1816
1658
|
providerType: "WHATSAPP" /* WHATSAPP */,
|
|
@@ -1823,7 +1665,7 @@ var NotificationService = class {
|
|
|
1823
1665
|
}
|
|
1824
1666
|
if (appTpl) {
|
|
1825
1667
|
const subjectRendered = renderTemplate(appTpl.subject ?? "", evt.data);
|
|
1826
|
-
const bodyRendered = renderTemplate(appTpl.
|
|
1668
|
+
const bodyRendered = renderTemplate(appTpl.bodyText, evt.data);
|
|
1827
1669
|
promises.push(
|
|
1828
1670
|
this.sendAndAudit({
|
|
1829
1671
|
providerType: "APP_NOTIFICATION" /* APP_NOTIFICATION */,
|
|
@@ -1885,20 +1727,12 @@ var NotificationEmitter = class {
|
|
|
1885
1727
|
service;
|
|
1886
1728
|
constructor(deps) {
|
|
1887
1729
|
this.emitter = new EventEmitter();
|
|
1888
|
-
this.service = new NotificationService(
|
|
1889
|
-
deps.prisma,
|
|
1890
|
-
deps.logger ?? console,
|
|
1891
|
-
deps.envMode,
|
|
1892
|
-
deps.helpers
|
|
1893
|
-
);
|
|
1730
|
+
this.service = new NotificationService(deps.prisma, deps.logger ?? console, deps.envMode, deps.helpers);
|
|
1894
1731
|
this.emitter.on("notify", async (payload) => {
|
|
1895
1732
|
try {
|
|
1896
1733
|
await this.service.handleEvent(payload);
|
|
1897
1734
|
} catch (err) {
|
|
1898
|
-
(deps.logger ?? console).error(
|
|
1899
|
-
"[NotificationEmitter] Error handling event",
|
|
1900
|
-
err
|
|
1901
|
-
);
|
|
1735
|
+
(deps.logger ?? console).error("[NotificationEmitter] Error handling event", err);
|
|
1902
1736
|
}
|
|
1903
1737
|
});
|
|
1904
1738
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "av6-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"author": "Aniket Sarkar",
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "tsup"
|
|
11
|
+
"build": "npm run format && tsup",
|
|
12
|
+
"format": "prettier --write **/*.ts"
|
|
12
13
|
},
|
|
13
14
|
"devDependencies": {
|
|
14
15
|
"@types/nodemailer": "^7.0.3",
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
"exceljs": "^4.4.0",
|
|
26
27
|
"handlebars": "^4.7.8",
|
|
27
28
|
"node-cron": "^4.2.1",
|
|
28
|
-
"nodemailer": "^7.0.10"
|
|
29
|
+
"nodemailer": "^7.0.10",
|
|
30
|
+
"prettier": "^3.6.2"
|
|
29
31
|
}
|
|
30
32
|
}
|