Merge branch 'develop' into adiDev
This commit is contained in:
commit
83eeb0d468
10 changed files with 1202 additions and 1009 deletions
|
|
@ -1,204 +1,176 @@
|
|||
import {
|
||||
Controller,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Put,
|
||||
Post,
|
||||
Path,
|
||||
Delete,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { Controller, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Put, Post, Path, Delete, Query } from "tsoa"
|
||||
import { setLogDataDiff } from "../interfaces/utils"
|
||||
|
||||
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 permission from "../interfaces/permission";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Appoint, CreateAppoint, Person, UpdateAppoint } from "../entities/Appoint";
|
||||
import { AppointDirector } from "../entities/AppointDirector";
|
||||
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 permission from "../interfaces/permission"
|
||||
import { RequestWithUser } from "../middlewares/user"
|
||||
import { Appoint, CreateAppoint, Person, UpdateAppoint } from "../entities/Appoint"
|
||||
import { AppointDirector } from "../entities/AppointDirector"
|
||||
|
||||
@Route("api/v1/probation/appoint")
|
||||
@Tags("Appoint Director")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
|
||||
export class AppointController extends Controller {
|
||||
private appointRepository = AppDataSource.getRepository(Appoint);
|
||||
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector);
|
||||
private appointRepository = AppDataSource.getRepository(Appoint)
|
||||
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector)
|
||||
|
||||
/**
|
||||
* API รายการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||
*
|
||||
* @summary รายการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetList(
|
||||
@Query() keyword: string = "",
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionList(request, "SYS_PROBATION");
|
||||
const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION");
|
||||
/**
|
||||
* API รายการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||
*
|
||||
* @summary รายการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetList(@Query() keyword: string = "", @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionList(request, "SYS_PROBATION")
|
||||
const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION")
|
||||
|
||||
const conditions: any = {};
|
||||
const conditions: any = {}
|
||||
|
||||
if (_data.root != undefined && _data.root != null && _data.root[0] != null) {
|
||||
conditions.root = _data.root;
|
||||
}
|
||||
if (_data.root != undefined && _data.root != null && _data.root[0] != null) {
|
||||
conditions.root = _data.root
|
||||
}
|
||||
|
||||
if (_data.child1 != undefined && _data.child1 != null && _data.child1[0] != null) {
|
||||
conditions.child1 = _data.child1;
|
||||
}
|
||||
if (_data.child1 != undefined && _data.child1 != null && _data.child1[0] != null) {
|
||||
conditions.child1 = _data.child1
|
||||
}
|
||||
|
||||
if (_data.child2 != undefined && _data.child2 != null && _data.child2[0] != null) {
|
||||
conditions.child2 = _data.child2;
|
||||
}
|
||||
if (_data.child2 != undefined && _data.child2 != null && _data.child2[0] != null) {
|
||||
conditions.child2 = _data.child2
|
||||
}
|
||||
|
||||
if (_data.child3 != undefined && _data.child3 != null && _data.child3[0] != null) {
|
||||
conditions.child3 = _data.child3;
|
||||
}
|
||||
if (_data.child3 != undefined && _data.child3 != null && _data.child3[0] != null) {
|
||||
conditions.child3 = _data.child3
|
||||
}
|
||||
|
||||
if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) {
|
||||
conditions.child4 = _data.child4;
|
||||
}
|
||||
if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) {
|
||||
conditions.child4 = _data.child4
|
||||
}
|
||||
|
||||
const appoint = await this.appointRepository.find({
|
||||
relations: ["personal"],
|
||||
where: { personal: conditions },
|
||||
});
|
||||
const appoint = await this.appointRepository.find({
|
||||
relations: ["personal"],
|
||||
where: { personal: conditions },
|
||||
})
|
||||
|
||||
return new HttpSuccess(appoint);
|
||||
}
|
||||
return new HttpSuccess(appoint)
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการแต่งตั้งคณะกรรมการฯ ที่ออกคำสั่งแล้วทดลองงาน
|
||||
*
|
||||
* @summary รายการแต่งตั้งคณะกรรมการฯ ที่ออกคำสั่งแล้ว
|
||||
*
|
||||
*/
|
||||
@Get("list/{id}")
|
||||
async GetListCommand(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
const appoint = await this.appointRepository.find({
|
||||
relations: ["directors"],
|
||||
where: { profileId: id, status: "DONE" },
|
||||
});
|
||||
/**
|
||||
* API รายการแต่งตั้งคณะกรรมการฯ ที่ออกคำสั่งแล้วทดลองงาน
|
||||
*
|
||||
* @summary รายการแต่งตั้งคณะกรรมการฯ ที่ออกคำสั่งแล้ว
|
||||
*
|
||||
*/
|
||||
@Get("list/{id}")
|
||||
async GetListCommand(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
const appoint = await this.appointRepository.find({
|
||||
relations: ["directors"],
|
||||
where: { profileId: id, status: "DONE" },
|
||||
})
|
||||
|
||||
return new HttpSuccess(appoint);
|
||||
}
|
||||
return new HttpSuccess(appoint)
|
||||
}
|
||||
|
||||
/**
|
||||
* API สร้างการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||
*
|
||||
* @summary สร้างการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
*/
|
||||
@Post("")
|
||||
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
||||
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
||||
/**
|
||||
* API สร้างการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||
*
|
||||
* @summary สร้างการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
*/
|
||||
@Post("")
|
||||
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
||||
await new permission().PermissionCreate(request, "SYS_PROBATION")
|
||||
|
||||
const data: any = {
|
||||
topic: requestBody.topic,
|
||||
profileId: requestBody.profileId,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
};
|
||||
const before = null;
|
||||
const appoint = await this.appointRepository.save(data, { data: request });
|
||||
setLogDataDiff(request, { before, after: appoint });
|
||||
const data: any = {
|
||||
topic: requestBody.topic,
|
||||
profileId: requestBody.profileId,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
}
|
||||
const before = null
|
||||
const appoint = await this.appointRepository.save(data, { data: request })
|
||||
setLogDataDiff(request, { before, after: appoint })
|
||||
|
||||
return new HttpSuccess(appoint.id);
|
||||
}
|
||||
return new HttpSuccess(appoint.id)
|
||||
}
|
||||
|
||||
/**
|
||||
* API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
* @summary API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ ตาม id
|
||||
*
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION");
|
||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||
/**
|
||||
* API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
* @summary API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ ตาม id
|
||||
*
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION")
|
||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION")
|
||||
|
||||
const appoint = await this.appointRepository.findOne({
|
||||
select: ["id", "topic", "status", "profileId"],
|
||||
where: { id },
|
||||
relations: ["directors"],
|
||||
});
|
||||
const appoint = await this.appointRepository.findOne({
|
||||
select: ["id", "topic", "status", "profileId"],
|
||||
where: { id },
|
||||
relations: ["directors"],
|
||||
})
|
||||
|
||||
return new HttpSuccess(appoint);
|
||||
}
|
||||
return new HttpSuccess(appoint)
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||
*
|
||||
* @summary แก้ไขการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
*/
|
||||
@Put("{id}")
|
||||
async Update(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body() requestBody: UpdateAppoint,
|
||||
@Path() id: string,
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||
/**
|
||||
* API แก้ไขการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||
*
|
||||
* @summary แก้ไขการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
*/
|
||||
@Put("{id}")
|
||||
async Update(@Request() request: RequestWithUser, @Body() requestBody: UpdateAppoint, @Path() id: string) {
|
||||
await new permission().PermissionUpdate(request, "SYS_PROBATION")
|
||||
|
||||
const appoint: any = await this.appointRepository.findOne({ where: { id } });
|
||||
const appoint: any = await this.appointRepository.findOne({ where: { id } })
|
||||
|
||||
if (!appoint) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ");
|
||||
}
|
||||
if (!appoint) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ")
|
||||
}
|
||||
|
||||
const before = appoint;
|
||||
const before = appoint
|
||||
|
||||
appoint.topic = requestBody.topic;
|
||||
appoint.updateUserId = request.user.sub;
|
||||
appoint.updateFullName = request.user.name;
|
||||
appoint.topic = requestBody.topic
|
||||
appoint.updateUserId = request.user.sub
|
||||
appoint.updateFullName = request.user.name
|
||||
await this.appointDirectorRepository.delete({ appointId: id })
|
||||
const directors: any = await requestBody.persons.map((x: Person) => ({
|
||||
...x,
|
||||
appointId: id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
}))
|
||||
await this.appointDirectorRepository.save(directors)
|
||||
|
||||
await this.appointDirectorRepository.delete({ appointId: id });
|
||||
const directors = await requestBody.persons.map((x: Person) => ({
|
||||
...x,
|
||||
appointId: id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
}));
|
||||
await this.appointDirectorRepository.save(directors);
|
||||
await this.appointRepository.save(appoint, { data: request })
|
||||
setLogDataDiff(request, { before, after: appoint })
|
||||
|
||||
await this.appointRepository.save(appoint, { data: request });
|
||||
setLogDataDiff(request, { before, after: appoint });
|
||||
return new HttpSuccess()
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
/**
|
||||
* API ลบรายการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
* @summary ลบรายการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
*/
|
||||
@Delete("{id}")
|
||||
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionDelete(request, "SYS_PROBATION")
|
||||
|
||||
/**
|
||||
* API ลบรายการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
* @summary ลบรายการแต่งตั้งคณะกรรมการฯ
|
||||
*
|
||||
*/
|
||||
@Delete("{id}")
|
||||
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionDelete(request, "SYS_PROBATION");
|
||||
await this.appointDirectorRepository.delete({ appointId: id })
|
||||
|
||||
await this.appointDirectorRepository.delete({ appointId: id });
|
||||
const result = await this.appointRepository.delete({ id })
|
||||
if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
||||
|
||||
const result = await this.appointRepository.delete({ id });
|
||||
if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
return new HttpSuccess()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -20,6 +20,7 @@ import { setLogDataDiff } from "../interfaces/utils";
|
|||
import { Personal, PostPersonal } from "../entities/Personal";
|
||||
import permission from "../interfaces/permission";
|
||||
import { Assign } from "../entities/Assign";
|
||||
import { Brackets } from "typeorm";
|
||||
|
||||
@Route("api/v1/probation/personal")
|
||||
@Tags("Personal")
|
||||
|
|
@ -101,6 +102,7 @@ export class PersonalController extends Controller {
|
|||
@Get("list")
|
||||
async ListPersonal(
|
||||
@Query() status: string = "",
|
||||
@Query() keyword: string = "",
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Request() request: RequestWithUser,
|
||||
|
|
@ -133,12 +135,39 @@ export class PersonalController extends Controller {
|
|||
conditions.child4 = _data.child4;
|
||||
}
|
||||
|
||||
const [lists, total] = await this.personalRepository.findAndCount({
|
||||
order: { createdAt: "DESC" },
|
||||
where: conditions,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
const searchKeyword = await (keyword ? keyword.trim() : null);
|
||||
|
||||
const [lists, total] = await AppDataSource.getRepository(Personal)
|
||||
.createQueryBuilder("personal")
|
||||
.where(conditions)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(
|
||||
searchKeyword
|
||||
? `CONCAT(prefixName, firstName," ",lastName) like '%${keyword}%'`
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${searchKeyword}%`,
|
||||
},
|
||||
);
|
||||
qb.orWhere(searchKeyword ? `positionName like '%${keyword}%'` : "1=1", {
|
||||
keyword: `%${searchKeyword}%`,
|
||||
});
|
||||
qb.orWhere(searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1", {
|
||||
keyword: `%${searchKeyword}%`,
|
||||
});
|
||||
qb.orWhere(searchKeyword ? `organization like '%${keyword}%'` : "1=1", {
|
||||
keyword: `%${searchKeyword}%`,
|
||||
});
|
||||
qb.orWhere(searchKeyword ? `order_number like '%${keyword}%'` : "1=1", {
|
||||
keyword: `%${searchKeyword}%`,
|
||||
});
|
||||
}),
|
||||
)
|
||||
.orderBy("updatedAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
if (!lists) {
|
||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้");
|
||||
|
|
@ -146,32 +175,54 @@ export class PersonalController extends Controller {
|
|||
|
||||
let result: any = [];
|
||||
|
||||
await Promise.all(
|
||||
lists.map(async (item, index) => {
|
||||
const probation_no = await this.assignRepository.count({
|
||||
where: {
|
||||
personal_id: item.personal_id,
|
||||
},
|
||||
});
|
||||
for (let i = 0; i < lists.length; i++) {
|
||||
const probation_no = await this.assignRepository.count({
|
||||
where: { personal_id: lists[i].personal_id },
|
||||
});
|
||||
|
||||
await result.push({
|
||||
personal_id: item.personal_id,
|
||||
ordering: index + 1,
|
||||
name: item.prefixName + item.firstName + " " + item.lastName,
|
||||
idcard: item.idcard,
|
||||
prefixName: item.prefixName,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position_line: item.positionName,
|
||||
position_level: item.positionLevelName,
|
||||
position_type: item.positionTypeName,
|
||||
organization: item.organization,
|
||||
probation_no: probation_no,
|
||||
order_number: item.order_number,
|
||||
probation_status: item.probation_status,
|
||||
});
|
||||
}),
|
||||
);
|
||||
await result.push({
|
||||
personal_id: lists[i].personal_id,
|
||||
ordering: i + 1,
|
||||
name: lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName,
|
||||
prefixName: lists[i].prefixName,
|
||||
firstName: lists[i].firstName,
|
||||
lastName: lists[i].lastName,
|
||||
idcard: lists[i].idcard,
|
||||
position_line: lists[i].positionName,
|
||||
position_level: lists[i].positionLevelName,
|
||||
position_type: lists[i].positionTypeName,
|
||||
organization: lists[i].organization,
|
||||
probation_no: probation_no,
|
||||
order_number: lists[i].order_number,
|
||||
probation_status: lists[i].probation_status,
|
||||
});
|
||||
}
|
||||
// await Promise.all(
|
||||
// lists.map(async (item, index) => {
|
||||
// const probation_no = await this.assignRepository.count({
|
||||
// where: {
|
||||
// personal_id: item.personal_id,
|
||||
// },
|
||||
// });
|
||||
|
||||
// await result.push({
|
||||
// personal_id: item.personal_id,
|
||||
// ordering: index + 1,
|
||||
// name: item.prefixName + item.firstName + " " + item.lastName,
|
||||
// idcard: item.idcard,
|
||||
// // prefixName: item.prefixName,
|
||||
// // firstName: item.firstName,
|
||||
// // lastName: item.lastName,
|
||||
// position_line: item.positionName,
|
||||
// position_level: item.positionLevelName,
|
||||
// position_type: item.positionTypeName,
|
||||
// organization: item.organization,
|
||||
// probation_no: probation_no,
|
||||
// order_number: item.order_number,
|
||||
// probation_status: item.probation_status,
|
||||
// });
|
||||
// }),
|
||||
// );
|
||||
|
||||
return new HttpSuccess({ data: result, total: total });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue