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 permission from "../interfaces/permission";
|
||||
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 CallAPI from "../interfaces/call-api";
|
||||
|
||||
@Route("api/v1/probation/appoint")
|
||||
@Tags("Appoint Director")
|
||||
|
|
@ -39,8 +35,7 @@ import { AppointDirector } from "../entities/AppointDirector";
|
|||
)
|
||||
export class AppointController extends Controller {
|
||||
private appointRepository = AppDataSource.getRepository(Appoint);
|
||||
private appointDirectorRepository =
|
||||
AppDataSource.getRepository(AppointDirector);
|
||||
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector);
|
||||
|
||||
/**
|
||||
* API รายการแต่งตั้งคณะกรรมการฯ ทดลองงาน
|
||||
|
|
@ -96,10 +91,7 @@ export class AppointController extends Controller {
|
|||
*
|
||||
*/
|
||||
@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({
|
||||
relations: ["directors"],
|
||||
where: { profileId: id, status: "DONE" },
|
||||
|
|
@ -115,10 +107,7 @@ export class AppointController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Post("")
|
||||
async Create(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body() requestBody: CreateAppoint,
|
||||
) {
|
||||
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
||||
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
||||
|
||||
const data: any = {
|
||||
|
|
@ -142,13 +131,8 @@ export class AppointController extends Controller {
|
|||
*/
|
||||
@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");
|
||||
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"],
|
||||
|
|
@ -178,10 +162,7 @@ export class AppointController extends Controller {
|
|||
});
|
||||
|
||||
if (!appoint) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ",
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ");
|
||||
}
|
||||
|
||||
const before = appoint;
|
||||
|
|
@ -213,10 +194,7 @@ export class AppointController extends Controller {
|
|||
*
|
||||
*/
|
||||
@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 this.appointDirectorRepository.delete({ appointId: id });
|
||||
|
|
@ -226,4 +204,36 @@ export class AppointController extends Controller {
|
|||
|
||||
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