api soft delete

This commit is contained in:
harid 2026-02-16 10:30:15 +07:00
parent 17f7fc5d84
commit 9382482f06
44 changed files with 1717 additions and 0 deletions

View file

@ -174,6 +174,45 @@ export class ProfileCertificateEmployeeController extends Controller {
return new HttpSuccess();
}
/**
* API
* @summary API
* @param certificateId
*/
@Patch("update-delete/{certificateId}")
public async updateIsDeleted(
@Request() req: RequestWithUser,
@Path() certificateId: string,
) {
const record = await this.certificateRepo.findOneBy({ id: certificateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (record.isDeleted === true) {
return new HttpSuccess();
}
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId);
const before = structuredClone(record);
const history = new ProfileCertificateHistory();
const now = new Date();
record.isDeleted = true;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = now;
Object.assign(history, { ...record, id: undefined });
history.profileCertificateId = certificateId;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = now;
await Promise.all([
this.certificateRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.certificateHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess();
}
@Delete("{certificateId}")
public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) {
const _record = await this.certificateRepo.findOneBy({ id: certificateId });