no message
This commit is contained in:
parent
59607aafd1
commit
a9f0458f1b
6 changed files with 190 additions and 5 deletions
180
src/controllers/ProfileCertificateEmployeeController.ts
Normal file
180
src/controllers/ProfileCertificateEmployeeController.ts
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateProfileCertificate,
|
||||
ProfileCertificate,
|
||||
UpdateProfileCertificate,
|
||||
} from "../entities/ProfileCertificate";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
|
||||
@Route("api/v1/org/profile-employee/certificate")
|
||||
@Tags("ProfileEmployeeCertificate")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileCertificateEmployeeController extends Controller {
|
||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||
private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
|
||||
private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory);
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
@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: "สาวิตรี ศรีสมัย",
|
||||
profileEmployeeId: "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() profileEmployeeId: string) {
|
||||
const record = await this.certificateRepo.findBy({ profileEmployeeId });
|
||||
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) {
|
||||
const record = await this.certificateHistoryRepo.findBy({
|
||||
profileCertificateId: certificateId,
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newCertificate(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileCertificate,
|
||||
) {
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileCertificate();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.certificateRepo.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{certificateId}")
|
||||
public async editCertificate(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileCertificate,
|
||||
@Path() certificateId: string,
|
||||
) {
|
||||
const record = await this.certificateRepo.findOneBy({ id: certificateId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileCertificateId = certificateId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(record),
|
||||
this.certificateHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{certificateId}")
|
||||
public async deleteCertificate(@Path() certificateId: string) {
|
||||
await this.certificateHistoryRepo.delete({
|
||||
profileCertificateId: certificateId,
|
||||
});
|
||||
|
||||
const certificateResult = await this.certificateRepo.delete({
|
||||
id: certificateId,
|
||||
});
|
||||
|
||||
if (certificateResult.affected && certificateResult.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -102,7 +102,8 @@ export class ProfileAssessment extends EntityBase {
|
|||
}
|
||||
|
||||
export class CreateProfileAssessment {
|
||||
profileId: string | null;
|
||||
profileId?: string | null;
|
||||
profileEmployeeId?: string | null;
|
||||
name: string | null;
|
||||
date: Date | null;
|
||||
point1: number | null;
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ export class ProfileCertificate extends EntityBase {
|
|||
}
|
||||
|
||||
export class CreateProfileCertificate {
|
||||
profileId: string | null;
|
||||
profileId?: string | null;
|
||||
profileEmployeeId?: string | null;
|
||||
expireDate: Date | null;
|
||||
issueDate: Date | null;
|
||||
certificateNo: string | null;
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@ export class ProfileHonor extends EntityBase {
|
|||
}
|
||||
|
||||
export class CreateProfileHonor {
|
||||
profileId: string | null;
|
||||
profileId?: string | null;
|
||||
profileEmployeeId?: string | null;
|
||||
detail: string | null;
|
||||
issueDate: Date | null;
|
||||
issuer: string | null;
|
||||
|
|
|
|||
|
|
@ -142,7 +142,8 @@ export class ProfileInsignia extends EntityBase {
|
|||
}
|
||||
|
||||
export class CreateProfileInsignia {
|
||||
profileId: string | null;
|
||||
profileId?: string | null;
|
||||
profileEmployeeId?: string | null;
|
||||
year: number;
|
||||
no: string | null;
|
||||
volume: string | null;
|
||||
|
|
|
|||
|
|
@ -124,7 +124,8 @@ export class ProfileTraining extends EntityBase {
|
|||
}
|
||||
|
||||
export class CreateProfileTraining {
|
||||
profileId: string | null;
|
||||
profileId?: string | null;
|
||||
profileEmployeeId?: string | null;
|
||||
startDate: Date | null;
|
||||
endDate: Date | null;
|
||||
numberOrder: string | null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue