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

@ -191,6 +191,45 @@ export class ProfileChangeNameController extends Controller {
return new HttpSuccess();
}
/**
* API -
* @summary API -
* @param trainingId -
*/
@Patch("update-delete/{changeNameId}")
public async updateIsDeleted(
@Request() req: RequestWithUser,
@Path() changeNameId: string,
) {
const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
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 ProfileChangeNameHistory();
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.profileChangeNameId = changeNameId;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = now;
await Promise.all([
this.changeNameRepository.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.changeNameHistoryRepository.save(history, { data: req }),
]);
return new HttpSuccess();
}
@Delete("{changeNameId}")
public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) {
const _record = await this.changeNameRepository.findOneBy({ id: changeNameId });