#migrate add ssues
This commit is contained in:
parent
64a7010d0a
commit
dd01e2a79d
3 changed files with 186 additions and 0 deletions
60
src/controllers/IssuesController.ts
Normal file
60
src/controllers/IssuesController.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Response,
|
||||
} from "tsoa";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Issues, CreateIssueRequest, UpdateIssueRequest } from "../entities/Issues";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
||||
@Route("api/v1/org/issues")
|
||||
@Tags("issues")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
export class IssuesController extends Controller {
|
||||
private issuesRepository = AppDataSource.getRepository(Issues);
|
||||
|
||||
@Get("lists")
|
||||
async getIssues() {
|
||||
const issues = await this.issuesRepository.find({
|
||||
order: {
|
||||
createdAt: "DESC",
|
||||
},
|
||||
});
|
||||
return new HttpSuccess(issues);
|
||||
}
|
||||
|
||||
@Post("")
|
||||
async createIssue(@Body() requestBody: CreateIssueRequest) {
|
||||
let issue = this.issuesRepository.create(requestBody);
|
||||
|
||||
await this.issuesRepository.save(issue);
|
||||
|
||||
return new HttpSuccess(issue);
|
||||
}
|
||||
|
||||
@Put("{id}")
|
||||
async updateIssue(@Path("id") id: string, @Body() requestBody: Partial<UpdateIssueRequest>) {
|
||||
let issue = await this.issuesRepository.findOneBy({ id });
|
||||
if (!issue) {
|
||||
this.setStatus(HttpStatusCode.NOT_FOUND);
|
||||
return { message: "ไม่พบข้อมูลที่ต้องการแก้ไข" };
|
||||
}
|
||||
Object.assign(issue, requestBody);
|
||||
await this.issuesRepository.save(issue);
|
||||
return new HttpSuccess(issue);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue