updated appoint list by creator id
This commit is contained in:
parent
a9273a4cd1
commit
ad5c953aa8
1 changed files with 144 additions and 121 deletions
|
|
@ -1,151 +1,174 @@
|
||||||
import { Controller, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Put, Post, Path, Delete } from "tsoa"
|
import {
|
||||||
import { setLogDataDiff } from "../interfaces/utils"
|
Controller,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
Body,
|
||||||
|
Request,
|
||||||
|
SuccessResponse,
|
||||||
|
Response,
|
||||||
|
Get,
|
||||||
|
Put,
|
||||||
|
Post,
|
||||||
|
Path,
|
||||||
|
Delete,
|
||||||
|
} from "tsoa";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
|
||||||
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";
|
||||||
import HttpError from "../interfaces/http-error"
|
import HttpError from "../interfaces/http-error";
|
||||||
import permission from "../interfaces/permission"
|
import permission from "../interfaces/permission";
|
||||||
import { RequestWithUser } from "../middlewares/user"
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import { Appoint, CreateAppoint, Person, UpdateAppoint } from "../entities/Appoint"
|
import { Appoint, CreateAppoint, Person, UpdateAppoint } from "../entities/Appoint";
|
||||||
import { AppointDirector } from "../entities/AppointDirector"
|
import { AppointDirector } from "../entities/AppointDirector";
|
||||||
|
|
||||||
@Route("api/v1/probation/appoint")
|
@Route("api/v1/probation/appoint")
|
||||||
@Tags("Appoint Director")
|
@Tags("Appoint Director")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
export class AppointController extends Controller {
|
export class AppointController extends Controller {
|
||||||
private appointRepository = AppDataSource.getRepository(Appoint)
|
private appointRepository = AppDataSource.getRepository(Appoint);
|
||||||
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector)
|
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API รายการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
* API รายการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||||
*
|
*
|
||||||
* @summary รายการแต่งตั้งคณะกรรมการฯ
|
* @summary รายการแต่งตั้งคณะกรรมการฯ
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("")
|
@Get("")
|
||||||
async GetList(@Request() request: RequestWithUser) {
|
async GetList(@Request() request: RequestWithUser) {
|
||||||
await new permission().PermissionList(request, "SYS_PROBATION")
|
await new permission().PermissionList(request, "SYS_PROBATION");
|
||||||
|
|
||||||
const appoint = await this.appointRepository.find({})
|
const appoint = await this.appointRepository.find({
|
||||||
|
where: { createdUserId: request.user.sub },
|
||||||
|
});
|
||||||
|
|
||||||
return new HttpSuccess(appoint)
|
return new HttpSuccess(appoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API รายการแต่งตั้งคณะกรรมการฯ ที่ออกคำสั่งแล้วทดลองงาน
|
* API รายการแต่งตั้งคณะกรรมการฯ ที่ออกคำสั่งแล้วทดลองงาน
|
||||||
*
|
*
|
||||||
* @summary รายการแต่งตั้งคณะกรรมการฯ ที่ออกคำสั่งแล้ว
|
* @summary รายการแต่งตั้งคณะกรรมการฯ ที่ออกคำสั่งแล้ว
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("list/{id}")
|
@Get("list/{id}")
|
||||||
async GetListCommand(@Request() request: RequestWithUser, @Path() id: string) {
|
async GetListCommand(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
const appoint = await this.appointRepository.find({
|
const appoint = await this.appointRepository.find({
|
||||||
relations: ["directors"],
|
relations: ["directors"],
|
||||||
where: { profileId: id, status: "DONE" },
|
where: { profileId: id, status: "DONE" },
|
||||||
})
|
});
|
||||||
|
|
||||||
return new HttpSuccess(appoint)
|
return new HttpSuccess(appoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API สร้างการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
* API สร้างการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||||
*
|
*
|
||||||
* @summary สร้างการแต่งตั้งคณะกรรมการฯ
|
* @summary สร้างการแต่งตั้งคณะกรรมการฯ
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post("")
|
@Post("")
|
||||||
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
||||||
await new permission().PermissionCreate(request, "SYS_PROBATION")
|
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
||||||
|
|
||||||
const data: any = {
|
const data: any = {
|
||||||
topic: requestBody.topic,
|
topic: requestBody.topic,
|
||||||
profileId: requestBody.profileId,
|
profileId: requestBody.profileId,
|
||||||
createdUserId: request.user.sub,
|
createdUserId: request.user.sub,
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
}
|
};
|
||||||
const before = null
|
const before = null;
|
||||||
const appoint = await this.appointRepository.save(data, { data: request })
|
const appoint = await this.appointRepository.save(data, { data: request });
|
||||||
setLogDataDiff(request, { before, after: appoint })
|
setLogDataDiff(request, { before, after: appoint });
|
||||||
|
|
||||||
return new HttpSuccess(appoint.id)
|
return new HttpSuccess(appoint.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ
|
* API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ
|
||||||
*
|
*
|
||||||
* @summary API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ ตาม id
|
* @summary API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ ตาม id
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async GetById(@Request() request: RequestWithUser, @Path() id: string) {
|
async GetById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION")
|
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION");
|
||||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION")
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
|
|
||||||
const appoint = await this.appointRepository.findOne({
|
const appoint = await this.appointRepository.findOne({
|
||||||
select: ["id", "topic", "status", "profileId"],
|
select: ["id", "topic", "status", "profileId"],
|
||||||
where: { id },
|
where: { id },
|
||||||
relations: ["directors"],
|
relations: ["directors"],
|
||||||
})
|
});
|
||||||
|
|
||||||
return new HttpSuccess(appoint)
|
return new HttpSuccess(appoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API แก้ไขการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
* API แก้ไขการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||||
*
|
*
|
||||||
* @summary แก้ไขการแต่งตั้งคณะกรรมการฯ
|
* @summary แก้ไขการแต่งตั้งคณะกรรมการฯ
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Put("{id}")
|
@Put("{id}")
|
||||||
async Update(@Request() request: RequestWithUser, @Body() requestBody: UpdateAppoint, @Path() id: string) {
|
async Update(
|
||||||
await new permission().PermissionUpdate(request, "SYS_PROBATION")
|
@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) {
|
if (!appoint) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ")
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ");
|
||||||
}
|
}
|
||||||
|
|
||||||
const before = appoint
|
const before = appoint;
|
||||||
|
|
||||||
appoint.topic = requestBody.topic
|
appoint.topic = requestBody.topic;
|
||||||
appoint.updateUserId = request.user.sub
|
appoint.updateUserId = request.user.sub;
|
||||||
appoint.updateFullName = request.user.name
|
appoint.updateFullName = request.user.name;
|
||||||
|
|
||||||
await this.appointDirectorRepository.delete({ appointId: id })
|
await this.appointDirectorRepository.delete({ appointId: id });
|
||||||
const directors = await requestBody.persons.map((x: Person) => ({
|
const directors = await requestBody.persons.map((x: Person) => ({
|
||||||
...x,
|
...x,
|
||||||
appointId: id,
|
appointId: id,
|
||||||
createdUserId: request.user.sub,
|
createdUserId: request.user.sub,
|
||||||
createdFullName: request.user.name,
|
createdFullName: request.user.name,
|
||||||
updateUserId: request.user.sub,
|
updateUserId: request.user.sub,
|
||||||
updateFullName: request.user.name,
|
updateFullName: request.user.name,
|
||||||
}))
|
}));
|
||||||
await this.appointDirectorRepository.save(directors)
|
await this.appointDirectorRepository.save(directors);
|
||||||
|
|
||||||
await this.appointRepository.save(appoint, { data: request })
|
await this.appointRepository.save(appoint, { data: request });
|
||||||
setLogDataDiff(request, { before, after: appoint })
|
setLogDataDiff(request, { before, after: appoint });
|
||||||
|
|
||||||
return new HttpSuccess()
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API ลบรายการแต่งตั้งคณะกรรมการฯ
|
* API ลบรายการแต่งตั้งคณะกรรมการฯ
|
||||||
*
|
*
|
||||||
* @summary ลบรายการแต่งตั้งคณะกรรมการฯ
|
* @summary ลบรายการแต่งตั้งคณะกรรมการฯ
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
|
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
await new permission().PermissionDelete(request, "SYS_PROBATION")
|
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 })
|
const result = await this.appointRepository.delete({ id });
|
||||||
if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
return new HttpSuccess()
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue