av6-core 2.0.2 → 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 +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +82 -7
- package/dist/index.mjs +82 -7
- 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;
|
|
@@ -1039,4 +1052,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
1039
1052
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
1040
1053
|
}
|
|
1041
1054
|
|
|
1042
|
-
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 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;
|
|
@@ -1039,4 +1052,4 @@ declare class AuditProxy<Module extends string = "OPD" | "PROCEDURE" | "GENERAL_
|
|
|
1039
1052
|
createAuditedService<T extends object>(serviceName: string, service: T): T;
|
|
1040
1053
|
}
|
|
1041
1054
|
|
|
1042
|
-
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 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");
|
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");
|