แก้ วันที่ update

This commit is contained in:
kittapath 2024-08-30 18:02:34 +07:00
parent 6d36c9b05f
commit 218886b3f4
83 changed files with 1671 additions and 3483 deletions

View file

@ -2,7 +2,6 @@ import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
@ -48,41 +47,12 @@ export class ProfileInsigniaController extends Controller {
},
},
where: { profileId: profile.id },
order: { createdAt: "ASC" },
});
return new HttpSuccess(record);
}
@Get("{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "c9d4dd52-25f5-491a-852d-28bfe00d66cb",
createdAt: "2024-03-12T03:05:09.393Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-12T03:05:09.393Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
year: 0,
no: "string",
volume: "string",
section: "string",
page: "string",
receiveDate: "2024-03-12T10:05:02.000Z",
insigniaId: "string",
insigniaType: "string",
dateAnnounce: "2024-03-12T10:05:02.000Z",
issue: "string",
volumeNo: "string",
refCommandDate: "2024-03-12T10:05:02.000Z",
refCommandNo: "string",
note: "string",
},
],
})
public async getInsignia(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const record = await this.insigniaRepo.find({
@ -92,70 +62,17 @@ export class ProfileInsigniaController extends Controller {
},
},
where: { profileId },
order: { createdAt: "ASC" },
});
return new HttpSuccess(record);
}
@Get("history/{InsigniaId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "c363d13c-88bd-4954-adf5-70d3f5ca9c30",
createdAt: "2024-03-12T03:06:31.062Z",
createdUserId: "00000000-0000-0000-0000-000000000000",
lastUpdatedAt: "2024-03-12T03:06:31.062Z",
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
year: 0,
no: "no",
volume: "volume",
section: "section",
page: "page",
receiveDate: "2024-03-12T10:05:44.000Z",
insigniaId: "insigniaId",
insigniaType: "insigniaType",
dateAnnounce: "2024-03-12T10:05:44.000Z",
issue: "string",
volumeNo: "volumeNo",
refCommandDate: "2024-03-12T10:05:44.000Z",
refCommandNo: "refCommandNo",
note: "string",
profileInsigniaId: "c9d4dd52-25f5-491a-852d-28bfe00d66cb",
},
{
id: "c9d4dd52-25f5-491a-852d-28bfe00d66cb",
createdAt: "2024-03-12T03:05:09.393Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-12T03:09:04.905Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
year: 0,
no: "string",
volume: "string",
section: "string",
page: "string",
receiveDate: "2024-03-12T10:05:02.000Z",
insigniaId: "string",
insigniaType: "string",
dateAnnounce: "2024-03-12T10:05:02.000Z",
issue: "string",
volumeNo: "string",
refCommandDate: "2024-03-12T10:05:02.000Z",
refCommandNo: "string",
note: "string",
profileInsigniaId: "c9d4dd52-25f5-491a-852d-28bfe00d66cb",
},
],
})
public async getInsigniaHistory(@Path() InsigniaId: string, @Request() req: RequestWithUser) {
const _record = await this.insigniaRepo.findOneBy({ id: InsigniaId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
const _record = await this.insigniaRepo.findOneBy({ id: InsigniaId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
const record = await this.insigniaHistoryRepo.find({
relations: {
insignia: {
@ -165,6 +82,7 @@ export class ProfileInsigniaController extends Controller {
where: {
profileInsigniaId: InsigniaId,
},
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
}
@ -174,7 +92,7 @@ export class ProfileInsigniaController extends Controller {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
@ -195,6 +113,8 @@ export class ProfileInsigniaController extends Controller {
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
@ -228,15 +148,18 @@ export class ProfileInsigniaController extends Controller {
const history = new ProfileInsigniaHistory();
Object.assign(record, body);
Object.assign(history, body);
Object.assign(history, { ...body, id: undefined });
history.profileInsigniaId = insigniaId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]);
@ -247,14 +170,18 @@ export class ProfileInsigniaController extends Controller {
public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) {
const _record = await this.insigniaRepo.findOneBy({ id: insigniaId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", _record.profileId);
await new permission().PermissionOrgUserDelete(
req,
"SYS_REGISTRY_OFFICER",
_record.profileId,
);
}
await this.insigniaHistoryRepo.delete({
profileInsigniaId: insigniaId,
});
const result = await this.insigniaRepo.delete({ id: insigniaId });
if (result.affected == undefined || result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
@ -291,6 +218,8 @@ export class ProfileInsigniaController extends Controller {
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });