sort ตำแหน่งลูกจ้าง
This commit is contained in:
parent
2972d6ef5e
commit
222a2a5b6b
4 changed files with 71 additions and 22 deletions
|
|
@ -58,7 +58,6 @@ export class EmployeePosLevelController extends Controller {
|
|||
|
||||
const EmpPosType = await this.employeePosTypeRepository.findOne({
|
||||
where: { id: requestBody.posTypeId },
|
||||
|
||||
});
|
||||
if (!EmpPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานลูกจ้างประจำนี้");
|
||||
|
|
@ -112,12 +111,12 @@ export class EmployeePosLevelController extends Controller {
|
|||
|
||||
const chkEmpPosLevel = await this.employeePosLevelRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posLevelName: requestBody.posLevelName,
|
||||
posTypeId: requestBody.posTypeId,
|
||||
id: Not(id),
|
||||
posLevelName: requestBody.posLevelName,
|
||||
posTypeId: requestBody.posTypeId,
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
if (chkEmpPosLevel) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
|
|
@ -198,6 +197,7 @@ export class EmployeePosLevelController extends Controller {
|
|||
const empPosLevel = await this.employeePosLevelRepository.find({
|
||||
relations: ["posType"],
|
||||
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority"],
|
||||
order: { posLevelRank: "ASC" },
|
||||
});
|
||||
const mapEmpPosLevel = empPosLevel.map((item) => ({
|
||||
id: item.id,
|
||||
|
|
|
|||
|
|
@ -166,12 +166,14 @@ export class EmployeePosTypeController extends Controller {
|
|||
posTypeName: getEmpPosType.posTypeName,
|
||||
posTypeRank: getEmpPosType.posTypeRank,
|
||||
posTypeShortName: getEmpPosType.posTypeShortName,
|
||||
posLevels: getEmpPosType.posLevels.map((empPosLevel) => ({
|
||||
id: empPosLevel.id,
|
||||
posLevelName: empPosLevel.posLevelName,
|
||||
posLevelRank: empPosLevel.posLevelRank,
|
||||
posLevelAuthority: empPosLevel.posLevelAuthority,
|
||||
})),
|
||||
posLevels: getEmpPosType.posLevels
|
||||
.sort((a, b) => a.posLevelRank - b.posLevelRank)
|
||||
.map((empPosLevel) => ({
|
||||
id: empPosLevel.id,
|
||||
posLevelName: empPosLevel.posLevelName,
|
||||
posLevelRank: empPosLevel.posLevelRank,
|
||||
posLevelAuthority: empPosLevel.posLevelAuthority,
|
||||
})),
|
||||
};
|
||||
|
||||
return new HttpSuccess(mapGetEmpPosType);
|
||||
|
|
@ -188,6 +190,7 @@ export class EmployeePosTypeController extends Controller {
|
|||
const empPosType = await this.employeePosTypeRepository.find({
|
||||
relations: ["posLevels"],
|
||||
select: ["id", "posTypeName", "posTypeRank", "posTypeShortName"],
|
||||
order: { posTypeRank: "ASC" },
|
||||
});
|
||||
|
||||
const mapEmpPosType = empPosType.map((item) => ({
|
||||
|
|
@ -195,12 +198,14 @@ export class EmployeePosTypeController extends Controller {
|
|||
posTypeName: item.posTypeName,
|
||||
posTypeRank: item.posTypeRank,
|
||||
posTypeShortName: item.posTypeShortName,
|
||||
posLevels: item.posLevels.map((empPosLevel) => ({
|
||||
id: empPosLevel.id,
|
||||
posLevelName: empPosLevel.posLevelName,
|
||||
posLevelRank: empPosLevel.posLevelRank,
|
||||
posLevelAuthority: empPosLevel.posLevelAuthority,
|
||||
})),
|
||||
posLevels: item.posLevels
|
||||
.sort((a, b) => a.posLevelRank - b.posLevelRank)
|
||||
.map((empPosLevel) => ({
|
||||
id: empPosLevel.id,
|
||||
posLevelName: empPosLevel.posLevelName,
|
||||
posLevelRank: empPosLevel.posLevelRank,
|
||||
posLevelAuthority: empPosLevel.posLevelAuthority,
|
||||
})),
|
||||
}));
|
||||
return new HttpSuccess(mapEmpPosType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import {
|
|||
Get,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import { Not } from "typeorm"
|
||||
import { Not } from "typeorm";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -54,6 +54,27 @@ export class PosExecutiveController extends Controller {
|
|||
}
|
||||
|
||||
const posExecutive = Object.assign(new PosExecutive(), requestBody);
|
||||
if (requestBody.posExecutivePriority == null) {
|
||||
const checkPriority = await this.posExecutiveRepository.findOne({
|
||||
order: { posExecutivePriority: "DESC" },
|
||||
});
|
||||
if (checkPriority == null) {
|
||||
posExecutive.posExecutivePriority = 1;
|
||||
} else {
|
||||
posExecutive.posExecutivePriority = checkPriority.posExecutivePriority + 1;
|
||||
}
|
||||
} else {
|
||||
posExecutive.posExecutivePriority = requestBody.posExecutivePriority;
|
||||
}
|
||||
const _checkPriority = await this.posExecutiveRepository.findOne({
|
||||
where: {
|
||||
posExecutivePriority: posExecutive.posExecutivePriority,
|
||||
},
|
||||
});
|
||||
|
||||
if (_checkPriority) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
posExecutive.createdUserId = request.user.sub;
|
||||
posExecutive.createdFullName = request.user.name;
|
||||
posExecutive.lastUpdateUserId = request.user.sub;
|
||||
|
|
@ -84,17 +105,40 @@ export class PosExecutiveController extends Controller {
|
|||
const checkName = await this.posExecutiveRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posExecutiveName: requestBody.posExecutiveName
|
||||
posExecutiveName: requestBody.posExecutiveName,
|
||||
},
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
if (requestBody.posExecutivePriority == null) {
|
||||
const checkPriority = await this.posExecutiveRepository.findOne({
|
||||
order: { posExecutivePriority: "DESC" },
|
||||
});
|
||||
if (checkPriority == null) {
|
||||
posExecutive.posExecutivePriority = 1;
|
||||
} else {
|
||||
posExecutive.posExecutivePriority = checkPriority.posExecutivePriority + 1;
|
||||
}
|
||||
} else {
|
||||
posExecutive.posExecutivePriority = requestBody.posExecutivePriority;
|
||||
}
|
||||
const _checkPriority = await this.posExecutiveRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posExecutivePriority: posExecutive.posExecutivePriority,
|
||||
},
|
||||
});
|
||||
|
||||
if (_checkPriority) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
posExecutive.posExecutiveName = requestBody.posExecutiveName;
|
||||
posExecutive.lastUpdateUserId = request.user.sub;
|
||||
posExecutive.lastUpdateFullName = request.user.name;
|
||||
this.posExecutiveRepository.merge(posExecutive, requestBody);
|
||||
// this.posExecutiveRepository.merge(posExecutive, requestBody);
|
||||
await this.posExecutiveRepository.save(posExecutive);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export class CreatePosExecutive {
|
|||
posExecutiveName: string;
|
||||
|
||||
@Column()
|
||||
posExecutivePriority: number;
|
||||
posExecutivePriority: number | null;
|
||||
}
|
||||
|
||||
export type UpdatePosExecutive = Partial<CreatePosExecutive>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue