rank
This commit is contained in:
parent
065d0fd7e5
commit
93373bc00f
4 changed files with 178 additions and 3 deletions
|
|
@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { CreateEducationLevel, EducationLevel } from "../entities/EducationLevel";
|
import { CreateEducationLevel, EducationLevel } from "../entities/EducationLevel";
|
||||||
|
import { Not } from "typeorm";
|
||||||
@Route("api/v1/org/educationLevel")
|
@Route("api/v1/org/educationLevel")
|
||||||
@Tags("EducationLevel")
|
@Tags("EducationLevel")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -82,7 +83,7 @@ export class EducationLevelController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkName = await this.educationLevelRepository.findOne({
|
const checkName = await this.educationLevelRepository.findOne({
|
||||||
where: { name: requestBody.name },
|
where: { id:Not(id),name: requestBody.name },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (checkName) {
|
if (checkName) {
|
||||||
|
|
|
||||||
172
src/controllers/RankController.ts
Normal file
172
src/controllers/RankController.ts
Normal file
|
|
@ -0,0 +1,172 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
Body,
|
||||||
|
Path,
|
||||||
|
Request,
|
||||||
|
SuccessResponse,
|
||||||
|
Response,
|
||||||
|
Get,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import { CreateRank, Rank } from "../entities/Rank";
|
||||||
|
import { Not } from "typeorm";
|
||||||
|
@Route("api/v1/org/rank")
|
||||||
|
@Tags("Rank")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
|
export class RankController extends Controller {
|
||||||
|
private rankRepository = AppDataSource.getRepository(Rank);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - สร้างยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post()
|
||||||
|
async createRank(
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateRank,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const checkName = await this.rankRepository.findOne({
|
||||||
|
where: { name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const rank = Object.assign(new Rank(), requestBody);
|
||||||
|
rank.createdUserId = request.user.sub;
|
||||||
|
rank.createdFullName = request.user.name;
|
||||||
|
rank.lastUpdateUserId = request.user.sub;
|
||||||
|
rank.lastUpdateFullName = request.user.name;
|
||||||
|
await this.rankRepository.save(rank);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - แก้ไขยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ยศ
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
async updateRank(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateRank,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const rank = await this.rankRepository.findOne({ where: { id: id } });
|
||||||
|
if (!rank) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkName = await this.rankRepository.findOne({
|
||||||
|
where: { id:Not(id),name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
rank.lastUpdateUserId = request.user.sub;
|
||||||
|
rank.lastUpdateFullName = request.user.name;
|
||||||
|
this.rankRepository.merge(rank, requestBody);
|
||||||
|
await this.rankRepository.save(rank);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ลบยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - ลบยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ยศ
|
||||||
|
*/
|
||||||
|
@Delete("{id}")
|
||||||
|
async deleteRank(@Path() id: string) {
|
||||||
|
const delRank = await this.rankRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
if (!delRank) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.rankRepository.delete({ id: id });
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายละเอียดรายการยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - รายละเอียดรายการยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ยศ
|
||||||
|
*/
|
||||||
|
@Get("{id}")
|
||||||
|
async detailRank(@Path() id: string) {
|
||||||
|
const rank = await this.rankRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
select: ["id", "name"],
|
||||||
|
});
|
||||||
|
if (!rank) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(rank);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายการยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - รายการยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get()
|
||||||
|
async listRank() {
|
||||||
|
const rank = await this.rankRepository.find({
|
||||||
|
select: ["id", "name" ],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!rank) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(rank);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { CreateRelationship, Relationship } from "../entities/Relationship";
|
import { CreateRelationship, Relationship } from "../entities/Relationship";
|
||||||
|
import { Not } from "typeorm";
|
||||||
@Route("api/v1/org/relationship")
|
@Route("api/v1/org/relationship")
|
||||||
@Tags("Relationship")
|
@Tags("Relationship")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -82,7 +83,7 @@ export class RelationshipController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkName = await this.relationshipRepository.findOne({
|
const checkName = await this.relationshipRepository.findOne({
|
||||||
where: { name: requestBody.name },
|
where: {id:Not(id),name: requestBody.name },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (checkName) {
|
if (checkName) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { CreateReligion, Religion } from "../entities/Religion";
|
import { CreateReligion, Religion } from "../entities/Religion";
|
||||||
|
import { Not } from "typeorm";
|
||||||
@Route("api/v1/org/religion")
|
@Route("api/v1/org/religion")
|
||||||
@Tags("Religion")
|
@Tags("Religion")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -82,7 +83,7 @@ export class ReligionController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkName = await this.religionRepository.findOne({
|
const checkName = await this.religionRepository.findOne({
|
||||||
where: { name: requestBody.name },
|
where: { id:Not(id),name: requestBody.name },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (checkName) {
|
if (checkName) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue