hrms-api-probation/src/controllers/SurveyController.ts

48 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-10-18 09:56:01 +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 13:59:43 +07:00
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")
2024-10-18 09:56:01 +07:00
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
2024-09-05 13:59:43 +07:00
export class SurveyController extends Controller {
2024-10-18 09:56:01 +07:00
private surveyRepository = AppDataSource.getRepository(Survey)
2024-09-05 13:59:43 +07:00
2024-10-18 09:56:01 +07:00
/**
* API
*
* @summary
*
*/
@Get("")
async GetSurvey(@Query() assign_id: string) {
const data = await this.surveyRepository.findOne({
where: {
assign_id,
},
})
return new HttpSuccess(data)
}
2024-09-05 13:59:43 +07:00
2024-10-18 09:56:01 +07:00
/**
* 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 })
2024-09-05 13:59:43 +07:00
2024-10-18 09:56:01 +07:00
return new HttpSuccess()
}
2024-09-05 13:59:43 +07:00
}