แก้ วันที่ 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,61 +36,27 @@ export class ProfileNopaidController extends Controller {
}
const lists = await this.nopaidRepository.find({
where: { profileId: profile.id },
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@Get("{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
date: "2024-03-12T10:09:47.000Z",
reference: "string",
detail: "string",
refCommandNo: "string",
refCommandDate: "2024-03-12T10:09:47.000Z",
},
],
})
public async getNopaid(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const lists = await this.nopaidRepository.find({
where: { profileId },
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@Get("history/{nopaidId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
date: "2024-03-12T10:09:47.000Z",
reference: "string",
detail: "string",
refCommandNo: "string",
refCommandDate: "2024-03-12T10:09:47.000Z",
},
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
date: "2024-03-12T10:09:47.000Z",
reference: "string",
detail: "string",
refCommandNo: "string",
refCommandDate: "2024-03-12T10:09:47.000Z",
},
],
})
public async nopaidHistory(@Path() nopaidId: string, @Request() req: RequestWithUser) {
const _record = await this.nopaidRepository.findOneBy({ id: nopaidId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
};
const _record = await this.nopaidRepository.findOneBy({ id: nopaidId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
const record = await this.nopaidHistoryRepository.find({
where: { profileNopaidId: nopaidId },
order: { createdAt: "DESC" },
@ -104,7 +69,7 @@ export class ProfileNopaidController extends Controller {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepository.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
@ -118,6 +83,8 @@ export class ProfileNopaidController 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 });
@ -144,15 +111,18 @@ export class ProfileNopaidController extends Controller {
const history = new ProfileNopaidHistory();
Object.assign(record, body);
Object.assign(history, body);
Object.assign(history, { ...body, id: undefined });
history.profileNopaidId = nopaidId;
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.nopaidRepository.save(record),
@ -166,7 +136,11 @@ export class ProfileNopaidController extends Controller {
public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) {
const _record = await this.nopaidRepository.findOneBy({ id: nopaidId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", _record.profileId);
await new permission().PermissionOrgUserDelete(
req,
"SYS_REGISTRY_OFFICER",
_record.profileId,
);
}
await this.nopaidHistoryRepository.delete({
profileNopaidId: nopaidId,