Merge branch 'develop' into adiDev
This commit is contained in:
commit
f42f200c8a
14 changed files with 1608 additions and 13 deletions
196
src/controllers/ProfileEmployeeAssessmentsController.ts
Normal file
196
src/controllers/ProfileEmployeeAssessmentsController.ts
Normal file
|
|
@ -0,0 +1,196 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
Body,
|
||||||
|
Path,
|
||||||
|
Request,
|
||||||
|
SuccessResponse,
|
||||||
|
Response,
|
||||||
|
Get,
|
||||||
|
Query,
|
||||||
|
Patch,
|
||||||
|
Example,
|
||||||
|
} from "tsoa";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import {
|
||||||
|
CreateProfileEmployeeAssessment,
|
||||||
|
ProfileAssessment,
|
||||||
|
UpdateProfileAssessment,
|
||||||
|
} from "../entities/ProfileAssessment";
|
||||||
|
import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile-employee/assessments")
|
||||||
|
@Tags("ProfileEmployeeAssessments")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileEmployeeAssessmentsController extends Controller {
|
||||||
|
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment);
|
||||||
|
private profileAssessmentsHistoryRepository =
|
||||||
|
AppDataSource.getRepository(ProfileAssessmentHistory);
|
||||||
|
|
||||||
|
@Get("{profileEmployeeId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "f723bf42-a61c-4af4-ba8b-0e4ad0a89a80",
|
||||||
|
createdAt: "2024-03-12T20:56:45.986Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-03-12T20:56:45.986Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "test bar",
|
||||||
|
lastUpdateFullName: "test bar",
|
||||||
|
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||||
|
name: "สาวิตรี ศรีสมัย",
|
||||||
|
date: "2024-03-13T03:55:42.000Z",
|
||||||
|
point1: 0,
|
||||||
|
point1Total: 0,
|
||||||
|
point2: 0,
|
||||||
|
point2Total: 0,
|
||||||
|
pointSum: 0,
|
||||||
|
pointSumTotal: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async detailProfileAssessments(@Path() profileEmployeeId: string) {
|
||||||
|
const getProfileAssessments = await this.profileAssessmentsRepository.findBy({ profileEmployeeId });
|
||||||
|
if (!getProfileAssessments) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
return new HttpSuccess(getProfileAssessments);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("history/{assessmentId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "47b3e370-be05-4469-a34f-e4a04747f54e",
|
||||||
|
createdAt: "2024-03-12T20:59:39.774Z",
|
||||||
|
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||||
|
lastUpdatedAt: "2024-03-12T20:59:39.774Z",
|
||||||
|
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||||
|
createdFullName: "string",
|
||||||
|
lastUpdateFullName: "test bar",
|
||||||
|
name: "สาวิตรี ศรีสมัย",
|
||||||
|
date: "2024-03-13T03:55:42.000Z",
|
||||||
|
point1: 0,
|
||||||
|
point1Total: 0,
|
||||||
|
point2: 100,
|
||||||
|
point2Total: 100,
|
||||||
|
pointSum: 100,
|
||||||
|
pointSumTotal: 100,
|
||||||
|
profileAssessmentId: "f723bf42-a61c-4af4-ba8b-0e4ad0a89a80",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ecff89b1-9bef-49a9-83f5-8be3cecb8ca7",
|
||||||
|
createdAt: "2024-03-12T20:58:19.450Z",
|
||||||
|
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||||
|
lastUpdatedAt: "2024-03-12T20:58:19.450Z",
|
||||||
|
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||||
|
createdFullName: "string",
|
||||||
|
lastUpdateFullName: "test bar",
|
||||||
|
name: "สาวิตรี ศรีสมัย",
|
||||||
|
date: "2024-03-13T03:55:42.000Z",
|
||||||
|
point1: 50,
|
||||||
|
point1Total: 50,
|
||||||
|
point2: 100,
|
||||||
|
point2Total: 100,
|
||||||
|
pointSum: 150,
|
||||||
|
pointSumTotal: 150,
|
||||||
|
profileAssessmentId: "f723bf42-a61c-4af4-ba8b-0e4ad0a89a80",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async getProfileAssessmentsHistory(@Path() assessmentId: string) {
|
||||||
|
const record = await this.profileAssessmentsHistoryRepository.findBy({
|
||||||
|
profileAssessmentId: assessmentId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!record) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async profileAssessment(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: CreateProfileEmployeeAssessment,
|
||||||
|
) {
|
||||||
|
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 ProfileAssessment();
|
||||||
|
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.profileAssessmentsRepository.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{assessmentId}")
|
||||||
|
public async editProfileAssessment(
|
||||||
|
@Body() requestBody: UpdateProfileAssessment,
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Path() assessmentId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
const history = new ProfileAssessmentHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
Object.assign(record, requestBody);
|
||||||
|
|
||||||
|
history.profileAssessmentId = assessmentId;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
this.profileAssessmentsRepository.save(record),
|
||||||
|
this.profileAssessmentsHistoryRepository.save(history),
|
||||||
|
]);
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{assessmentId}")
|
||||||
|
public async deleteProfileAssessment(@Path() assessmentId: string) {
|
||||||
|
await this.profileAssessmentsHistoryRepository.delete({
|
||||||
|
profileAssessmentId: assessmentId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.profileAssessmentsRepository.delete({ id: assessmentId });
|
||||||
|
|
||||||
|
if (result.affected && result.affected <= 0)
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ import {
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import {
|
import {
|
||||||
CreateProfileCertificate,
|
CreateProfileEmployeeCertificate,
|
||||||
ProfileCertificate,
|
ProfileCertificate,
|
||||||
UpdateProfileCertificate,
|
UpdateProfileCertificate,
|
||||||
} from "../entities/ProfileCertificate";
|
} from "../entities/ProfileCertificate";
|
||||||
|
|
@ -28,7 +28,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
@Route("api/v1/org/profile-employee/certificate")
|
@Route("api/v1/org/profile-employee/certificate")
|
||||||
@Tags("ProfileEmployeeCertificate")
|
@Tags("ProfileEmployeeCertificate")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
export class ProfileCertificateEmployeeController extends Controller {
|
export class ProfileEmployeeCertificateController extends Controller {
|
||||||
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
|
private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
|
||||||
private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory);
|
private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory);
|
||||||
|
|
@ -107,7 +107,7 @@ export class ProfileCertificateEmployeeController extends Controller {
|
||||||
@Post()
|
@Post()
|
||||||
public async newCertificate(
|
public async newCertificate(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
@Body() body: CreateProfileCertificate,
|
@Body() body: CreateProfileEmployeeCertificate,
|
||||||
) {
|
) {
|
||||||
if (!body.profileEmployeeId) {
|
if (!body.profileEmployeeId) {
|
||||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||||
185
src/controllers/ProfileEmployeeDisciplineController.ts
Normal file
185
src/controllers/ProfileEmployeeDisciplineController.ts
Normal file
|
|
@ -0,0 +1,185 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Example,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Path,
|
||||||
|
Post,
|
||||||
|
Request,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import {
|
||||||
|
CreateProfileDiscipline,
|
||||||
|
ProfileDiscipline,
|
||||||
|
UpdateProfileDiscipline,
|
||||||
|
} from "../entities/ProfileDiscipline";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile-employee/discipline")
|
||||||
|
@Tags("ProfileDisciplineEmployee")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileDisciplineEmployeeController extends Controller {
|
||||||
|
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
|
||||||
|
private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory);
|
||||||
|
|
||||||
|
@Get("{profileId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||||
|
date: "2024-03-12T10:09:47.000Z",
|
||||||
|
level: "string",
|
||||||
|
detail: "string",
|
||||||
|
unStigma: "string",
|
||||||
|
refCommandNo: "string",
|
||||||
|
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async getDiscipline(@Path() profileId: string) {
|
||||||
|
const lists = await this.disciplineRepository.find({
|
||||||
|
where: { profileEmployeeId: profileId },
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"date",
|
||||||
|
"level",
|
||||||
|
"detail",
|
||||||
|
"unStigma",
|
||||||
|
"refCommandNo",
|
||||||
|
"refCommandDate",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
return new HttpSuccess(lists);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("history/{disciplineId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||||
|
date: "2024-03-12T10:09:47.000Z",
|
||||||
|
level: "string",
|
||||||
|
detail: "string",
|
||||||
|
unStigma: "string",
|
||||||
|
refCommandNo: "string",
|
||||||
|
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ba0e2f82-014e-46c6-8b82-a7c28eb5325f",
|
||||||
|
date: "2024-03-12T10:09:47.000Z",
|
||||||
|
level: "string",
|
||||||
|
detail: "string",
|
||||||
|
unStigma: "string",
|
||||||
|
refCommandNo: "string",
|
||||||
|
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async disciplineHistory(@Path() disciplineId: string) {
|
||||||
|
const record = await this.disciplineHistoryRepository.find({
|
||||||
|
where: { profileDisciplineId: disciplineId },
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"date",
|
||||||
|
"level",
|
||||||
|
"detail",
|
||||||
|
"unStigma",
|
||||||
|
"refCommandNo",
|
||||||
|
"refCommandDate",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
],
|
||||||
|
order: { createdAt: "DESC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newDiscipline(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: CreateProfileDiscipline,
|
||||||
|
) {
|
||||||
|
if (!body.profileEmployeeId) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||||
|
}
|
||||||
|
|
||||||
|
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||||
|
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = new ProfileDiscipline();
|
||||||
|
|
||||||
|
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.disciplineRepository.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{disciplineId}")
|
||||||
|
public async editDiscipline(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: UpdateProfileDiscipline,
|
||||||
|
@Path() disciplineId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
|
||||||
|
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
const history = new ProfileDisciplineHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
Object.assign(record, body);
|
||||||
|
history.profileDisciplineId = disciplineId;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
this.disciplineRepository.save(record),
|
||||||
|
this.disciplineHistoryRepository.save(history),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{disciplineId}")
|
||||||
|
public async deleteTraning(@Path() disciplineId: string) {
|
||||||
|
await this.disciplineHistoryRepository.delete({
|
||||||
|
profileDisciplineId: disciplineId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.disciplineRepository.delete({ id: disciplineId });
|
||||||
|
|
||||||
|
if (result.affected && result.affected <= 0) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
173
src/controllers/ProfileEmployeeDutyController.ts
Normal file
173
src/controllers/ProfileEmployeeDutyController.ts
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Example,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Path,
|
||||||
|
Post,
|
||||||
|
Request,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import { ProfileDutyHistory } from "../entities/ProfileDutyHistory";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
import { CreateProfileDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile/duty")
|
||||||
|
@Tags("ProfileDuty")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileDutyController extends Controller {
|
||||||
|
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private dutyRepository = AppDataSource.getRepository(ProfileDuty);
|
||||||
|
private dutyHistoryRepository = AppDataSource.getRepository(ProfileDutyHistory);
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
const lists = await this.dutyRepository.find({
|
||||||
|
where: { profileEmployeeId: profileId },
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"dateStart",
|
||||||
|
"dateEnd",
|
||||||
|
"reference",
|
||||||
|
"detail",
|
||||||
|
"refCommandNo",
|
||||||
|
"refCommandDate",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
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) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileDuty) {
|
||||||
|
if (!body.profileEmployeeId) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||||
|
}
|
||||||
|
|
||||||
|
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||||
|
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = new ProfileDuty();
|
||||||
|
|
||||||
|
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.dutyRepository.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{dutyId}")
|
||||||
|
public async editDuty(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: UpdateProfileDuty,
|
||||||
|
@Path() dutyId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.dutyRepository.findOneBy({ id: dutyId });
|
||||||
|
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
const history = new ProfileDutyHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
Object.assign(record, body);
|
||||||
|
history.profileDutyId = dutyId;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{dutyId}")
|
||||||
|
public async deleteTraning(@Path() dutyId: string) {
|
||||||
|
await this.dutyHistoryRepository.delete({
|
||||||
|
profileDutyId: dutyId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.dutyRepository.delete({ id: dutyId });
|
||||||
|
|
||||||
|
if (result.affected && result.affected <= 0) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
171
src/controllers/ProfileEmployeeHonorController.ts
Normal file
171
src/controllers/ProfileEmployeeHonorController.ts
Normal file
|
|
@ -0,0 +1,171 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Example,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Path,
|
||||||
|
Post,
|
||||||
|
Request,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import { CreateProfileEmployeeHonor, ProfileHonor, UpdateProfileHonor } from "../entities/ProfileHonor";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile-employee/honor")
|
||||||
|
@Tags("ProfileEmployeeHonor")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileEmployeeHonorController extends Controller {
|
||||||
|
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private honorRepo = AppDataSource.getRepository(ProfileHonor);
|
||||||
|
private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory);
|
||||||
|
|
||||||
|
@Get("{profileEmployeeId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||||
|
createdAt: "2024-03-12T03:10:05.594Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-03-12T03:10:05.594Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||||
|
detail: "string",
|
||||||
|
issueDate: "2024-03-12T10:09:47.000Z",
|
||||||
|
issuer: "string",
|
||||||
|
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||||
|
refCommandNo: "string",
|
||||||
|
isDate: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async getHonor(@Path() profileEmployeeId: string) {
|
||||||
|
const record = await this.honorRepo.findBy({ profileEmployeeId });
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("history/{honorId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "3bedb365-4a41-4df5-8f47-b6e143221d2c",
|
||||||
|
createdAt: "2024-03-12T03:11:01.395Z",
|
||||||
|
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||||
|
lastUpdatedAt: "2024-03-12T03:11:01.395Z",
|
||||||
|
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||||
|
createdFullName: "string",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
detail: "detail",
|
||||||
|
issueDate: "2024-03-12T10:10:31.000Z",
|
||||||
|
issuer: "issuer",
|
||||||
|
refCommandDate: "2024-03-12T10:10:31.000Z",
|
||||||
|
refCommandNo: "refCommandNo",
|
||||||
|
isDate: true,
|
||||||
|
profileHonorId: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "ba0e2f82-014e-46c6-8b82-a7c28eb5325f",
|
||||||
|
createdAt: "2024-03-12T03:10:05.657Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-03-12T03:10:05.657Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
detail: "string",
|
||||||
|
issueDate: "2024-03-12T10:09:47.000Z",
|
||||||
|
issuer: "string",
|
||||||
|
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||||
|
refCommandNo: "string",
|
||||||
|
isDate: true,
|
||||||
|
profileHonorId: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async honorHistory(@Path() honorId: string) {
|
||||||
|
const record = await this.honorHistoryRepo.findBy({
|
||||||
|
profileHonorId: honorId,
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeHonor) {
|
||||||
|
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 ProfileHonor();
|
||||||
|
|
||||||
|
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.honorRepo.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{honorId}")
|
||||||
|
public async editHonor(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: UpdateProfileHonor,
|
||||||
|
@Path() honorId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.honorRepo.findOneBy({ id: honorId });
|
||||||
|
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
const history = new ProfileHonorHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
Object.assign(record, body);
|
||||||
|
history.profileHonorId = honorId;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([this.honorRepo.save(record), this.honorHistoryRepo.save(history)]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{honorId}")
|
||||||
|
public async deleteTraning(@Path() honorId: string) {
|
||||||
|
await this.honorHistoryRepo.delete({
|
||||||
|
profileHonorId: honorId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.honorRepo.delete({ id: honorId });
|
||||||
|
|
||||||
|
if (result.affected && result.affected <= 0) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
229
src/controllers/ProfileEmployeeInsigniaController.ts
Normal file
229
src/controllers/ProfileEmployeeInsigniaController.ts
Normal file
|
|
@ -0,0 +1,229 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Example,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Path,
|
||||||
|
Post,
|
||||||
|
Request,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import {
|
||||||
|
CreateProfileEmployeeInsignia,
|
||||||
|
ProfileInsignia,
|
||||||
|
UpdateProfileInsignia,
|
||||||
|
} from "../entities/ProfileInsignia";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
import { Insignia } from "../entities/Insignia";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile-employee/insignia")
|
||||||
|
@Tags("ProfileEmployeeInsignia")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileEmployeeInsigniaController extends Controller {
|
||||||
|
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
||||||
|
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
|
||||||
|
private insigniaMetaRepo = AppDataSource.getRepository(Insignia);
|
||||||
|
|
||||||
|
@Get("{profileEmployeeId}")
|
||||||
|
@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: "สาวิตรี ศรีสมัย",
|
||||||
|
profileEmployeeId: "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() profileEmployeeId: string) {
|
||||||
|
const record = await this.insigniaRepo.find({
|
||||||
|
relations: {
|
||||||
|
insignia: {
|
||||||
|
insigniaType: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
where: { profileEmployeeId },
|
||||||
|
});
|
||||||
|
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) {
|
||||||
|
const record = await this.insigniaHistoryRepo.find({
|
||||||
|
relations: {
|
||||||
|
insignia: {
|
||||||
|
insigniaType: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
profileInsigniaId: InsigniaId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeInsignia) {
|
||||||
|
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 insignia = await this.insigniaMetaRepo.findOne({
|
||||||
|
where: { id: body.insigniaId },
|
||||||
|
});
|
||||||
|
if (!insignia) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = new ProfileInsignia();
|
||||||
|
|
||||||
|
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.insigniaRepo.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{insigniaId}")
|
||||||
|
public async editInsignia(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: UpdateProfileInsignia,
|
||||||
|
@Path() insigniaId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.insigniaRepo.findOneBy({ id: insigniaId });
|
||||||
|
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
const insignia = await this.insigniaMetaRepo.findOne({
|
||||||
|
where: { id: body.insigniaId },
|
||||||
|
});
|
||||||
|
if (!insignia) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||||
|
}
|
||||||
|
|
||||||
|
const history = new ProfileInsigniaHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
Object.assign(record, body);
|
||||||
|
history.profileInsigniaId = insigniaId;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{insigniaId}")
|
||||||
|
public async deleteInsignia(@Path() insigniaId: string) {
|
||||||
|
await this.insigniaHistoryRepo.delete({
|
||||||
|
profileInsigniaId: insigniaId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.insigniaRepo.delete({ id: insigniaId });
|
||||||
|
|
||||||
|
if (result.affected && result.affected <= 0) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
237
src/controllers/ProfileEmployeeLeaveController.ts
Normal file
237
src/controllers/ProfileEmployeeLeaveController.ts
Normal file
|
|
@ -0,0 +1,237 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Example,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Path,
|
||||||
|
Post,
|
||||||
|
Request,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import {
|
||||||
|
ProfileLeaveHistory,
|
||||||
|
CreateProfileLeave,
|
||||||
|
ProfileLeave,
|
||||||
|
UpdateProfileLeave,
|
||||||
|
} from "../entities/ProfileLeave";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { LeaveType } from "../entities/LeaveType";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile/leave")
|
||||||
|
@Tags("ProfileLeave")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileLeaveController extends Controller {
|
||||||
|
private profileRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private leaveRepo = AppDataSource.getRepository(ProfileLeave);
|
||||||
|
private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory);
|
||||||
|
private leaveTypeRepository = AppDataSource.getRepository(LeaveType);
|
||||||
|
|
||||||
|
@Get("{profileId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: {
|
||||||
|
id: "adbb08a6-d2f4-41b0-a9c1-49e883ca96bc",
|
||||||
|
createdAt: "2024-03-20T23:35:45.230Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-03-20T23:40:06.000Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||||
|
leaveTypeId: "8dc5e672-b416-4323-b086-06dde8c4353c",
|
||||||
|
dateLeaveStart: "2024-03-21T06:39:46.000Z",
|
||||||
|
dateLeaveEnd: "2024-03-21T06:39:46.000Z",
|
||||||
|
leaveDays: 0,
|
||||||
|
leaveCount: null,
|
||||||
|
totalLeave: 0,
|
||||||
|
status: "string",
|
||||||
|
reason: "string",
|
||||||
|
leaveType: {
|
||||||
|
id: "8dc5e672-b416-4323-b086-06dde8c4353c",
|
||||||
|
createdAt: "2024-02-04T21:28:40.536Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-02-04T21:28:40.536Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
name: "ลาป่วย",
|
||||||
|
code: "CM-002",
|
||||||
|
limit: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
public async getLeave(@Path() profileId: string) {
|
||||||
|
const record = await this.leaveRepo.find({
|
||||||
|
relations: { leaveType: true },
|
||||||
|
where: { profileId },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("history/{leaveId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "7eed2e72-d71c-4b3b-a90b-e1b7abdaa838",
|
||||||
|
createdAt: "2024-03-20T23:35:45.230Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-03-20T23:40:06.000Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||||
|
leaveTypeId: "8dc5e672-b416-4323-b086-06dde8c4353c",
|
||||||
|
dateLeaveStart: "2024-03-21T06:39:46.000Z",
|
||||||
|
dateLeaveEnd: "2024-03-21T06:39:46.000Z",
|
||||||
|
leaveDays: 0,
|
||||||
|
leaveCount: null,
|
||||||
|
totalLeave: 0,
|
||||||
|
status: "string",
|
||||||
|
reason: "string",
|
||||||
|
leaveType: {
|
||||||
|
id: "8dc5e672-b416-4323-b086-06dde8c4353c",
|
||||||
|
createdAt: "2024-02-04T21:28:40.536Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-02-04T21:28:40.536Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
name: "ลาป่วย",
|
||||||
|
code: "CM-002",
|
||||||
|
limit: 1,
|
||||||
|
},
|
||||||
|
profileLeaveId: "adbb08a6-d2f4-41b0-a9c1-49e883ca96bc",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "b1b9c291-9c96-4cbb-9309-6ff5a2a6e0e8",
|
||||||
|
createdAt: "2024-03-20T23:35:45.230Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-03-20T23:35:45.230Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||||
|
leaveTypeId: "7dc4e314-b456-4323-b086-06dde8c4353c",
|
||||||
|
dateLeaveStart: "2024-03-21T06:34:49.000Z",
|
||||||
|
dateLeaveEnd: "2024-03-21T06:34:49.000Z",
|
||||||
|
leaveDays: 2,
|
||||||
|
leaveCount: null,
|
||||||
|
totalLeave: 200,
|
||||||
|
status: "ไม่ผ่าน",
|
||||||
|
reason: "ติดงานสำคัญ",
|
||||||
|
leaveType: {
|
||||||
|
id: "7dc4e314-b456-4323-b086-06dde8c4353c",
|
||||||
|
createdAt: "2024-02-04T21:28:40.536Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-02-04T21:28:40.536Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
name: "ลาพักร้อน",
|
||||||
|
code: "CM-001",
|
||||||
|
limit: 356,
|
||||||
|
},
|
||||||
|
profileLeaveId: "adbb08a6-d2f4-41b0-a9c1-49e883ca96bc",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async leaveHistory(@Path() leaveId: string) {
|
||||||
|
const record = await this.leaveHistoryRepo.find({
|
||||||
|
relations: { leaveType: true },
|
||||||
|
where: { profileLeaveId: leaveId },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileLeave) {
|
||||||
|
if (!body.profileEmployeeId) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||||
|
}
|
||||||
|
|
||||||
|
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
|
||||||
|
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
const leaveType = await this.leaveTypeRepository.findOne({
|
||||||
|
where: { id: body.leaveTypeId },
|
||||||
|
});
|
||||||
|
if (!leaveType) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = new ProfileLeave();
|
||||||
|
|
||||||
|
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.leaveRepo.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{leaveId}")
|
||||||
|
public async editLeave(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: UpdateProfileLeave,
|
||||||
|
@Path() leaveId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.leaveRepo.findOneBy({ id: leaveId });
|
||||||
|
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
const leaveType = await this.leaveTypeRepository.findOne({
|
||||||
|
where: { id: body.leaveTypeId },
|
||||||
|
});
|
||||||
|
if (!leaveType) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||||
|
}
|
||||||
|
|
||||||
|
const history = new ProfileLeaveHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
Object.assign(record, body);
|
||||||
|
history.profileLeaveId = leaveId;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([this.leaveRepo.save(record), this.leaveHistoryRepo.save(history)]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{leaveId}")
|
||||||
|
public async deleteTraning(@Path() leaveId: string) {
|
||||||
|
await this.leaveHistoryRepo.delete({
|
||||||
|
profileLeaveId: leaveId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.leaveRepo.delete({ id: leaveId });
|
||||||
|
|
||||||
|
if (result.affected && result.affected <= 0) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
153
src/controllers/ProfileEmployeeNopaidController.ts
Normal file
153
src/controllers/ProfileEmployeeNopaidController.ts
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Example,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Path,
|
||||||
|
Post,
|
||||||
|
Request,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import { ProfileNopaidHistory } from "../entities/ProfileNopaidHistory";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
import { CreateProfileNopaid, ProfileNopaid, UpdateProfileNopaid } from "../entities/ProfileNopaid";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile/nopaid")
|
||||||
|
@Tags("ProfileNopaid")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileNopaidController extends Controller {
|
||||||
|
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private nopaidRepository = AppDataSource.getRepository(ProfileNopaid);
|
||||||
|
private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory);
|
||||||
|
|
||||||
|
@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) {
|
||||||
|
const lists = await this.nopaidRepository.find({
|
||||||
|
where: { profileId },
|
||||||
|
});
|
||||||
|
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) {
|
||||||
|
const record = await this.nopaidHistoryRepository.find({
|
||||||
|
where: { profileNopaidId: nopaidId },
|
||||||
|
order: { createdAt: "DESC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newNopaid(@Request() req: RequestWithUser, @Body() body: CreateProfileNopaid) {
|
||||||
|
if (!body.profileEmployeeId) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||||
|
}
|
||||||
|
|
||||||
|
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||||
|
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = new ProfileNopaid();
|
||||||
|
|
||||||
|
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.nopaidRepository.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{nopaidId}")
|
||||||
|
public async editNopaid(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: UpdateProfileNopaid,
|
||||||
|
@Path() nopaidId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
|
||||||
|
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
const history = new ProfileNopaidHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
Object.assign(record, body);
|
||||||
|
history.profileNopaidId = nopaidId;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
this.nopaidRepository.save(record),
|
||||||
|
this.nopaidHistoryRepository.save(history),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{nopaidId}")
|
||||||
|
public async deleteTraning(@Path() nopaidId: string) {
|
||||||
|
await this.nopaidHistoryRepository.delete({
|
||||||
|
profileNopaidId: nopaidId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.nopaidRepository.delete({ id: nopaidId });
|
||||||
|
|
||||||
|
if (result.affected && result.affected <= 0) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
193
src/controllers/ProfileEmployeeTrainingController.ts
Normal file
193
src/controllers/ProfileEmployeeTrainingController.ts
Normal file
|
|
@ -0,0 +1,193 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Example,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Path,
|
||||||
|
Post,
|
||||||
|
Request,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import {
|
||||||
|
CreateProfileEmployeeTraining,
|
||||||
|
ProfileTraining,
|
||||||
|
UpdateProfileTraining,
|
||||||
|
} from "../entities/ProfileTraining";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile-employee/training")
|
||||||
|
@Tags("ProfileEmployeeTraining")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileEmployeeTrainingController extends Controller {
|
||||||
|
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private trainingRepo = AppDataSource.getRepository(ProfileTraining);
|
||||||
|
private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory);
|
||||||
|
|
||||||
|
@Get("{profileEmployeeId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "3cf02fb7-2f0c-471b-b641-51d557375c0a",
|
||||||
|
createdAt: "2024-03-12T02:55:56.915Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-03-12T02:55:56.915Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||||
|
isActive: true,
|
||||||
|
startDate: "2024-03-12T09:55:23.000Z",
|
||||||
|
endDate: "2024-03-12T09:55:23.000Z",
|
||||||
|
numberOrder: "string",
|
||||||
|
topic: "string",
|
||||||
|
place: "string",
|
||||||
|
dateOrder: "2024-03-12T09:55:23.000Z",
|
||||||
|
department: "string",
|
||||||
|
duration: "string",
|
||||||
|
name: "string",
|
||||||
|
yearly: 0,
|
||||||
|
isDate: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async getTraining(@Path() profileEmployeeId: string) {
|
||||||
|
const record = await this.trainingRepo.findBy({ profileEmployeeId });
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("history/{trainingId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "6d4e9dbe-8697-4546-9651-0a1c3ea0a82d",
|
||||||
|
createdAt: "2024-03-12T02:55:56.971Z",
|
||||||
|
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
lastUpdatedAt: "2024-03-12T02:55:56.971Z",
|
||||||
|
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||||
|
createdFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
isActive: true,
|
||||||
|
startDate: "2024-03-12T09:55:23.000Z",
|
||||||
|
endDate: "2024-03-12T09:55:23.000Z",
|
||||||
|
numberOrder: "string",
|
||||||
|
topic: "string",
|
||||||
|
place: "string",
|
||||||
|
dateOrder: "2024-03-12T09:55:23.000Z",
|
||||||
|
department: "string",
|
||||||
|
duration: "string",
|
||||||
|
name: "string",
|
||||||
|
yearly: 0,
|
||||||
|
isDate: true,
|
||||||
|
profileTrainingId: "3cf02fb7-2f0c-471b-b641-51d557375c0a",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "a251c176-3dac-4d09-9813-38c8db1127e3",
|
||||||
|
createdAt: "2024-03-12T02:58:17.917Z",
|
||||||
|
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||||
|
lastUpdatedAt: "2024-03-12T02:58:17.917Z",
|
||||||
|
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||||
|
createdFullName: "string",
|
||||||
|
lastUpdateFullName: "สาวิตรี ศรีสมัย",
|
||||||
|
isActive: true,
|
||||||
|
startDate: "2024-03-12T09:57:44.000Z",
|
||||||
|
endDate: "2024-03-12T09:57:44.000Z",
|
||||||
|
numberOrder: "string",
|
||||||
|
topic: "topic",
|
||||||
|
place: "place",
|
||||||
|
dateOrder: "2024-03-12T09:57:44.000Z",
|
||||||
|
department: "department",
|
||||||
|
duration: "string",
|
||||||
|
name: "name",
|
||||||
|
yearly: 0,
|
||||||
|
isDate: true,
|
||||||
|
profileTrainingId: "3cf02fb7-2f0c-471b-b641-51d557375c0a",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async trainingHistory(@Path() trainingId: string) {
|
||||||
|
const record = await this.trainingHistoryRepo.findBy({
|
||||||
|
profileTrainingId: trainingId,
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeTraining) {
|
||||||
|
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 ProfileTraining();
|
||||||
|
|
||||||
|
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.trainingRepo.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{trainingId}")
|
||||||
|
public async editTraining(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: UpdateProfileTraining,
|
||||||
|
@Path() trainingId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.trainingRepo.findOneBy({ id: trainingId });
|
||||||
|
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
const history = new ProfileTrainingHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
Object.assign(record, body);
|
||||||
|
history.profileTrainingId = trainingId;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([this.trainingRepo.save(record), this.trainingHistoryRepo.save(history)]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{trainingId}")
|
||||||
|
public async deleteTraining(@Path() trainingId: string) {
|
||||||
|
await this.trainingHistoryRepo.delete({
|
||||||
|
profileTrainingId: trainingId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.trainingRepo.delete({ id: trainingId });
|
||||||
|
|
||||||
|
if (result.affected && result.affected <= 0) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -102,8 +102,19 @@ export class ProfileAssessment extends EntityBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateProfileAssessment {
|
export class CreateProfileAssessment {
|
||||||
profileId?: string | null;
|
profileId: string | null;
|
||||||
profileEmployeeId?: string | null;
|
name: string | null;
|
||||||
|
date: Date | null;
|
||||||
|
point1: number | null;
|
||||||
|
point1Total: number | null;
|
||||||
|
point2: number | null;
|
||||||
|
point2Total: number | null;
|
||||||
|
pointSum: number | null;
|
||||||
|
pointSumTotal: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateProfileEmployeeAssessment {
|
||||||
|
profileEmployeeId: string | null;
|
||||||
name: string | null;
|
name: string | null;
|
||||||
date: Date | null;
|
date: Date | null;
|
||||||
point1: number | null;
|
point1: number | null;
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,16 @@ export class ProfileCertificate extends EntityBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateProfileCertificate {
|
export class CreateProfileCertificate {
|
||||||
profileId?: string | null;
|
profileId: string | null;
|
||||||
profileEmployeeId?: string | null;
|
expireDate: Date | null;
|
||||||
|
issueDate: Date | null;
|
||||||
|
certificateNo: string | null;
|
||||||
|
certificateType: string | null;
|
||||||
|
issuer: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateProfileEmployeeCertificate {
|
||||||
|
profileEmployeeId: string | null;
|
||||||
expireDate: Date | null;
|
expireDate: Date | null;
|
||||||
issueDate: Date | null;
|
issueDate: Date | null;
|
||||||
certificateNo: string | null;
|
certificateNo: string | null;
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,17 @@ export class ProfileHonor extends EntityBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateProfileHonor {
|
export class CreateProfileHonor {
|
||||||
profileId?: string | null;
|
profileId: string | null;
|
||||||
profileEmployeeId?: string | null;
|
detail: string | null;
|
||||||
|
issueDate: Date | null;
|
||||||
|
issuer: string | null;
|
||||||
|
refCommandDate: Date | null;
|
||||||
|
refCommandNo: string | null;
|
||||||
|
isDate: boolean | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateProfileEmployeeHonor {
|
||||||
|
profileEmployeeId: string | null;
|
||||||
detail: string | null;
|
detail: string | null;
|
||||||
issueDate: Date | null;
|
issueDate: Date | null;
|
||||||
issuer: string | null;
|
issuer: string | null;
|
||||||
|
|
|
||||||
|
|
@ -142,8 +142,24 @@ export class ProfileInsignia extends EntityBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateProfileInsignia {
|
export class CreateProfileInsignia {
|
||||||
profileId?: string | null;
|
profileId: string | null;
|
||||||
profileEmployeeId?: string | null;
|
year: number;
|
||||||
|
no: string | null;
|
||||||
|
volume: string | null;
|
||||||
|
section: string | null;
|
||||||
|
page: string | null;
|
||||||
|
receiveDate: Date | null;
|
||||||
|
insigniaId: string;
|
||||||
|
dateAnnounce: Date | null;
|
||||||
|
issue: string | null;
|
||||||
|
volumeNo: string | null;
|
||||||
|
refCommandDate: Date | null;
|
||||||
|
refCommandNo: string | null;
|
||||||
|
note: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateProfileEmployeeInsignia {
|
||||||
|
profileEmployeeId: string | null;
|
||||||
year: number;
|
year: number;
|
||||||
no: string | null;
|
no: string | null;
|
||||||
volume: string | null;
|
volume: string | null;
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,22 @@ export class ProfileTraining extends EntityBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateProfileTraining {
|
export class CreateProfileTraining {
|
||||||
profileId?: string | null;
|
profileId: string | null;
|
||||||
profileEmployeeId?: string | null;
|
startDate: Date | null;
|
||||||
|
endDate: Date | null;
|
||||||
|
numberOrder: string | null;
|
||||||
|
topic: string | null;
|
||||||
|
place: string | null;
|
||||||
|
dateOrder: Date | null;
|
||||||
|
department: string | null;
|
||||||
|
duration: string | null;
|
||||||
|
name: string | null;
|
||||||
|
yearly: number | null;
|
||||||
|
isDate: boolean | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateProfileEmployeeTraining {
|
||||||
|
profileEmployeeId: string | null;
|
||||||
startDate: Date | null;
|
startDate: Date | null;
|
||||||
endDate: Date | null;
|
endDate: Date | null;
|
||||||
numberOrder: string | null;
|
numberOrder: string | null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue