แก้ไขเงินเดือน
This commit is contained in:
parent
f79704c7a7
commit
bf12751bfa
10 changed files with 969 additions and 582 deletions
|
|
@ -32,9 +32,7 @@ import { Not } from "typeorm";
|
|||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
|
||||
export class PosTypeController extends Controller {
|
||||
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
|
||||
|
|
@ -45,34 +43,37 @@ export class PosTypeController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Post()
|
||||
@Example(
|
||||
{
|
||||
positionName: "นักบริหาร",
|
||||
posTypeRank: 1,
|
||||
},
|
||||
)
|
||||
@Example({
|
||||
positionName: "นักบริหาร",
|
||||
posTypeRank: 1,
|
||||
})
|
||||
async createType(
|
||||
@Body()
|
||||
requestBody: CreatePosType,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const posType = Object.assign(new PosType(), requestBody);
|
||||
if (!posType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const chkPosTypeName = await this.posTypeRepository.findOne({ where: {
|
||||
posTypeName: requestBody.posTypeName }
|
||||
})
|
||||
if(chkPosTypeName){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว");
|
||||
const chkPosTypeName = await this.posTypeRepository.findOne({
|
||||
where: {
|
||||
posTypeName: requestBody.posTypeName,
|
||||
},
|
||||
});
|
||||
if (chkPosTypeName) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
// try {
|
||||
posType.createdUserId = request.user.sub;
|
||||
posType.createdFullName = request.user.name;
|
||||
posType.lastUpdateUserId = request.user.sub;
|
||||
posType.lastUpdateFullName = request.user.name;
|
||||
await this.posTypeRepository.save(posType);
|
||||
return new HttpSuccess(posType);
|
||||
posType.createdUserId = request.user.sub;
|
||||
posType.createdFullName = request.user.name;
|
||||
posType.lastUpdateUserId = request.user.sub;
|
||||
posType.lastUpdateFullName = request.user.name;
|
||||
await this.posTypeRepository.save(posType);
|
||||
return new HttpSuccess(posType);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
|
|
@ -86,12 +87,10 @@ export class PosTypeController extends Controller {
|
|||
* @param {string} id Id ประเภทตำแหน่ง
|
||||
*/
|
||||
@Put("{id}")
|
||||
@Example(
|
||||
{
|
||||
positionName: "นักบริหาร",
|
||||
posTypeRank: 1,
|
||||
},
|
||||
)
|
||||
@Example({
|
||||
positionName: "นักบริหาร",
|
||||
posTypeRank: 1,
|
||||
})
|
||||
async editType(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdatePosType,
|
||||
|
|
@ -101,19 +100,24 @@ export class PosTypeController extends Controller {
|
|||
if (!posType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
const chkPosTypeName = await this.posTypeRepository.findOne({ where: {
|
||||
id: Not(id),
|
||||
posTypeName: requestBody.posTypeName }
|
||||
})
|
||||
if(chkPosTypeName){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว");
|
||||
const chkPosTypeName = await this.posTypeRepository.findOne({
|
||||
where: {
|
||||
id: Not(id),
|
||||
posTypeName: requestBody.posTypeName,
|
||||
},
|
||||
});
|
||||
if (chkPosTypeName) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว",
|
||||
);
|
||||
}
|
||||
// try {
|
||||
posType.lastUpdateUserId = request.user.sub;
|
||||
posType.lastUpdateFullName = request.user.name;
|
||||
this.posTypeRepository.merge(posType, requestBody);
|
||||
await this.posTypeRepository.save(posType);
|
||||
return new HttpSuccess(posType.id);
|
||||
posType.lastUpdateUserId = request.user.sub;
|
||||
posType.lastUpdateFullName = request.user.name;
|
||||
this.posTypeRepository.merge(posType, requestBody);
|
||||
await this.posTypeRepository.save(posType);
|
||||
return new HttpSuccess(posType.id);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
|
|
@ -133,15 +137,15 @@ export class PosTypeController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
const IdExitsInLevel = await this.posLevelRepository.find({
|
||||
where: { posTypeId: id }
|
||||
})
|
||||
if(IdExitsInLevel.length > 0){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับ posLevel",);
|
||||
where: { posTypeId: id },
|
||||
});
|
||||
if (IdExitsInLevel.length > 0) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับ posLevel");
|
||||
}
|
||||
|
||||
|
||||
// try {
|
||||
await this.posTypeRepository.remove(delPosType);
|
||||
return new HttpSuccess();
|
||||
await this.posTypeRepository.remove(delPosType);
|
||||
return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
|
|
@ -165,35 +169,35 @@ export class PosTypeController extends Controller {
|
|||
id: "00000000-0000-0000-0000-000000000000",
|
||||
posLevelName: "นักบริหาร",
|
||||
posLevelRank: 1,
|
||||
posLevelAuthority: "HEAD"
|
||||
}
|
||||
]
|
||||
posLevelAuthority: "HEAD",
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
async GetTypeDetail(@Path() id: string) {
|
||||
// try {
|
||||
const getPosType = await this.posTypeRepository.findOne({
|
||||
select: ["id", "posTypeName", "posTypeRank"],
|
||||
relations: ["posLevels"],
|
||||
where: { id: id }
|
||||
});
|
||||
if (!getPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
const getPosType = await this.posTypeRepository.findOne({
|
||||
select: ["id", "posTypeName", "posTypeRank"],
|
||||
relations: ["posLevels"],
|
||||
where: { id: id },
|
||||
});
|
||||
if (!getPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
|
||||
const mapGetPosType = {
|
||||
id : getPosType.id,
|
||||
posTypeName : getPosType.posTypeName,
|
||||
posTypeRank : getPosType.posTypeRank,
|
||||
posLevels : getPosType.posLevels.map((posLevel) => ({
|
||||
id: posLevel.id,
|
||||
posLevelName: posLevel.posLevelName,
|
||||
posLevelRank: posLevel.posLevelRank,
|
||||
posLevelAuthority: posLevel.posLevelAuthority,
|
||||
})),
|
||||
}
|
||||
|
||||
return new HttpSuccess(mapGetPosType);
|
||||
const mapGetPosType = {
|
||||
id: getPosType.id,
|
||||
posTypeName: getPosType.posTypeName,
|
||||
posTypeRank: getPosType.posTypeRank,
|
||||
posLevels: getPosType.posLevels.map((posLevel) => ({
|
||||
id: posLevel.id,
|
||||
posLevelName: posLevel.posLevelName,
|
||||
posLevelRank: posLevel.posLevelRank,
|
||||
posLevelAuthority: posLevel.posLevelAuthority,
|
||||
})),
|
||||
};
|
||||
|
||||
return new HttpSuccess(mapGetPosType);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
|
|
@ -223,25 +227,23 @@ export class PosTypeController extends Controller {
|
|||
])
|
||||
async GetPosType() {
|
||||
// try {
|
||||
const posType = await this.posTypeRepository.find({
|
||||
select: ["id", "posTypeName", "posTypeRank"],
|
||||
relations: ["posLevels"],
|
||||
});
|
||||
if (!posType) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
const mapPosType = posType.map((item) => ({
|
||||
id: item.id,
|
||||
posTypeName: item.posTypeName,
|
||||
posTypeRank: item.posTypeRank,
|
||||
posLevels: item.posLevels.map((posLevel) => ({
|
||||
id: posLevel.id,
|
||||
posLevelName: posLevel.posLevelName,
|
||||
posLevelRank: posLevel.posLevelRank,
|
||||
posLevelAuthority: posLevel.posLevelAuthority,
|
||||
})),
|
||||
}));
|
||||
return new HttpSuccess(mapPosType);
|
||||
const posType = await this.posTypeRepository.find({
|
||||
select: ["id", "posTypeName", "posTypeRank"],
|
||||
relations: ["posLevels"],
|
||||
});
|
||||
|
||||
const mapPosType = posType.map((item) => ({
|
||||
id: item.id,
|
||||
posTypeName: item.posTypeName,
|
||||
posTypeRank: item.posTypeRank,
|
||||
posLevels: item.posLevels.map((posLevel) => ({
|
||||
id: posLevel.id,
|
||||
posLevelName: posLevel.posLevelName,
|
||||
posLevelRank: posLevel.posLevelRank,
|
||||
posLevelAuthority: posLevel.posLevelAuthority,
|
||||
})),
|
||||
}));
|
||||
return new HttpSuccess(mapPosType);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue