add check commander
This commit is contained in:
parent
673fbbfa94
commit
6d6cdc047b
1 changed files with 41 additions and 31 deletions
|
|
@ -22,13 +22,9 @@ 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 {
|
import { Appoint, CreateAppoint, Person, UpdateAppoint } from "../entities/Appoint";
|
||||||
Appoint,
|
|
||||||
CreateAppoint,
|
|
||||||
Person,
|
|
||||||
UpdateAppoint,
|
|
||||||
} from "../entities/Appoint";
|
|
||||||
import { AppointDirector } from "../entities/AppointDirector";
|
import { AppointDirector } from "../entities/AppointDirector";
|
||||||
|
import CallAPI from "../interfaces/call-api";
|
||||||
|
|
||||||
@Route("api/v1/probation/appoint")
|
@Route("api/v1/probation/appoint")
|
||||||
@Tags("Appoint Director")
|
@Tags("Appoint Director")
|
||||||
|
|
@ -39,8 +35,7 @@ import { AppointDirector } from "../entities/AppointDirector";
|
||||||
)
|
)
|
||||||
export class AppointController extends Controller {
|
export class AppointController extends Controller {
|
||||||
private appointRepository = AppDataSource.getRepository(Appoint);
|
private appointRepository = AppDataSource.getRepository(Appoint);
|
||||||
private appointDirectorRepository =
|
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector);
|
||||||
AppDataSource.getRepository(AppointDirector);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API รายการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
* API รายการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||||
|
|
@ -96,10 +91,7 @@ export class AppointController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("list/{id}")
|
@Get("list/{id}")
|
||||||
async GetListCommand(
|
async GetListCommand(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
@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" },
|
||||||
|
|
@ -115,10 +107,7 @@ export class AppointController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post("")
|
@Post("")
|
||||||
async Create(
|
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
||||||
@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 = {
|
||||||
|
|
@ -142,13 +131,8 @@ export class AppointController extends Controller {
|
||||||
*/
|
*/
|
||||||
@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(
|
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION");
|
||||||
request,
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
id,
|
|
||||||
"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"],
|
||||||
|
|
@ -178,10 +162,7 @@ export class AppointController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!appoint) {
|
if (!appoint) {
|
||||||
throw new HttpError(
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ");
|
||||||
HttpStatusCode.NOT_FOUND,
|
|
||||||
"ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const before = appoint;
|
const before = appoint;
|
||||||
|
|
@ -213,10 +194,7 @@ export class AppointController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
public async deleteRole(
|
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
@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 });
|
||||||
|
|
@ -226,4 +204,36 @@ export class AppointController extends Controller {
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ
|
||||||
|
*
|
||||||
|
* @summary API ดึงข้อมูลแต่งตั้งคณะกรรมการฯ ตาม id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("/committee/{profileId}")
|
||||||
|
async GetCheckById(@Request() request: RequestWithUser, @Path() profileId: string) {
|
||||||
|
await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
|
|
||||||
|
const directorId = await new CallAPI()
|
||||||
|
.GetData(request, "/org/profile/keycloak")
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error calling API:", error);
|
||||||
|
});
|
||||||
|
|
||||||
|
const appoint = await AppDataSource.getRepository(Appoint)
|
||||||
|
.createQueryBuilder("appoint")
|
||||||
|
.leftJoinAndSelect("appoint.directors", "directors")
|
||||||
|
.where(
|
||||||
|
"appoint.profileId = :profileId and directors.profileId = :directorId and directors.role = 'committee'",
|
||||||
|
{
|
||||||
|
directorId,
|
||||||
|
profileId,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.orderBy("appoint.createdAt", "DESC")
|
||||||
|
.getOne();
|
||||||
|
const check = appoint ? true : false;
|
||||||
|
return new HttpSuccess(check);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue