av6-core 2.0.1 → 2.0.3
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 +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +97 -22
- package/dist/index.mjs +97 -22
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -308,6 +308,19 @@ type DynamicShortCode = {
|
|
|
308
308
|
whereClause?: Prisma.JsonValue | null;
|
|
309
309
|
selectClause?: Prisma.JsonValue | null;
|
|
310
310
|
config?: Prisma.JsonValue | null;
|
|
311
|
+
deleteConfig?: Prisma.JsonValue | null;
|
|
312
|
+
};
|
|
313
|
+
type SoftDeleteChildConfig = {
|
|
314
|
+
tableName: string;
|
|
315
|
+
foreignKey: string;
|
|
316
|
+
primaryKey?: string;
|
|
317
|
+
activeField?: string;
|
|
318
|
+
onlyActive?: boolean;
|
|
319
|
+
extraWhere?: Record<string, unknown>;
|
|
320
|
+
children?: SoftDeleteChildConfig[];
|
|
321
|
+
};
|
|
322
|
+
type SoftDeleteConfig = {
|
|
323
|
+
children?: SoftDeleteChildConfig[];
|
|
311
324
|
};
|
|
312
325
|
interface UpdateConfigByCodeInput extends Pick<DynamicShortCode, "config"> {
|
|
313
326
|
shortCode: string;
|
|
@@ -611,6 +624,9 @@ type ApprovalAction = {
|
|
|
611
624
|
comment: string | null;
|
|
612
625
|
actedAt: Date;
|
|
613
626
|
};
|
|
627
|
+
type ApprovalActionWithInstance = ApprovalAction & {
|
|
628
|
+
approvalInstance: ApprovalInstance | null;
|
|
629
|
+
};
|
|
614
630
|
type LevelReadyEvt = {
|
|
615
631
|
instanceId: number;
|
|
616
632
|
subjectType: string;
|
|
@@ -820,7 +836,7 @@ declare class ApprovalService {
|
|
|
820
836
|
private emitEvents;
|
|
821
837
|
private assertPermission;
|
|
822
838
|
getAllApprovalFlow(input: GetMyApprovalFlow): Promise<PaginatedResponse<ApprovalInstanceByUser>>;
|
|
823
|
-
getApprovalActDetailsBySubjectId(subjectId: number, subjectType: string, service: string): Promise<
|
|
839
|
+
getApprovalActDetailsBySubjectId(subjectId: number, subjectType: string, service: string): Promise<ApprovalActionWithInstance[]>;
|
|
824
840
|
commonStatusUpdate(config: IParentConfigJSON, data: ICommonApprovalUpdate): Promise<void>;
|
|
825
841
|
commonParentChildUpdate(config: IParentConfigJSON, childConfig: IChildConfigJSON | null, inst: EventInstance): Promise<void>;
|
|
826
842
|
}
|
|
@@ -1036,4 +1052,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
1036
1052
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
1037
1053
|
}
|
|
1038
1054
|
|
|
1039
|
-
export { type ActInput, ActionMode, type ApprovalAction, type ApprovalActionDto, type ApprovalDeps, type ApprovalFlow, type ApprovalInstance, type ApprovalInstanceByUser, ApprovalService, ApprovalStatus, type ApprovalStep, type ApproverMapping, type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type BulkAtomicResult, type BulkConfig, type BulkConflictConfig, type BulkOnConflict, type CacheAdapter, type CalculationRes, type ColValue, type CommonApproveReq, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonGetApprovalActionReq, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateApprovalFlow, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeepMerge, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type EventInstance, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedMap, type FixedSearchRequest, type FixedSearchRequestService, FlowType, type FlowWithSelectedStepResponse, type FlowWithStepsResponse, type GetMyApprovalFlow, type GetPendingApprovalReq, type Helpers, type IApprovalStep, type IChildConfigData, type IChildConfigJSON, type ICommonApprovalUpdate, type IParentConfigData, type IParentConfigJSON, type ImportExcel, type ImportExcelRequestService, type LevelDoneEvt, type LevelReadyEvt, type LockUnlockParams, type LockUnlockRequestRepository, type LogicNode, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type NotificationEvent, type Op, type PaginatedResponse, type PathToSelectWithSelect, type PathValue, type PathsToSelectWithSelect, type Presence, type PrismaTransactionClient, type RawFlowWithSelectedStepResponse, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SourcePath, type StartFlowReq, type StepType, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateApprovalFlow, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, approvalRepository, commonService, convertArrayPatternToEachBlocksGeneric, customOmit, findDifferences, formatDatesDeep, fromTimestampToSqlDatetime, generateHashForAuth, generateMd5, getDynamicValue, getNestedValue, getNestedValueV2, getPattern, interpolate, objectTo2DArray, renderEmailTemplate, renderTemplate, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
1055
|
+
export { type ActInput, ActionMode, type ApprovalAction, type ApprovalActionDto, type ApprovalActionWithInstance, type ApprovalDeps, type ApprovalFlow, type ApprovalInstance, type ApprovalInstanceByUser, ApprovalService, ApprovalStatus, type ApprovalStep, type ApproverMapping, type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type BulkAtomicResult, type BulkConfig, type BulkConflictConfig, type BulkOnConflict, type CacheAdapter, type CalculationRes, type ColValue, type CommonApproveReq, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonGetApprovalActionReq, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateApprovalFlow, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeepMerge, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type EventInstance, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedMap, type FixedSearchRequest, type FixedSearchRequestService, FlowType, type FlowWithSelectedStepResponse, type FlowWithStepsResponse, type GetMyApprovalFlow, type GetPendingApprovalReq, type Helpers, type IApprovalStep, type IChildConfigData, type IChildConfigJSON, type ICommonApprovalUpdate, type IParentConfigData, type IParentConfigJSON, type ImportExcel, type ImportExcelRequestService, type LevelDoneEvt, type LevelReadyEvt, type LockUnlockParams, type LockUnlockRequestRepository, type LogicNode, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type NotificationEvent, type Op, type PaginatedResponse, type PathToSelectWithSelect, type PathValue, type PathsToSelectWithSelect, type Presence, type PrismaTransactionClient, type RawFlowWithSelectedStepResponse, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SoftDeleteChildConfig, type SoftDeleteConfig, type SourcePath, type StartFlowReq, type StepType, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateApprovalFlow, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, approvalRepository, commonService, convertArrayPatternToEachBlocksGeneric, customOmit, findDifferences, formatDatesDeep, fromTimestampToSqlDatetime, generateHashForAuth, generateMd5, getDynamicValue, getNestedValue, getNestedValueV2, getPattern, interpolate, objectTo2DArray, renderEmailTemplate, renderTemplate, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -308,6 +308,19 @@ type DynamicShortCode = {
|
|
|
308
308
|
whereClause?: Prisma.JsonValue | null;
|
|
309
309
|
selectClause?: Prisma.JsonValue | null;
|
|
310
310
|
config?: Prisma.JsonValue | null;
|
|
311
|
+
deleteConfig?: Prisma.JsonValue | null;
|
|
312
|
+
};
|
|
313
|
+
type SoftDeleteChildConfig = {
|
|
314
|
+
tableName: string;
|
|
315
|
+
foreignKey: string;
|
|
316
|
+
primaryKey?: string;
|
|
317
|
+
activeField?: string;
|
|
318
|
+
onlyActive?: boolean;
|
|
319
|
+
extraWhere?: Record<string, unknown>;
|
|
320
|
+
children?: SoftDeleteChildConfig[];
|
|
321
|
+
};
|
|
322
|
+
type SoftDeleteConfig = {
|
|
323
|
+
children?: SoftDeleteChildConfig[];
|
|
311
324
|
};
|
|
312
325
|
interface UpdateConfigByCodeInput extends Pick<DynamicShortCode, "config"> {
|
|
313
326
|
shortCode: string;
|
|
@@ -611,6 +624,9 @@ type ApprovalAction = {
|
|
|
611
624
|
comment: string | null;
|
|
612
625
|
actedAt: Date;
|
|
613
626
|
};
|
|
627
|
+
type ApprovalActionWithInstance = ApprovalAction & {
|
|
628
|
+
approvalInstance: ApprovalInstance | null;
|
|
629
|
+
};
|
|
614
630
|
type LevelReadyEvt = {
|
|
615
631
|
instanceId: number;
|
|
616
632
|
subjectType: string;
|
|
@@ -820,7 +836,7 @@ declare class ApprovalService {
|
|
|
820
836
|
private emitEvents;
|
|
821
837
|
private assertPermission;
|
|
822
838
|
getAllApprovalFlow(input: GetMyApprovalFlow): Promise<PaginatedResponse<ApprovalInstanceByUser>>;
|
|
823
|
-
getApprovalActDetailsBySubjectId(subjectId: number, subjectType: string, service: string): Promise<
|
|
839
|
+
getApprovalActDetailsBySubjectId(subjectId: number, subjectType: string, service: string): Promise<ApprovalActionWithInstance[]>;
|
|
824
840
|
commonStatusUpdate(config: IParentConfigJSON, data: ICommonApprovalUpdate): Promise<void>;
|
|
825
841
|
commonParentChildUpdate(config: IParentConfigJSON, childConfig: IChildConfigJSON | null, inst: EventInstance): Promise<void>;
|
|
826
842
|
}
|
|
@@ -1036,4 +1052,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
1036
1052
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
1037
1053
|
}
|
|
1038
1054
|
|
|
1039
|
-
export { type ActInput, ActionMode, type ApprovalAction, type ApprovalActionDto, type ApprovalDeps, type ApprovalFlow, type ApprovalInstance, type ApprovalInstanceByUser, ApprovalService, ApprovalStatus, type ApprovalStep, type ApproverMapping, type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type BulkAtomicResult, type BulkConfig, type BulkConflictConfig, type BulkOnConflict, type CacheAdapter, type CalculationRes, type ColValue, type CommonApproveReq, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonGetApprovalActionReq, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateApprovalFlow, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeepMerge, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type EventInstance, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedMap, type FixedSearchRequest, type FixedSearchRequestService, FlowType, type FlowWithSelectedStepResponse, type FlowWithStepsResponse, type GetMyApprovalFlow, type GetPendingApprovalReq, type Helpers, type IApprovalStep, type IChildConfigData, type IChildConfigJSON, type ICommonApprovalUpdate, type IParentConfigData, type IParentConfigJSON, type ImportExcel, type ImportExcelRequestService, type LevelDoneEvt, type LevelReadyEvt, type LockUnlockParams, type LockUnlockRequestRepository, type LogicNode, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type NotificationEvent, type Op, type PaginatedResponse, type PathToSelectWithSelect, type PathValue, type PathsToSelectWithSelect, type Presence, type PrismaTransactionClient, type RawFlowWithSelectedStepResponse, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SourcePath, type StartFlowReq, type StepType, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateApprovalFlow, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, approvalRepository, commonService, convertArrayPatternToEachBlocksGeneric, customOmit, findDifferences, formatDatesDeep, fromTimestampToSqlDatetime, generateHashForAuth, generateMd5, getDynamicValue, getNestedValue, getNestedValueV2, getPattern, interpolate, objectTo2DArray, renderEmailTemplate, renderTemplate, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
|
1055
|
+
export { type ActInput, ActionMode, type ApprovalAction, type ApprovalActionDto, type ApprovalActionWithInstance, type ApprovalDeps, type ApprovalFlow, type ApprovalInstance, type ApprovalInstanceByUser, ApprovalService, ApprovalStatus, type ApprovalStep, type ApproverMapping, type AuditContext, type AuditContextProvider, AuditCore, type AuditLogPayload, AuditLogger, AuditProxy, type BulkAtomicResult, type BulkConfig, type BulkConflictConfig, type BulkOnConflict, type CacheAdapter, type CalculationRes, type ColValue, type CommonApproveReq, type CommonCreateRequestRepository, type CommonExcelRequest, type CommonFilterRequest, type CommonFilterWithDate, type CommonGetApprovalActionReq, type CommonServiceResponse, type CommonUpdateRequestRepository, type Config, type Context, type CreateApprovalFlow, type CreateUINConfigRequest, type CrudContext, type CrudDelegate, type DataType, type DeepMerge, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DtoFromMapping, type DtoNullOnMissing, type DynamicCreateInput, type DynamicCrudConfig, type DynamicShortCode, type DynamicUpdateInput, type EmitPayload, type EmployeeCache, type EventInstance, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FieldConfig, type FieldRules, type FieldType, type FixedMap, type FixedSearchRequest, type FixedSearchRequestService, FlowType, type FlowWithSelectedStepResponse, type FlowWithStepsResponse, type GetMyApprovalFlow, type GetPendingApprovalReq, type Helpers, type IApprovalStep, type IChildConfigData, type IChildConfigJSON, type ICommonApprovalUpdate, type IParentConfigData, type IParentConfigJSON, type ImportExcel, type ImportExcelRequestService, type LevelDoneEvt, type LevelReadyEvt, type LockUnlockParams, type LockUnlockRequestRepository, type LogicNode, type Mapper, type MergeAll, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, NotificationEmitter, type NotificationEvent, type Op, type PaginatedResponse, type PathToSelectWithSelect, type PathValue, type PathsToSelectWithSelect, type Presence, type PrismaTransactionClient, type RawFlowWithSelectedStepResponse, type Recipient, type RelationConfig, type RelationStrategy, type RelationWriteConfig, type SearchRequest, type SearchRequestService, type ServiceCacheAdapter, type SingleValidationMapping, type SoftDeleteChildConfig, type SoftDeleteConfig, type SourcePath, type StartFlowReq, type StepType, type Store, type ToggleActive, type TxClient, type UINConfigDTO, type UINPreviewRequest, type UINSegment, type UINSegmentType, type UIN_RESET_POLICY, type UinDeps, type UnionToIntersection, type UniqueConfig, type UpdateApprovalFlow, type UpdateConfigByCodeInput, type UpdateStatusRequestRepository, type UpdateUINConfigRequest, type ValidationErrorItem, approvalRepository, commonService, convertArrayPatternToEachBlocksGeneric, customOmit, findDifferences, formatDatesDeep, fromTimestampToSqlDatetime, generateHashForAuth, generateMd5, getDynamicValue, getNestedValue, getNestedValueV2, getPattern, interpolate, objectTo2DArray, renderEmailTemplate, renderTemplate, toNumberOrNull, toUINConfigDTO, uinConfigService, type updateStatusParams };
|
package/dist/index.js
CHANGED
|
@@ -605,24 +605,99 @@ var commonRepository = (serviceDeps) => {
|
|
|
605
605
|
logger.info("exiting::commonFetch::repository");
|
|
606
606
|
return results;
|
|
607
607
|
},
|
|
608
|
+
async softDeleteChildren({
|
|
609
|
+
tx,
|
|
610
|
+
parentId,
|
|
611
|
+
children,
|
|
612
|
+
deletedBy,
|
|
613
|
+
deletedAt
|
|
614
|
+
}) {
|
|
615
|
+
for (const child of children) {
|
|
616
|
+
const childModel = tx[child.tableName];
|
|
617
|
+
if (!childModel) {
|
|
618
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
619
|
+
}
|
|
620
|
+
const primaryKey = child.primaryKey ?? "id";
|
|
621
|
+
const activeField = child.activeField ?? "isActive";
|
|
622
|
+
const where = {
|
|
623
|
+
[child.foreignKey]: parentId,
|
|
624
|
+
...child.onlyActive === false ? {} : { [activeField]: true },
|
|
625
|
+
...child.extraWhere ?? {}
|
|
626
|
+
};
|
|
627
|
+
if (child.children?.length) {
|
|
628
|
+
const childRows = await childModel.findMany({
|
|
629
|
+
where,
|
|
630
|
+
select: {
|
|
631
|
+
[primaryKey]: true
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
for (const childRow of childRows) {
|
|
635
|
+
await this.softDeleteChildren({
|
|
636
|
+
tx,
|
|
637
|
+
parentId: childRow[primaryKey],
|
|
638
|
+
children: child.children,
|
|
639
|
+
deletedBy,
|
|
640
|
+
deletedAt
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
await childModel.updateMany({
|
|
645
|
+
where,
|
|
646
|
+
data: {
|
|
647
|
+
isActive: false,
|
|
648
|
+
deletedBy,
|
|
649
|
+
deletedAt
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
async getSoftDeleteConfig(deleteConfig) {
|
|
655
|
+
if (!deleteConfig) {
|
|
656
|
+
return {};
|
|
657
|
+
}
|
|
658
|
+
if (typeof deleteConfig === "string") {
|
|
659
|
+
try {
|
|
660
|
+
return JSON.parse(deleteConfig);
|
|
661
|
+
} catch {
|
|
662
|
+
throw new ErrorHandler(400, "Invalid delete config JSON");
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return deleteConfig;
|
|
666
|
+
},
|
|
608
667
|
async commonDelete({ id, shortCodeData }) {
|
|
609
668
|
logger.info("entering::commonDelete::repository");
|
|
610
669
|
const tableName = shortCodeData.tableName;
|
|
611
670
|
const store = requestStorage.getStore();
|
|
671
|
+
const currentUser = store?.user?.id;
|
|
612
672
|
const model = db[tableName];
|
|
613
673
|
if (!model) {
|
|
614
674
|
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
615
675
|
}
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
676
|
+
const deletedAt = /* @__PURE__ */ new Date();
|
|
677
|
+
const deleteConfig = await this.getSoftDeleteConfig(shortCodeData.deleteConfig);
|
|
678
|
+
const children = deleteConfig.children ?? [];
|
|
679
|
+
const result = await db.$transaction(async (tx) => {
|
|
680
|
+
if (children.length) {
|
|
681
|
+
await this.softDeleteChildren({
|
|
682
|
+
tx,
|
|
683
|
+
parentId: id,
|
|
684
|
+
children,
|
|
685
|
+
deletedBy: currentUser,
|
|
686
|
+
deletedAt
|
|
687
|
+
});
|
|
622
688
|
}
|
|
689
|
+
const deletedParent = await tx[tableName].update({
|
|
690
|
+
where: { id },
|
|
691
|
+
data: {
|
|
692
|
+
isActive: false,
|
|
693
|
+
deletedBy: currentUser,
|
|
694
|
+
deletedAt
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
return deletedParent;
|
|
623
698
|
});
|
|
624
699
|
logger.info("exiting::commonDelete::repository");
|
|
625
|
-
return
|
|
700
|
+
return result;
|
|
626
701
|
},
|
|
627
702
|
async commonUpdateStatus({ id, shortCodeData, status }) {
|
|
628
703
|
logger.info("entering::commonUpdateStatus::repository");
|
|
@@ -2317,6 +2392,21 @@ var commonService = (serviceDeps) => {
|
|
|
2317
2392
|
};
|
|
2318
2393
|
};
|
|
2319
2394
|
|
|
2395
|
+
// src/config/axiosClient.config.ts
|
|
2396
|
+
var import_axios2 = __toESM(require("axios"));
|
|
2397
|
+
var externalInterceptor = () => {
|
|
2398
|
+
const randomNumber = Math.floor(Math.random() * 1e6);
|
|
2399
|
+
const hash = generateHashForAuth(randomNumber.toString());
|
|
2400
|
+
return import_axios2.default.create({
|
|
2401
|
+
headers: {
|
|
2402
|
+
"Content-Type": "application/json",
|
|
2403
|
+
"client-key": hash,
|
|
2404
|
+
"client-id": randomNumber.toString()
|
|
2405
|
+
},
|
|
2406
|
+
validateStatus: () => true
|
|
2407
|
+
});
|
|
2408
|
+
};
|
|
2409
|
+
|
|
2320
2410
|
// src/types/approval.type.ts
|
|
2321
2411
|
var ApprovalStatus = /* @__PURE__ */ ((ApprovalStatus2) => {
|
|
2322
2412
|
ApprovalStatus2["PENDING"] = "PENDING";
|
|
@@ -2580,21 +2670,6 @@ var approvalRepository = (deps) => {
|
|
|
2580
2670
|
};
|
|
2581
2671
|
};
|
|
2582
2672
|
|
|
2583
|
-
// src/config/axiosClient.config.ts
|
|
2584
|
-
var import_axios2 = __toESM(require("axios"));
|
|
2585
|
-
var externalInterceptor = () => {
|
|
2586
|
-
const randomNumber = Math.floor(Math.random() * 1e6);
|
|
2587
|
-
const hash = generateHashForAuth(randomNumber.toString());
|
|
2588
|
-
return import_axios2.default.create({
|
|
2589
|
-
headers: {
|
|
2590
|
-
"Content-Type": "application/json",
|
|
2591
|
-
"client-key": hash,
|
|
2592
|
-
"client-id": randomNumber.toString()
|
|
2593
|
-
},
|
|
2594
|
-
validateStatus: () => true
|
|
2595
|
-
});
|
|
2596
|
-
};
|
|
2597
|
-
|
|
2598
2673
|
// src/services/approval.service.ts
|
|
2599
2674
|
var ApprovalService = class {
|
|
2600
2675
|
constructor(deps) {
|
package/dist/index.mjs
CHANGED
|
@@ -542,24 +542,99 @@ var commonRepository = (serviceDeps) => {
|
|
|
542
542
|
logger.info("exiting::commonFetch::repository");
|
|
543
543
|
return results;
|
|
544
544
|
},
|
|
545
|
+
async softDeleteChildren({
|
|
546
|
+
tx,
|
|
547
|
+
parentId,
|
|
548
|
+
children,
|
|
549
|
+
deletedBy,
|
|
550
|
+
deletedAt
|
|
551
|
+
}) {
|
|
552
|
+
for (const child of children) {
|
|
553
|
+
const childModel = tx[child.tableName];
|
|
554
|
+
if (!childModel) {
|
|
555
|
+
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
556
|
+
}
|
|
557
|
+
const primaryKey = child.primaryKey ?? "id";
|
|
558
|
+
const activeField = child.activeField ?? "isActive";
|
|
559
|
+
const where = {
|
|
560
|
+
[child.foreignKey]: parentId,
|
|
561
|
+
...child.onlyActive === false ? {} : { [activeField]: true },
|
|
562
|
+
...child.extraWhere ?? {}
|
|
563
|
+
};
|
|
564
|
+
if (child.children?.length) {
|
|
565
|
+
const childRows = await childModel.findMany({
|
|
566
|
+
where,
|
|
567
|
+
select: {
|
|
568
|
+
[primaryKey]: true
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
for (const childRow of childRows) {
|
|
572
|
+
await this.softDeleteChildren({
|
|
573
|
+
tx,
|
|
574
|
+
parentId: childRow[primaryKey],
|
|
575
|
+
children: child.children,
|
|
576
|
+
deletedBy,
|
|
577
|
+
deletedAt
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
await childModel.updateMany({
|
|
582
|
+
where,
|
|
583
|
+
data: {
|
|
584
|
+
isActive: false,
|
|
585
|
+
deletedBy,
|
|
586
|
+
deletedAt
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
},
|
|
591
|
+
async getSoftDeleteConfig(deleteConfig) {
|
|
592
|
+
if (!deleteConfig) {
|
|
593
|
+
return {};
|
|
594
|
+
}
|
|
595
|
+
if (typeof deleteConfig === "string") {
|
|
596
|
+
try {
|
|
597
|
+
return JSON.parse(deleteConfig);
|
|
598
|
+
} catch {
|
|
599
|
+
throw new ErrorHandler(400, "Invalid delete config JSON");
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return deleteConfig;
|
|
603
|
+
},
|
|
545
604
|
async commonDelete({ id, shortCodeData }) {
|
|
546
605
|
logger.info("entering::commonDelete::repository");
|
|
547
606
|
const tableName = shortCodeData.tableName;
|
|
548
607
|
const store = requestStorage.getStore();
|
|
608
|
+
const currentUser = store?.user?.id;
|
|
549
609
|
const model = db[tableName];
|
|
550
610
|
if (!model) {
|
|
551
611
|
throw new ErrorHandler(400, generateErrorMessage("INVALID_TABLE"));
|
|
552
612
|
}
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
613
|
+
const deletedAt = /* @__PURE__ */ new Date();
|
|
614
|
+
const deleteConfig = await this.getSoftDeleteConfig(shortCodeData.deleteConfig);
|
|
615
|
+
const children = deleteConfig.children ?? [];
|
|
616
|
+
const result = await db.$transaction(async (tx) => {
|
|
617
|
+
if (children.length) {
|
|
618
|
+
await this.softDeleteChildren({
|
|
619
|
+
tx,
|
|
620
|
+
parentId: id,
|
|
621
|
+
children,
|
|
622
|
+
deletedBy: currentUser,
|
|
623
|
+
deletedAt
|
|
624
|
+
});
|
|
559
625
|
}
|
|
626
|
+
const deletedParent = await tx[tableName].update({
|
|
627
|
+
where: { id },
|
|
628
|
+
data: {
|
|
629
|
+
isActive: false,
|
|
630
|
+
deletedBy: currentUser,
|
|
631
|
+
deletedAt
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
return deletedParent;
|
|
560
635
|
});
|
|
561
636
|
logger.info("exiting::commonDelete::repository");
|
|
562
|
-
return
|
|
637
|
+
return result;
|
|
563
638
|
},
|
|
564
639
|
async commonUpdateStatus({ id, shortCodeData, status }) {
|
|
565
640
|
logger.info("entering::commonUpdateStatus::repository");
|
|
@@ -2254,6 +2329,21 @@ var commonService = (serviceDeps) => {
|
|
|
2254
2329
|
};
|
|
2255
2330
|
};
|
|
2256
2331
|
|
|
2332
|
+
// src/config/axiosClient.config.ts
|
|
2333
|
+
import axios2 from "axios";
|
|
2334
|
+
var externalInterceptor = () => {
|
|
2335
|
+
const randomNumber = Math.floor(Math.random() * 1e6);
|
|
2336
|
+
const hash = generateHashForAuth(randomNumber.toString());
|
|
2337
|
+
return axios2.create({
|
|
2338
|
+
headers: {
|
|
2339
|
+
"Content-Type": "application/json",
|
|
2340
|
+
"client-key": hash,
|
|
2341
|
+
"client-id": randomNumber.toString()
|
|
2342
|
+
},
|
|
2343
|
+
validateStatus: () => true
|
|
2344
|
+
});
|
|
2345
|
+
};
|
|
2346
|
+
|
|
2257
2347
|
// src/types/approval.type.ts
|
|
2258
2348
|
var ApprovalStatus = /* @__PURE__ */ ((ApprovalStatus2) => {
|
|
2259
2349
|
ApprovalStatus2["PENDING"] = "PENDING";
|
|
@@ -2517,21 +2607,6 @@ var approvalRepository = (deps) => {
|
|
|
2517
2607
|
};
|
|
2518
2608
|
};
|
|
2519
2609
|
|
|
2520
|
-
// src/config/axiosClient.config.ts
|
|
2521
|
-
import axios2 from "axios";
|
|
2522
|
-
var externalInterceptor = () => {
|
|
2523
|
-
const randomNumber = Math.floor(Math.random() * 1e6);
|
|
2524
|
-
const hash = generateHashForAuth(randomNumber.toString());
|
|
2525
|
-
return axios2.create({
|
|
2526
|
-
headers: {
|
|
2527
|
-
"Content-Type": "application/json",
|
|
2528
|
-
"client-key": hash,
|
|
2529
|
-
"client-id": randomNumber.toString()
|
|
2530
|
-
},
|
|
2531
|
-
validateStatus: () => true
|
|
2532
|
-
});
|
|
2533
|
-
};
|
|
2534
|
-
|
|
2535
2610
|
// src/services/approval.service.ts
|
|
2536
2611
|
var ApprovalService = class {
|
|
2537
2612
|
constructor(deps) {
|