2024-09-05 13:59:43 +07:00
|
|
|
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";
|
|
|
|
|
|
2024-09-05 16:56:22 +07:00
|
|
|
@Route("api/v1/probation/survey")
|
2024-09-05 13:59:43 +07:00
|
|
|
@Tags("Survey")
|
|
|
|
|
@Security("bearerAuth")
|
|
|
|
|
@Response(
|
|
|
|
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
2024-09-05 16:56:22 +07:00
|
|
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
2024-09-05 13:59:43 +07:00
|
|
|
)
|
|
|
|
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
|
|
|
|
export class SurveyController extends Controller {
|
|
|
|
|
private surveyRepository = AppDataSource.getRepository(Survey);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API แบบสำรวจความคิดเห็น
|
|
|
|
|
*
|
|
|
|
|
* @summary แบบสำรวจความคิดเห็น
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Get("")
|
2024-09-05 16:56:22 +07:00
|
|
|
async GetSurvey(@Query() assign_id: string, @Request() request: RequestWithUser) {
|
2024-09-05 13:59:43 +07:00
|
|
|
const result = await this.surveyRepository.findOne({
|
|
|
|
|
where: {
|
|
|
|
|
assign_id,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return new HttpSuccess(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API บันทึกแบบสำรวจความคิดเห็น
|
|
|
|
|
*
|
|
|
|
|
* @summary บันทึกแบบสำรวจความคิดเห็น
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Post("")
|
|
|
|
|
async PostSurvey(
|
|
|
|
|
@Query() assign_id: string,
|
|
|
|
|
@Body() requestBody: any,
|
2024-09-05 16:56:22 +07:00
|
|
|
@Request() request: RequestWithUser,
|
2024-09-05 13:59:43 +07:00
|
|
|
) {
|
|
|
|
|
const before = null;
|
|
|
|
|
const data = await { ...requestBody, personal_id: request.user.sub };
|
|
|
|
|
await this.surveyRepository.save(data, { data: request });
|
|
|
|
|
setLogDataDiff(request, { before, after: data });
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess(data);
|
|
|
|
|
}
|
|
|
|
|
}
|