migrate add column isDeleted + API ลบข้อมูลฝึกอบรม/ดูงาน + การพัฒนารายบุคคล idp + รักษาการ Task #2276, #2279, #2278
All checks were successful
Build & Deploy on Dev / build (push) Successful in 50s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 50s
This commit is contained in:
parent
bb18fed9ae
commit
30bf5ad9e3
12 changed files with 317 additions and 9 deletions
|
|
@ -28,6 +28,7 @@ import permission from "../interfaces/permission";
|
|||
import { DevelopmentProject } from "../entities/DevelopmentProject";
|
||||
import { In, Brackets } from "typeorm";
|
||||
import { DevelopmentRequest } from "../entities/DevelopmentRequest";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/development")
|
||||
@Tags("ProfileDevelopment")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -45,7 +46,7 @@ export class ProfileDevelopmentController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const lists = await this.developmentRepository.find({
|
||||
where: { profileId: profile.id },
|
||||
where: { profileId: profile.id, isDeleted: false },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
|
|
@ -66,7 +67,7 @@ export class ProfileDevelopmentController extends Controller {
|
|||
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
|
||||
let query = await AppDataSource.getRepository(ProfileDevelopment)
|
||||
.createQueryBuilder("profileDevelopment")
|
||||
.where({ profileId: profileId })
|
||||
.where({ profileId: profileId, isDeleted: false })
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
|
|
@ -329,6 +330,44 @@ export class ProfileDevelopmentController extends Controller {
|
|||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบข้อมูลการพัฒนารายบุคคล IDP
|
||||
* @summary API ลบข้อมูลการพัฒนารายบุคคล IDP
|
||||
* @param developmentId คีย์การพัฒนารายบุคคล IDP
|
||||
*/
|
||||
@Patch("update-delete/{developmentId}")
|
||||
public async updateIsDeletedTraining(
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() developmentId: string,
|
||||
) {
|
||||
const record = await this.developmentRepository.findOneBy({ id: developmentId });
|
||||
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 ProfileDevelopmentHistory();
|
||||
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.createdUserId = req.user.sub;
|
||||
history.createdFullName = req.user.name;
|
||||
history.createdAt = now;
|
||||
|
||||
await Promise.all([
|
||||
this.developmentRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.developmentHistoryRepository.save(history, { data: req }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{developmentId}")
|
||||
public async deleteDevelopment(@Path() developmentId: string, @Request() req: RequestWithUser) {
|
||||
const _record = await this.developmentRepository.findOneBy({ id: developmentId });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue