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

@ -150,6 +150,45 @@ export class ProfileDutyController extends Controller {
return new HttpSuccess();
}
/**
* API
* @summary API
* @param dutyId
*/
@Patch("update-delete/{dutyId}")
public async updateIsDeleted(
@Request() req: RequestWithUser,
@Path() dutyId: string,
) {
const record = await this.dutyRepository.findOneBy({ id: dutyId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (record.isDeleted === true) {
return new HttpSuccess();
}
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
const history = new ProfileDutyHistory();
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.profileDutyId = dutyId;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = now;
await Promise.all([
this.dutyRepository.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.dutyHistoryRepository.save(history, { data: req }),
]);
return new HttpSuccess();
}
@Delete("{dutyId}")
public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) {
const _record = await this.dutyRepository.findOneBy({ id: dutyId });