แก้ วันที่ update
This commit is contained in:
parent
6d36c9b05f
commit
218886b3f4
83 changed files with 1671 additions and 3483 deletions
|
|
@ -2,7 +2,6 @@ import {
|
|||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
|
|
@ -41,85 +40,34 @@ export class ProfileCertificateController extends Controller {
|
|||
}
|
||||
const record = await this.certificateRepo.find({
|
||||
where: { profileId: profile.id },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("{profileId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "e1ef9c3d-079a-40d8-8332-664c3e9a5a70",
|
||||
createdAt: "2024-03-12T03:02:27.532Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T03:02:27.532Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
expireDate: "2024-03-12T10:01:48.000Z",
|
||||
issueDate: "2024-03-12T10:01:48.000Z",
|
||||
certificateNo: "string",
|
||||
certificateType: "string",
|
||||
issuer: "string",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getCertificate(@Path() profileId: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
|
||||
const record = await this.certificateRepo.findBy({ profileId });
|
||||
const record = await this.certificateRepo.find({
|
||||
where: { profileId: profileId },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("history/{certificateId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "c0ecf986-b290-44ca-b45e-f4448cdd34dd",
|
||||
createdAt: "2024-03-12T03:03:30.169Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T03:03:30.169Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
expireDate: "2024-03-12T10:03:05.000Z",
|
||||
issueDate: "2024-03-12T10:03:05.000Z",
|
||||
certificateNo: "no",
|
||||
certificateType: "type",
|
||||
issuer: "issuer",
|
||||
profileCertificateId: "e1ef9c3d-079a-40d8-8332-664c3e9a5a70",
|
||||
},
|
||||
{
|
||||
id: "dc4c2800-5fc5-4ec3-b19a-c4a27beac35f",
|
||||
createdAt: "2024-03-12T03:02:27.583Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T03:02:27.583Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "สาวิตรี ศรีสมัย",
|
||||
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||
expireDate: "2024-03-12T10:01:48.000Z",
|
||||
issueDate: "2024-03-12T10:01:48.000Z",
|
||||
certificateNo: "string",
|
||||
certificateType: "string",
|
||||
issuer: "string",
|
||||
profileCertificateId: "e1ef9c3d-079a-40d8-8332-664c3e9a5a70",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async certificateHistory(@Path() certificateId: string, @Request() req: RequestWithUser) {
|
||||
const _record = await this.certificateRepo.findOneBy({ id: certificateId });
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
|
||||
}
|
||||
const record = await this.certificateHistoryRepo.findBy({
|
||||
profileCertificateId: certificateId,
|
||||
const record = await this.certificateHistoryRepo.find({
|
||||
where: {
|
||||
profileCertificateId: certificateId,
|
||||
},
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
|
||||
}
|
||||
|
||||
@Post()
|
||||
|
|
@ -130,9 +78,9 @@ export class ProfileCertificateController 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 ดังกล่าว");
|
||||
}
|
||||
|
|
@ -145,6 +93,8 @@ export class ProfileCertificateController 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 });
|
||||
|
|
@ -167,19 +117,22 @@ export class ProfileCertificateController extends Controller {
|
|||
const record = await this.certificateRepo.findOneBy({ id: certificateId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, body);
|
||||
Object.assign(history, { ...body, id: undefined });
|
||||
|
||||
history.profileCertificateId = certificateId;
|
||||
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.certificateRepo.save(record),
|
||||
|
|
@ -191,10 +144,14 @@ export class ProfileCertificateController extends Controller {
|
|||
|
||||
@Delete("{certificateId}")
|
||||
public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) {
|
||||
const _record = await this.certificateRepo.findOneBy({ id: certificateId });
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", _record.profileId);
|
||||
}
|
||||
const _record = await this.certificateRepo.findOneBy({ id: certificateId });
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserDelete(
|
||||
req,
|
||||
"SYS_REGISTRY_OFFICER",
|
||||
_record.profileId,
|
||||
);
|
||||
}
|
||||
await this.certificateHistoryRepo.delete({
|
||||
profileCertificateId: certificateId,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue