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