แก้ วันที่ 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,
@ -37,77 +36,22 @@ export class ProfileDutyController extends Controller {
}
const lists = await this.dutyRepository.find({
where: { profileId: profile.id },
select: [
"id",
"dateStart",
"dateEnd",
"reference",
"detail",
"refCommandNo",
"refCommandDate",
],
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@Get("{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
dateStart: "2024-03-12T10:09:47.000Z",
dateEnd: "string",
reference: "string",
detail: "string",
refCommandNo: "string",
refCommandDate: "2024-03-12T10:09:47.000Z",
},
],
})
public async getDuty(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const lists = await this.dutyRepository.find({
where: { profileId: profileId },
select: [
"id",
"dateStart",
"dateEnd",
"reference",
"detail",
"refCommandNo",
"refCommandDate",
],
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@Get("history/{dutyId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
dateStart: "2024-03-12T10:09:47.000Z",
dateEnd: "string",
reference: "string",
detail: "string",
refCommandNo: "string",
refCommandDate: "2024-03-12T10:09:47.000Z",
},
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
dateStart: "2024-03-12T10:09:47.000Z",
dateEnd: "string",
reference: "string",
detail: "string",
refCommandNo: "string",
refCommandDate: "2024-03-12T10:09:47.000Z",
},
],
})
public async dutyHistory(@Path() dutyId: string, @Request() req: RequestWithUser) {
const _record = await this.dutyRepository.findOneBy({ id: dutyId });
if (_record) {
@ -115,17 +59,6 @@ export class ProfileDutyController extends Controller {
}
const record = await this.dutyHistoryRepository.find({
where: { profileDutyId: dutyId },
select: [
"id",
"dateStart",
"dateEnd",
"reference",
"detail",
"refCommandNo",
"refCommandDate",
"lastUpdateFullName",
"lastUpdatedAt",
],
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
@ -150,6 +83,8 @@ export class ProfileDutyController 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 });
@ -176,15 +111,18 @@ export class ProfileDutyController extends Controller {
const history = new ProfileDutyHistory();
Object.assign(record, body);
Object.assign(history, body);
Object.assign(history, { ...body, id: undefined });
history.profileDutyId = dutyId;
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.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]);