Assign Survey
This commit is contained in:
parent
51a6453f39
commit
114a27c5e6
2 changed files with 82 additions and 39 deletions
|
|
@ -29,7 +29,7 @@ export class AssignPermissionsController extends Controller {
|
|||
console.error("Error calling API:", error);
|
||||
});
|
||||
|
||||
const role = director.find((e: any) => e.role === personalId)?.role;
|
||||
const role = director.find((e: any) => e.personal_id === personalId)?.role;
|
||||
|
||||
const reportPersonId = await this.assignRepository.findOneBy({
|
||||
reportPersonId: personalId,
|
||||
|
|
|
|||
|
|
@ -1,47 +1,90 @@
|
|||
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Post, Body, Query } from "tsoa"
|
||||
import HttpSuccess from "../interfaces/http-success"
|
||||
import HttpStatusCode from "../interfaces/http-status"
|
||||
import { RequestWithUser } from "../middlewares/user"
|
||||
import { setLogDataDiff } from "../interfaces/utils"
|
||||
import { Survey } from "../entities/Survey"
|
||||
import { AppDataSource } from "../database/data-source"
|
||||
import {
|
||||
Controller,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { Survey } from "../entities/Survey";
|
||||
import { Assign } from "../entities/Assign";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
|
||||
@Route("api/v1/probation/survey")
|
||||
@Tags("Survey")
|
||||
@Security("bearerAuth")
|
||||
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
export class SurveyController extends Controller {
|
||||
private surveyRepository = AppDataSource.getRepository(Survey)
|
||||
private surveyRepository = AppDataSource.getRepository(Survey);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
|
||||
/**
|
||||
* API แบบสำรวจความคิดเห็น
|
||||
*
|
||||
* @summary แบบสำรวจความคิดเห็น
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetSurvey(@Query() assign_id: string) {
|
||||
const data = await this.surveyRepository.findOne({
|
||||
where: {
|
||||
assign_id,
|
||||
},
|
||||
})
|
||||
return new HttpSuccess(data)
|
||||
}
|
||||
/**
|
||||
* API แบบสำรวจความคิดเห็น
|
||||
*
|
||||
* @summary แบบสำรวจความคิดเห็น
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetSurvey(@Request() request: RequestWithUser) {
|
||||
const personalId = await new CallAPI()
|
||||
.GetData(request, "/org/profile/keycloak")
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
|
||||
/**
|
||||
* API บันทึกแบบสำรวจความคิดเห็น
|
||||
*
|
||||
* @summary บันทึกแบบสำรวจความคิดเห็น
|
||||
*
|
||||
*/
|
||||
@Post("")
|
||||
async PostSurvey(@Query() assign_id: string, @Body() requestBody: any, @Request() request: RequestWithUser) {
|
||||
const before = null
|
||||
const data = await { ...requestBody, personal_id: request.user.sub, assign_id }
|
||||
await this.surveyRepository.save(data, { data: request })
|
||||
setLogDataDiff(request, { before, after: data })
|
||||
const dataAssign = await this.assignRepository.findOne({
|
||||
select: ["id"],
|
||||
where: { personal_id: personalId },
|
||||
order: { date_start: "DESC" },
|
||||
});
|
||||
if (!dataAssign) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทดลองงาน");
|
||||
}
|
||||
const assign_id = dataAssign.id;
|
||||
|
||||
return new HttpSuccess()
|
||||
}
|
||||
const data = await this.surveyRepository.findOne({
|
||||
where: {
|
||||
assign_id,
|
||||
},
|
||||
});
|
||||
return new HttpSuccess({ data: data, assignId: assign_id });
|
||||
}
|
||||
|
||||
/**
|
||||
* API บันทึกแบบสำรวจความคิดเห็น
|
||||
*
|
||||
* @summary บันทึกแบบสำรวจความคิดเห็น
|
||||
*
|
||||
*/
|
||||
@Post("")
|
||||
async PostSurvey(
|
||||
@Query() assign_id: string,
|
||||
@Body() requestBody: any,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const before = null;
|
||||
const data = await {
|
||||
...requestBody,
|
||||
personal_id: request.user.sub,
|
||||
assign_id,
|
||||
};
|
||||
await this.surveyRepository.save(data, { data: request });
|
||||
setLogDataDiff(request, { before, after: data });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue