Merge branch 'develop' into adiDev
This commit is contained in:
commit
cf8281c38c
3 changed files with 118 additions and 5 deletions
|
|
@ -19,11 +19,13 @@ import {
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Equal, ILike, In, IsNull, Like, Not, Brackets, MoreThan } from "typeorm";
|
||||
import { ChangePosition } from "../entities/ChangePosition";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ChangePosition, CreateChangePosition, UpdateChangePosition } from "../entities/ChangePosition";
|
||||
|
||||
@Route("api/v1/placement/change-position")
|
||||
@Tags("Switch")
|
||||
@Tags("Placement")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
|
|
@ -34,17 +36,123 @@ export class ChangePositionController extends Controller {
|
|||
private ChangePositionRepository = AppDataSource.getRepository(ChangePosition);
|
||||
|
||||
/**
|
||||
* API รายการออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง
|
||||
* API เพิ่มรอบย้ายสับเปลี่ยนตำแหน่ง
|
||||
*
|
||||
* @summary API รายการออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง
|
||||
* @summary เพิ่มรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
async CreateChangePosition(
|
||||
@Body() body: CreateChangePosition,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _changePosition = await this.ChangePositionRepository.findOne({
|
||||
where: { name: body.name },
|
||||
});
|
||||
if(_changePosition){
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
|
||||
const changePosition = new ChangePosition();
|
||||
Object.assign(changePosition, body);
|
||||
changePosition.date = new Date,
|
||||
changePosition.status = "WAITTING",
|
||||
changePosition.createdUserId = request.user.sub;
|
||||
changePosition.createdFullName = request.user.name;
|
||||
changePosition.lastUpdateUserId = request.user.sub;
|
||||
changePosition.lastUpdateFullName = request.user.name;
|
||||
await this.ChangePositionRepository.save(changePosition);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบรอบย้ายสับเปลี่ยนตำแหน่ง
|
||||
*
|
||||
* @summary ลบรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN)
|
||||
*
|
||||
* @param {string} id Id รอบย้ายสับเปลี่ยนตำแหน่ง
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async DeleteChangePosition(@Path() id: string) {
|
||||
let result: any;
|
||||
try {
|
||||
result = await this.ChangePositionRepository.delete({ id: id });
|
||||
} catch {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่สามารถลบได้เนื่องจากมีการใช้งานรอบย้ายสับเปลี่ยนตำแหน่งนี้อยู่",
|
||||
);
|
||||
}
|
||||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขรอบย้ายสับเปลี่ยนตำแหน่ง
|
||||
*
|
||||
* @summary แก้ไขรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN)
|
||||
*
|
||||
* @param {string} id Id รอบย้ายสับเปลี่ยนตำแหน่ง
|
||||
*/
|
||||
@Put("{id}")
|
||||
async UpdateChangePosition(
|
||||
@Request() request: RequestWithUser,
|
||||
@Path() id: string,
|
||||
@Body() body: UpdateChangePosition,
|
||||
) {
|
||||
|
||||
const changePosition = await this.ChangePositionRepository.findOneBy({ id });
|
||||
if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const checkDuplicate = await this.ChangePositionRepository.find({
|
||||
where: {
|
||||
id: Not(id),
|
||||
name: body.name
|
||||
},
|
||||
});
|
||||
if(checkDuplicate.length > 0){
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
Object.assign(changePosition, body);
|
||||
changePosition.lastUpdateUserId = request.user.sub;
|
||||
changePosition.lastUpdateFullName = request.user.name;
|
||||
await this.ChangePositionRepository.save(changePosition);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการรอบย้ายสับเปลี่ยนตำแหน่ง
|
||||
*
|
||||
* @summary API รายการรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetChangePositionLists() {
|
||||
|
||||
const data = await this.ChangePositionRepository.find();
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดรอบย้ายสับเปลี่ยนตำแหน่ง
|
||||
*
|
||||
* @summary API รายละเอียดรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN)
|
||||
*
|
||||
* @param {string} id Id รอบย้ายสับเปลี่ยนตำแหน่ง
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetChangePositionById( @Path() id: string ) {
|
||||
|
||||
const data = await this.ChangePositionRepository.findOne({ where: { id: id }});
|
||||
if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง");
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1483,6 +1483,7 @@ export class ProfileController extends Controller {
|
|||
citizenId: profile.citizenId,
|
||||
birthDate: profile.birthDate,
|
||||
position: profile.position,
|
||||
leaveDate: profile.dateLeave,
|
||||
posMaster: posMaster == null ? null : posMaster.posMasterNo,
|
||||
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
|
||||
posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName,
|
||||
|
|
@ -1617,6 +1618,7 @@ export class ProfileController extends Controller {
|
|||
citizenId: profile.citizenId,
|
||||
birthDate: profile.birthDate,
|
||||
position: profile.position,
|
||||
leaveDate: profile.dateLeave,
|
||||
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
|
||||
posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName,
|
||||
posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank,
|
||||
|
|
@ -1738,6 +1740,7 @@ export class ProfileController extends Controller {
|
|||
lastName: profile.lastName,
|
||||
citizenId: profile.citizenId,
|
||||
position: profile.position,
|
||||
leaveDate: profile.dateLeave,
|
||||
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
|
||||
posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName,
|
||||
posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank,
|
||||
|
|
@ -1859,6 +1862,7 @@ export class ProfileController extends Controller {
|
|||
lastName: profile.lastName,
|
||||
citizenId: profile.citizenId,
|
||||
position: profile.position,
|
||||
leaveDate: profile.dateLeave,
|
||||
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
|
||||
posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName,
|
||||
posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank,
|
||||
|
|
|
|||
|
|
@ -535,6 +535,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
profile.dateRetire = calculateRetireDate(profile.birthDate);
|
||||
profile.dateRetireLaw = calculateRetireLaw(profile.birthDate);
|
||||
profile.citizenId = Extension.CheckCitizen(profile.citizenId);
|
||||
profile.statusTemp = profile.employeeClass.toLocaleUpperCase() == "TEMP" ? "WAITTING" : "";
|
||||
profile.employeeClass = profile.employeeClass.toLocaleUpperCase();
|
||||
await this.profileRepo.save(profile);
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue