av6-core 1.1.7 → 1.1.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/dist/index.d.mts +43 -1
- package/dist/index.d.ts +43 -1
- package/dist/index.js +100 -3
- package/dist/index.mjs +99 -3
- package/package.json +32 -32
package/dist/index.d.mts
CHANGED
|
@@ -29,6 +29,22 @@ declare enum ErrorMessageType {
|
|
|
29
29
|
EXCEL = "No data found to be downloaded"
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
interface EmployeeCache {
|
|
33
|
+
id: number;
|
|
34
|
+
name: string;
|
|
35
|
+
surname: string | null;
|
|
36
|
+
dob: string | null;
|
|
37
|
+
employeeId: string | null;
|
|
38
|
+
title: string | null;
|
|
39
|
+
phone: string | null;
|
|
40
|
+
email: string | null;
|
|
41
|
+
departmentId: number | null;
|
|
42
|
+
designationId: number | null;
|
|
43
|
+
}
|
|
44
|
+
interface CommonFilterWithDate extends CommonFilterRequest {
|
|
45
|
+
startDate?: string;
|
|
46
|
+
endDate?: string;
|
|
47
|
+
}
|
|
32
48
|
interface ToggleActive {
|
|
33
49
|
id: number;
|
|
34
50
|
action: "ACTIVE" | "IN_ACTIVE";
|
|
@@ -58,6 +74,7 @@ interface CommonFilterRequest {
|
|
|
58
74
|
pageSize: number;
|
|
59
75
|
sortBy?: string;
|
|
60
76
|
sortDir?: "ASC" | "DESC";
|
|
77
|
+
searchText?: string;
|
|
61
78
|
}
|
|
62
79
|
interface File {
|
|
63
80
|
fieldname: string;
|
|
@@ -168,6 +185,27 @@ interface updateStatusParams {
|
|
|
168
185
|
interface UpdateStatusRequestRepository<T extends DynamicShortCode> extends updateStatusParams {
|
|
169
186
|
shortCodeData: T;
|
|
170
187
|
}
|
|
188
|
+
interface LockUnlockParams {
|
|
189
|
+
shortCode: string;
|
|
190
|
+
id: number;
|
|
191
|
+
}
|
|
192
|
+
interface LockUnlockRequestRepository<T extends DynamicShortCode> extends LockUnlockParams {
|
|
193
|
+
shortCodeData: T;
|
|
194
|
+
}
|
|
195
|
+
interface CommonCreateParams {
|
|
196
|
+
shortCode: string;
|
|
197
|
+
value: string;
|
|
198
|
+
description?: string;
|
|
199
|
+
}
|
|
200
|
+
interface CommonCreateRequestRepository<T extends DynamicShortCode> extends CommonCreateParams {
|
|
201
|
+
shortCodeData: T;
|
|
202
|
+
}
|
|
203
|
+
interface CommonUpdateParams extends CommonCreateParams {
|
|
204
|
+
id: number;
|
|
205
|
+
}
|
|
206
|
+
interface CommonUpdateRequestRepository<T extends DynamicShortCode> extends CommonUpdateParams {
|
|
207
|
+
shortCodeData: T;
|
|
208
|
+
}
|
|
171
209
|
interface PaginatedResponse<T> {
|
|
172
210
|
totalRecords: number;
|
|
173
211
|
currentPageNumber: number;
|
|
@@ -251,6 +289,9 @@ interface CommonServiceResponse {
|
|
|
251
289
|
commonExcelExport: (exportParams: ExportExcelRequestService<DynamicShortCode>) => Promise<ExcelJs.Workbook>;
|
|
252
290
|
delete: (deleteParams: DeleteRequestRepository<DynamicShortCode>) => Promise<void>;
|
|
253
291
|
updateStatus: (updateStatusParams: UpdateStatusRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
292
|
+
lockUnlock: (lockUnlockParams: LockUnlockRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
293
|
+
create: (createParams: CommonCreateRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
294
|
+
update: (updateParams: CommonUpdateRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
254
295
|
fetchImageStream: (imageBaseUrl: string, fileName: string) => Promise<AxiosResponse<Readable>>;
|
|
255
296
|
}
|
|
256
297
|
|
|
@@ -267,6 +308,7 @@ declare const getPattern: {
|
|
|
267
308
|
[key: string]: RegExp;
|
|
268
309
|
};
|
|
269
310
|
declare const interpolate: (template: string, vars: Record<string, unknown>) => string;
|
|
311
|
+
declare const fromTimestampToSqlDatetime: (date: string) => string;
|
|
270
312
|
|
|
271
313
|
interface CreateTransaction {
|
|
272
314
|
field: string;
|
|
@@ -430,4 +472,4 @@ declare class AuditProxy {
|
|
|
430
472
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
431
473
|
}
|
|
432
474
|
|
|
433
|
-
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
475
|
+
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateParams, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateParams, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,22 @@ declare enum ErrorMessageType {
|
|
|
29
29
|
EXCEL = "No data found to be downloaded"
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
interface EmployeeCache {
|
|
33
|
+
id: number;
|
|
34
|
+
name: string;
|
|
35
|
+
surname: string | null;
|
|
36
|
+
dob: string | null;
|
|
37
|
+
employeeId: string | null;
|
|
38
|
+
title: string | null;
|
|
39
|
+
phone: string | null;
|
|
40
|
+
email: string | null;
|
|
41
|
+
departmentId: number | null;
|
|
42
|
+
designationId: number | null;
|
|
43
|
+
}
|
|
44
|
+
interface CommonFilterWithDate extends CommonFilterRequest {
|
|
45
|
+
startDate?: string;
|
|
46
|
+
endDate?: string;
|
|
47
|
+
}
|
|
32
48
|
interface ToggleActive {
|
|
33
49
|
id: number;
|
|
34
50
|
action: "ACTIVE" | "IN_ACTIVE";
|
|
@@ -58,6 +74,7 @@ interface CommonFilterRequest {
|
|
|
58
74
|
pageSize: number;
|
|
59
75
|
sortBy?: string;
|
|
60
76
|
sortDir?: "ASC" | "DESC";
|
|
77
|
+
searchText?: string;
|
|
61
78
|
}
|
|
62
79
|
interface File {
|
|
63
80
|
fieldname: string;
|
|
@@ -168,6 +185,27 @@ interface updateStatusParams {
|
|
|
168
185
|
interface UpdateStatusRequestRepository<T extends DynamicShortCode> extends updateStatusParams {
|
|
169
186
|
shortCodeData: T;
|
|
170
187
|
}
|
|
188
|
+
interface LockUnlockParams {
|
|
189
|
+
shortCode: string;
|
|
190
|
+
id: number;
|
|
191
|
+
}
|
|
192
|
+
interface LockUnlockRequestRepository<T extends DynamicShortCode> extends LockUnlockParams {
|
|
193
|
+
shortCodeData: T;
|
|
194
|
+
}
|
|
195
|
+
interface CommonCreateParams {
|
|
196
|
+
shortCode: string;
|
|
197
|
+
value: string;
|
|
198
|
+
description?: string;
|
|
199
|
+
}
|
|
200
|
+
interface CommonCreateRequestRepository<T extends DynamicShortCode> extends CommonCreateParams {
|
|
201
|
+
shortCodeData: T;
|
|
202
|
+
}
|
|
203
|
+
interface CommonUpdateParams extends CommonCreateParams {
|
|
204
|
+
id: number;
|
|
205
|
+
}
|
|
206
|
+
interface CommonUpdateRequestRepository<T extends DynamicShortCode> extends CommonUpdateParams {
|
|
207
|
+
shortCodeData: T;
|
|
208
|
+
}
|
|
171
209
|
interface PaginatedResponse<T> {
|
|
172
210
|
totalRecords: number;
|
|
173
211
|
currentPageNumber: number;
|
|
@@ -251,6 +289,9 @@ interface CommonServiceResponse {
|
|
|
251
289
|
commonExcelExport: (exportParams: ExportExcelRequestService<DynamicShortCode>) => Promise<ExcelJs.Workbook>;
|
|
252
290
|
delete: (deleteParams: DeleteRequestRepository<DynamicShortCode>) => Promise<void>;
|
|
253
291
|
updateStatus: (updateStatusParams: UpdateStatusRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
292
|
+
lockUnlock: (lockUnlockParams: LockUnlockRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
293
|
+
create: (createParams: CommonCreateRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
294
|
+
update: (updateParams: CommonUpdateRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
254
295
|
fetchImageStream: (imageBaseUrl: string, fileName: string) => Promise<AxiosResponse<Readable>>;
|
|
255
296
|
}
|
|
256
297
|
|
|
@@ -267,6 +308,7 @@ declare const getPattern: {
|
|
|
267
308
|
[key: string]: RegExp;
|
|
268
309
|
};
|
|
269
310
|
declare const interpolate: (template: string, vars: Record<string, unknown>) => string;
|
|
311
|
+
declare const fromTimestampToSqlDatetime: (date: string) => string;
|
|
270
312
|
|
|
271
313
|
interface CreateTransaction {
|
|
272
314
|
field: string;
|
|
@@ -430,4 +472,4 @@ declare class AuditProxy {
|
|
|
430
472
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
431
473
|
}
|
|
432
474
|
|
|
433
|
-
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
475
|
+
export { type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type CacheAdapter, type CalculationRes, type ColValue, type CommonCreateParams, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonServiceResponse, type CommonUpdateParams, type CommonUpdateRequestRepository, type Config, type Context, type CreateUINConfigRequest, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type EmitPayload, type EmployeeCache, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type LockUnlockParams, type LockUnlockRequestRepository, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type PaginatedResponse, type Recipient, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type Store, type ToggleActive, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, commonService, customOmit, findDifferences, fromTimestampToSqlDatetime, getDynamicValue, getPattern, interpolate, objectTo2DArray, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
commonService: () => commonService,
|
|
38
38
|
customOmit: () => customOmit,
|
|
39
39
|
findDifferences: () => findDifferences,
|
|
40
|
+
fromTimestampToSqlDatetime: () => fromTimestampToSqlDatetime,
|
|
40
41
|
getDynamicValue: () => getDynamicValue,
|
|
41
42
|
getPattern: () => getPattern,
|
|
42
43
|
interpolate: () => interpolate,
|
|
@@ -434,6 +435,62 @@ var commonRepository = (serviceDeps) => {
|
|
|
434
435
|
logger.info("exiting::commonUpdateStatus::repository");
|
|
435
436
|
return results;
|
|
436
437
|
},
|
|
438
|
+
async commonlockUnlock({ id, shortCodeData }) {
|
|
439
|
+
logger.info("entering::commonlockUnlock::repository");
|
|
440
|
+
const tableName = shortCodeData.tableName;
|
|
441
|
+
const model = db[tableName];
|
|
442
|
+
if (!model) {
|
|
443
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
444
|
+
}
|
|
445
|
+
const currentRecord = await model.findUnique({
|
|
446
|
+
where: { id },
|
|
447
|
+
select: { isLock: true }
|
|
448
|
+
});
|
|
449
|
+
if (!currentRecord) {
|
|
450
|
+
throw new ErrorHandler(404, "Record not found");
|
|
451
|
+
}
|
|
452
|
+
const updatedRecord = await model.update({
|
|
453
|
+
where: { id },
|
|
454
|
+
data: {
|
|
455
|
+
isLock: !currentRecord.isLock
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
logger.info("exiting::commonLock::repository");
|
|
459
|
+
return updatedRecord;
|
|
460
|
+
},
|
|
461
|
+
async commonCreate({ shortCodeData, value, description }) {
|
|
462
|
+
logger.info("entering::commonCreate::repository");
|
|
463
|
+
const tableName = shortCodeData.tableName;
|
|
464
|
+
const model = db[tableName];
|
|
465
|
+
if (!model) {
|
|
466
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
467
|
+
}
|
|
468
|
+
const results = model.create({
|
|
469
|
+
data: {
|
|
470
|
+
value,
|
|
471
|
+
description
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
logger.info("exiting::commonCreate::repository");
|
|
475
|
+
return results;
|
|
476
|
+
},
|
|
477
|
+
async commonUpdate({ id, shortCodeData, value, description }) {
|
|
478
|
+
logger.info("entering::commonUpdate::repository");
|
|
479
|
+
const tableName = shortCodeData.tableName;
|
|
480
|
+
const model = db[tableName];
|
|
481
|
+
if (!model) {
|
|
482
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
483
|
+
}
|
|
484
|
+
const results = model.update({
|
|
485
|
+
where: { id },
|
|
486
|
+
data: {
|
|
487
|
+
value,
|
|
488
|
+
description
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
logger.info("exiting::commonUpdate::repository");
|
|
492
|
+
return results;
|
|
493
|
+
},
|
|
437
494
|
async generateRootCondition({
|
|
438
495
|
fixedSearch,
|
|
439
496
|
fixedNotSearch
|
|
@@ -879,6 +936,7 @@ var interpolate = (template, vars) => {
|
|
|
879
936
|
return key in vars ? String(vars[key]) : "";
|
|
880
937
|
});
|
|
881
938
|
};
|
|
939
|
+
var fromTimestampToSqlDatetime = (date) => date.replace("T", " ").replace("Z", "");
|
|
882
940
|
|
|
883
941
|
// src/services/common.service.ts
|
|
884
942
|
var import_axios = __toESM(require("axios"));
|
|
@@ -886,7 +944,7 @@ var import_exceljs = __toESM(require("exceljs"));
|
|
|
886
944
|
var commonService = (serviceDeps) => {
|
|
887
945
|
const generateErrorMessage = serviceDeps.helpers.generateErrorMessage;
|
|
888
946
|
const ErrorHandler = serviceDeps.helpers.ErrorHandler;
|
|
889
|
-
const { deleteCache, getCacheById, updateCache } = serviceDeps.cacheAdapter;
|
|
947
|
+
const { deleteCache, getCacheById, updateCache, createCache } = serviceDeps.cacheAdapter;
|
|
890
948
|
const logger = serviceDeps.logger;
|
|
891
949
|
const dtoMapping = serviceDeps.mapper.dtoMapping;
|
|
892
950
|
const { REDIS_PREFIX, CACHE_KEY_NAME } = serviceDeps.config;
|
|
@@ -1114,6 +1172,44 @@ var commonService = (serviceDeps) => {
|
|
|
1114
1172
|
logger.info("exiting::updateStatus::service");
|
|
1115
1173
|
return updatedData;
|
|
1116
1174
|
},
|
|
1175
|
+
async lockUnlock(lockUnlockParams) {
|
|
1176
|
+
logger.info("entering::lockUnlock::service");
|
|
1177
|
+
const shortCodeData = lockUnlockParams.shortCodeData;
|
|
1178
|
+
const lockResult = await commonRepositoryFactory.commonlockUnlock({ ...lockUnlockParams, shortCodeData });
|
|
1179
|
+
if (shortCodeData.isCacheable) {
|
|
1180
|
+
await updateCache(
|
|
1181
|
+
`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
|
|
1182
|
+
lockUnlockParams.id,
|
|
1183
|
+
lockResult
|
|
1184
|
+
);
|
|
1185
|
+
}
|
|
1186
|
+
logger.info("exiting::lockUnlock::service");
|
|
1187
|
+
return lockResult;
|
|
1188
|
+
},
|
|
1189
|
+
async create(createParams) {
|
|
1190
|
+
logger.info("entering::create::service");
|
|
1191
|
+
const shortCodeData = createParams.shortCodeData;
|
|
1192
|
+
const createResult = await commonRepositoryFactory.commonCreate({ ...createParams, shortCodeData });
|
|
1193
|
+
if (shortCodeData.isCacheable) {
|
|
1194
|
+
await createCache(`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`, createResult);
|
|
1195
|
+
}
|
|
1196
|
+
logger.info("exiting::create::service");
|
|
1197
|
+
return createResult;
|
|
1198
|
+
},
|
|
1199
|
+
async update(updateParams) {
|
|
1200
|
+
logger.info("entering::update::service");
|
|
1201
|
+
const shortCodeData = updateParams.shortCodeData;
|
|
1202
|
+
const updateResult = await commonRepositoryFactory.commonUpdate({ ...updateParams, shortCodeData });
|
|
1203
|
+
if (shortCodeData.isCacheable) {
|
|
1204
|
+
await updateCache(
|
|
1205
|
+
`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
|
|
1206
|
+
updateResult.id,
|
|
1207
|
+
updateResult
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
logger.info("exiting::update::service");
|
|
1211
|
+
return updateResult;
|
|
1212
|
+
},
|
|
1117
1213
|
async fetchImageStream(imageBaseUrl, fileName) {
|
|
1118
1214
|
const url = imageBaseUrl + fileName;
|
|
1119
1215
|
return import_axios.default.get(url, { responseType: "stream" });
|
|
@@ -2027,7 +2123,7 @@ var AuditLogger = class {
|
|
|
2027
2123
|
if (!config || !config.isAuditable) {
|
|
2028
2124
|
return;
|
|
2029
2125
|
}
|
|
2030
|
-
const message = config.message;
|
|
2126
|
+
const message = payload.type === "ERROR" ? payload.message : config.message;
|
|
2031
2127
|
const type = payload.type ?? "INFO";
|
|
2032
2128
|
const ccId = payload.ccId ?? ctxCcId ?? 0;
|
|
2033
2129
|
await prisma.commonAudit.create({
|
|
@@ -2082,7 +2178,7 @@ var AuditProxy = class {
|
|
|
2082
2178
|
throw err;
|
|
2083
2179
|
} finally {
|
|
2084
2180
|
const hasError = !!error;
|
|
2085
|
-
const message = hasError ?
|
|
2181
|
+
const message = hasError ? error.message : `Executed ${serviceName}.${methodName}`;
|
|
2086
2182
|
logger.logIfEnabled({
|
|
2087
2183
|
service: serviceName,
|
|
2088
2184
|
method: methodName,
|
|
@@ -2110,6 +2206,7 @@ var AuditProxy = class {
|
|
|
2110
2206
|
commonService,
|
|
2111
2207
|
customOmit,
|
|
2112
2208
|
findDifferences,
|
|
2209
|
+
fromTimestampToSqlDatetime,
|
|
2113
2210
|
getDynamicValue,
|
|
2114
2211
|
getPattern,
|
|
2115
2212
|
interpolate,
|
package/dist/index.mjs
CHANGED
|
@@ -385,6 +385,62 @@ var commonRepository = (serviceDeps) => {
|
|
|
385
385
|
logger.info("exiting::commonUpdateStatus::repository");
|
|
386
386
|
return results;
|
|
387
387
|
},
|
|
388
|
+
async commonlockUnlock({ id, shortCodeData }) {
|
|
389
|
+
logger.info("entering::commonlockUnlock::repository");
|
|
390
|
+
const tableName = shortCodeData.tableName;
|
|
391
|
+
const model = db[tableName];
|
|
392
|
+
if (!model) {
|
|
393
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
394
|
+
}
|
|
395
|
+
const currentRecord = await model.findUnique({
|
|
396
|
+
where: { id },
|
|
397
|
+
select: { isLock: true }
|
|
398
|
+
});
|
|
399
|
+
if (!currentRecord) {
|
|
400
|
+
throw new ErrorHandler(404, "Record not found");
|
|
401
|
+
}
|
|
402
|
+
const updatedRecord = await model.update({
|
|
403
|
+
where: { id },
|
|
404
|
+
data: {
|
|
405
|
+
isLock: !currentRecord.isLock
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
logger.info("exiting::commonLock::repository");
|
|
409
|
+
return updatedRecord;
|
|
410
|
+
},
|
|
411
|
+
async commonCreate({ shortCodeData, value, description }) {
|
|
412
|
+
logger.info("entering::commonCreate::repository");
|
|
413
|
+
const tableName = shortCodeData.tableName;
|
|
414
|
+
const model = db[tableName];
|
|
415
|
+
if (!model) {
|
|
416
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
417
|
+
}
|
|
418
|
+
const results = model.create({
|
|
419
|
+
data: {
|
|
420
|
+
value,
|
|
421
|
+
description
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
logger.info("exiting::commonCreate::repository");
|
|
425
|
+
return results;
|
|
426
|
+
},
|
|
427
|
+
async commonUpdate({ id, shortCodeData, value, description }) {
|
|
428
|
+
logger.info("entering::commonUpdate::repository");
|
|
429
|
+
const tableName = shortCodeData.tableName;
|
|
430
|
+
const model = db[tableName];
|
|
431
|
+
if (!model) {
|
|
432
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
433
|
+
}
|
|
434
|
+
const results = model.update({
|
|
435
|
+
where: { id },
|
|
436
|
+
data: {
|
|
437
|
+
value,
|
|
438
|
+
description
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
logger.info("exiting::commonUpdate::repository");
|
|
442
|
+
return results;
|
|
443
|
+
},
|
|
388
444
|
async generateRootCondition({
|
|
389
445
|
fixedSearch,
|
|
390
446
|
fixedNotSearch
|
|
@@ -830,6 +886,7 @@ var interpolate = (template, vars) => {
|
|
|
830
886
|
return key in vars ? String(vars[key]) : "";
|
|
831
887
|
});
|
|
832
888
|
};
|
|
889
|
+
var fromTimestampToSqlDatetime = (date) => date.replace("T", " ").replace("Z", "");
|
|
833
890
|
|
|
834
891
|
// src/services/common.service.ts
|
|
835
892
|
import axios from "axios";
|
|
@@ -837,7 +894,7 @@ import ExcelJs from "exceljs";
|
|
|
837
894
|
var commonService = (serviceDeps) => {
|
|
838
895
|
const generateErrorMessage = serviceDeps.helpers.generateErrorMessage;
|
|
839
896
|
const ErrorHandler = serviceDeps.helpers.ErrorHandler;
|
|
840
|
-
const { deleteCache, getCacheById, updateCache } = serviceDeps.cacheAdapter;
|
|
897
|
+
const { deleteCache, getCacheById, updateCache, createCache } = serviceDeps.cacheAdapter;
|
|
841
898
|
const logger = serviceDeps.logger;
|
|
842
899
|
const dtoMapping = serviceDeps.mapper.dtoMapping;
|
|
843
900
|
const { REDIS_PREFIX, CACHE_KEY_NAME } = serviceDeps.config;
|
|
@@ -1065,6 +1122,44 @@ var commonService = (serviceDeps) => {
|
|
|
1065
1122
|
logger.info("exiting::updateStatus::service");
|
|
1066
1123
|
return updatedData;
|
|
1067
1124
|
},
|
|
1125
|
+
async lockUnlock(lockUnlockParams) {
|
|
1126
|
+
logger.info("entering::lockUnlock::service");
|
|
1127
|
+
const shortCodeData = lockUnlockParams.shortCodeData;
|
|
1128
|
+
const lockResult = await commonRepositoryFactory.commonlockUnlock({ ...lockUnlockParams, shortCodeData });
|
|
1129
|
+
if (shortCodeData.isCacheable) {
|
|
1130
|
+
await updateCache(
|
|
1131
|
+
`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
|
|
1132
|
+
lockUnlockParams.id,
|
|
1133
|
+
lockResult
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
logger.info("exiting::lockUnlock::service");
|
|
1137
|
+
return lockResult;
|
|
1138
|
+
},
|
|
1139
|
+
async create(createParams) {
|
|
1140
|
+
logger.info("entering::create::service");
|
|
1141
|
+
const shortCodeData = createParams.shortCodeData;
|
|
1142
|
+
const createResult = await commonRepositoryFactory.commonCreate({ ...createParams, shortCodeData });
|
|
1143
|
+
if (shortCodeData.isCacheable) {
|
|
1144
|
+
await createCache(`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`, createResult);
|
|
1145
|
+
}
|
|
1146
|
+
logger.info("exiting::create::service");
|
|
1147
|
+
return createResult;
|
|
1148
|
+
},
|
|
1149
|
+
async update(updateParams) {
|
|
1150
|
+
logger.info("entering::update::service");
|
|
1151
|
+
const shortCodeData = updateParams.shortCodeData;
|
|
1152
|
+
const updateResult = await commonRepositoryFactory.commonUpdate({ ...updateParams, shortCodeData });
|
|
1153
|
+
if (shortCodeData.isCacheable) {
|
|
1154
|
+
await updateCache(
|
|
1155
|
+
`${REDIS_PREFIX}${CACHE_KEY_NAME}:${shortCodeData.tableName}:all`,
|
|
1156
|
+
updateResult.id,
|
|
1157
|
+
updateResult
|
|
1158
|
+
);
|
|
1159
|
+
}
|
|
1160
|
+
logger.info("exiting::update::service");
|
|
1161
|
+
return updateResult;
|
|
1162
|
+
},
|
|
1068
1163
|
async fetchImageStream(imageBaseUrl, fileName) {
|
|
1069
1164
|
const url = imageBaseUrl + fileName;
|
|
1070
1165
|
return axios.get(url, { responseType: "stream" });
|
|
@@ -1978,7 +2073,7 @@ var AuditLogger = class {
|
|
|
1978
2073
|
if (!config || !config.isAuditable) {
|
|
1979
2074
|
return;
|
|
1980
2075
|
}
|
|
1981
|
-
const message = config.message;
|
|
2076
|
+
const message = payload.type === "ERROR" ? payload.message : config.message;
|
|
1982
2077
|
const type = payload.type ?? "INFO";
|
|
1983
2078
|
const ccId = payload.ccId ?? ctxCcId ?? 0;
|
|
1984
2079
|
await prisma.commonAudit.create({
|
|
@@ -2033,7 +2128,7 @@ var AuditProxy = class {
|
|
|
2033
2128
|
throw err;
|
|
2034
2129
|
} finally {
|
|
2035
2130
|
const hasError = !!error;
|
|
2036
|
-
const message = hasError ?
|
|
2131
|
+
const message = hasError ? error.message : `Executed ${serviceName}.${methodName}`;
|
|
2037
2132
|
logger.logIfEnabled({
|
|
2038
2133
|
service: serviceName,
|
|
2039
2134
|
method: methodName,
|
|
@@ -2060,6 +2155,7 @@ export {
|
|
|
2060
2155
|
commonService,
|
|
2061
2156
|
customOmit,
|
|
2062
2157
|
findDifferences,
|
|
2158
|
+
fromTimestampToSqlDatetime,
|
|
2063
2159
|
getDynamicValue,
|
|
2064
2160
|
getPattern,
|
|
2065
2161
|
interpolate,
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "av6-core",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"module": "dist/index.mjs",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"description": "All utility function for av6 node js projects.",
|
|
8
|
-
"author": "Aniket Sarkar",
|
|
9
|
-
"license": "ISC",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "npm run format && tsup",
|
|
12
|
-
"format": "prettier --write **/*.ts"
|
|
13
|
-
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@types/nodemailer": "^7.0.3",
|
|
16
|
-
"tsup": "^8.5.0",
|
|
17
|
-
"typescript": "^5.9.2"
|
|
18
|
-
},
|
|
19
|
-
"peerDependencies": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"axios": "^1.11.0",
|
|
26
|
-
"exceljs": "^4.4.0",
|
|
27
|
-
"handlebars": "^4.7.8",
|
|
28
|
-
"node-cron": "^4.2.1",
|
|
29
|
-
"nodemailer": "^7.0.10",
|
|
30
|
-
"prettier": "^3.6.2"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "av6-core",
|
|
3
|
+
"version": "1.1.9",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.mjs",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"description": "All utility function for av6 node js projects.",
|
|
8
|
+
"author": "Aniket Sarkar",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "npm run format && tsup",
|
|
12
|
+
"format": "prettier --write **/*.ts"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/nodemailer": "^7.0.3",
|
|
16
|
+
"tsup": "^8.5.0",
|
|
17
|
+
"typescript": "^5.9.2"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"winston": "^3.17.0"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@prisma/client": "^6.19.0",
|
|
24
|
+
"prisma": "^6.19.0",
|
|
25
|
+
"axios": "^1.11.0",
|
|
26
|
+
"exceljs": "^4.4.0",
|
|
27
|
+
"handlebars": "^4.7.8",
|
|
28
|
+
"node-cron": "^4.2.1",
|
|
29
|
+
"nodemailer": "^7.0.10",
|
|
30
|
+
"prettier": "^3.6.2"
|
|
31
|
+
}
|
|
32
|
+
}
|