start project
This commit is contained in:
commit
0703810fa3
62 changed files with 12665 additions and 0 deletions
70
src/controllers/SurveyController.ts
Normal file
70
src/controllers/SurveyController.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
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";
|
||||
|
||||
@Route("api/v1/survey")
|
||||
@Tags("Survey")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class SurveyController extends Controller {
|
||||
private surveyRepository = AppDataSource.getRepository(Survey);
|
||||
|
||||
/**
|
||||
* API แบบสำรวจความคิดเห็น
|
||||
*
|
||||
* @summary แบบสำรวจความคิดเห็น
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetSurvey(
|
||||
@Query() assign_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
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,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue