แก้pathข้อมูลบุคคล
This commit is contained in:
parent
c22d33fa60
commit
4c67904018
8 changed files with 367 additions and 369 deletions
172
src/controllers/BloodGroupController.ts
Normal file
172
src/controllers/BloodGroupController.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 { CreateBloodGroup, BloodGroup } from "../entities/BloodGroup";
|
||||
import { Not } from "typeorm";
|
||||
@Route("api/v1/org/metadata/bloodGroup")
|
||||
@Tags("BloodGroup")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class BloodGroupController extends Controller {
|
||||
private bloodGroupRepository = AppDataSource.getRepository(BloodGroup);
|
||||
|
||||
/**
|
||||
* API สร้างกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - สร้างกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
async createBloodGroup(
|
||||
@Body()
|
||||
requestBody: CreateBloodGroup,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const checkName = await this.bloodGroupRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
const bloodGroup = Object.assign(new BloodGroup(), requestBody);
|
||||
bloodGroup.createdUserId = request.user.sub;
|
||||
bloodGroup.createdFullName = request.user.name;
|
||||
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||
bloodGroup.lastUpdateFullName = request.user.name;
|
||||
await this.bloodGroupRepository.save(bloodGroup);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - แก้ไขกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
* @param {string} id Id กลุ่มเลือด
|
||||
*/
|
||||
@Put("{id}")
|
||||
async updateBloodGroup(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateBloodGroup,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const bloodGroup = await this.bloodGroupRepository.findOne({ where: { id: id } });
|
||||
if (!bloodGroup) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
|
||||
const checkName = await this.bloodGroupRepository.findOne({
|
||||
where: { id: Not(id), name: requestBody.name },
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||
bloodGroup.lastUpdateFullName = request.user.name;
|
||||
this.bloodGroupRepository.merge(bloodGroup, requestBody);
|
||||
await this.bloodGroupRepository.save(bloodGroup);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - ลบกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
* @param {string} id Id กลุ่มเลือด
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteBloodGroup(@Path() id: string) {
|
||||
const delBloodGroup = await this.bloodGroupRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!delBloodGroup) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.bloodGroupRepository.delete({ id: id });
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดรายการกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - รายละเอียดรายการกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
* @param {string} id Id กลุ่มเลือด
|
||||
*/
|
||||
@Get("{id}")
|
||||
async detailBloodGroup(@Path() id: string) {
|
||||
const bloodGroup = await this.bloodGroupRepository.findOne({
|
||||
where: { id },
|
||||
select: ["id", "name"],
|
||||
});
|
||||
if (!bloodGroup) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(bloodGroup);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - รายการกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
*/
|
||||
@Get()
|
||||
async listBloodGroup() {
|
||||
const bloodGroup = await this.bloodGroupRepository.find({
|
||||
select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
|
||||
if (!bloodGroup) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(bloodGroup);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateEducationLevel, EducationLevel } from "../entities/EducationLevel";
|
||||
import { Not } from "typeorm";
|
||||
@Route("api/v1/org/educationLevel")
|
||||
@Route("api/v1/org/metadata/educationLevel")
|
||||
@Tags("EducationLevel")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
|
|
@ -83,7 +83,7 @@ export class EducationLevelController extends Controller {
|
|||
}
|
||||
|
||||
const checkName = await this.educationLevelRepository.findOne({
|
||||
where: { id:Not(id),name: requestBody.name },
|
||||
where: { id: Not(id), name: requestBody.name },
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
|
|
@ -135,7 +135,7 @@ export class EducationLevelController extends Controller {
|
|||
async detailEducationLevel(@Path() id: string) {
|
||||
const educationLevel = await this.educationLevelRepository.findOne({
|
||||
where: { id },
|
||||
select: ["id", "name" ,"rank"],
|
||||
select: ["id", "name", "rank"],
|
||||
});
|
||||
if (!educationLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -156,10 +156,10 @@ export class EducationLevelController extends Controller {
|
|||
@Get()
|
||||
async listEducationLevel() {
|
||||
const educationLevel = await this.educationLevelRepository.find({
|
||||
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
|
||||
order:{ createdAt:"ASC" }
|
||||
select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
|
||||
|
||||
if (!educationLevel) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ import HttpError from "../interfaces/http-error";
|
|||
import { Gender, CreateGender, UpdateGender } from "../entities/Gender";
|
||||
import { Not } from "typeorm";
|
||||
|
||||
@Route("api/v1/org/gender")
|
||||
@Route("api/v1/org/metadata/gender")
|
||||
@Tags("Gender")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
|
|
@ -39,10 +39,10 @@ export class GenderController extends Controller {
|
|||
*/
|
||||
@Get()
|
||||
async GetResult() {
|
||||
console.log("asds")
|
||||
console.log("asds");
|
||||
const _gender = await this.genderRepository.find({
|
||||
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
|
||||
order:{ createdAt:"ASC" }
|
||||
select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
if (!_gender) {
|
||||
return new HttpSuccess([]);
|
||||
|
|
@ -50,7 +50,7 @@ export class GenderController extends Controller {
|
|||
try {
|
||||
return new HttpSuccess(_gender);
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
console.log(error);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
|
@ -152,11 +152,11 @@ export class GenderController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* API ลบรายการเพศ
|
||||
* API ลบรายการเพศ
|
||||
*
|
||||
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||
*
|
||||
* @param {string} id Id เพศ
|
||||
* @param {string} id Id เพศ
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async Delete(@Path() id: string) {
|
||||
|
|
@ -1,173 +0,0 @@
|
|||
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 { CreateBloodGroup, BloodGroup } from "../entities/BloodGroup";
|
||||
import { Not } from "typeorm";
|
||||
@Route("api/v1/org/bloodGroup")
|
||||
@Tags("BloodGroup")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class BloodGroupController extends Controller {
|
||||
private bloodGroupRepository = AppDataSource.getRepository(BloodGroup);
|
||||
|
||||
/**
|
||||
* API สร้างกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - สร้างกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
async createBloodGroup(
|
||||
@Body()
|
||||
requestBody: CreateBloodGroup,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const checkName = await this.bloodGroupRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
const bloodGroup = Object.assign(new BloodGroup(), requestBody);
|
||||
bloodGroup.createdUserId = request.user.sub;
|
||||
bloodGroup.createdFullName = request.user.name;
|
||||
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||
bloodGroup.lastUpdateFullName = request.user.name;
|
||||
await this.bloodGroupRepository.save(bloodGroup);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - แก้ไขกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
* @param {string} id Id กลุ่มเลือด
|
||||
*/
|
||||
@Put("{id}")
|
||||
async updateBloodGroup(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateBloodGroup,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const bloodGroup = await this.bloodGroupRepository.findOne({ where: { id: id } });
|
||||
if (!bloodGroup) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
|
||||
const checkName = await this.bloodGroupRepository.findOne({
|
||||
where: { id:Not(id),name: requestBody.name },
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||
bloodGroup.lastUpdateFullName = request.user.name;
|
||||
this.bloodGroupRepository.merge(bloodGroup, requestBody);
|
||||
await this.bloodGroupRepository.save(bloodGroup);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - ลบกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
* @param {string} id Id กลุ่มเลือด
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteBloodGroup(@Path() id: string) {
|
||||
const delBloodGroup = await this.bloodGroupRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!delBloodGroup) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.bloodGroupRepository.delete({ id: id });
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดรายการกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - รายละเอียดรายการกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
* @param {string} id Id กลุ่มเลือด
|
||||
*/
|
||||
@Get("{id}")
|
||||
async detailBloodGroup(@Path() id: string) {
|
||||
const bloodGroup = await this.bloodGroupRepository.findOne({
|
||||
where: { id },
|
||||
select: ["id", "name"],
|
||||
});
|
||||
if (!bloodGroup) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(bloodGroup);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการกลุ่มเลือด
|
||||
*
|
||||
* @summary ORG_062 - รายการกลุ่มเลือด (ADMIN) #66
|
||||
*
|
||||
*/
|
||||
@Get()
|
||||
async listBloodGroup() {
|
||||
const bloodGroup = await this.bloodGroupRepository.find({
|
||||
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
|
||||
order:{ createdAt:"ASC" }
|
||||
});
|
||||
|
||||
if (!bloodGroup) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(bloodGroup);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ import HttpError from "../interfaces/http-error";
|
|||
import { Prefixe, CreatePrefixe, UpdatePrefixe } from "../entities/Prefixe";
|
||||
import { Not } from "typeorm";
|
||||
|
||||
@Route("api/v1/org/prefix")
|
||||
@Route("api/v1/org/metadata/prefix")
|
||||
@Tags("Prefix")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
|
|
@ -40,8 +40,8 @@ export class PrefixController extends Controller {
|
|||
@Get()
|
||||
async Get() {
|
||||
const _prefix = await this.prefixRepository.find({
|
||||
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"] ,
|
||||
order:{ createdAt:"ASC" }
|
||||
select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
if (!_prefix) {
|
||||
return new HttpSuccess([]);
|
||||
|
|
@ -150,11 +150,11 @@ export class PrefixController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* API ลบรายการคำนำหน้า
|
||||
* API ลบรายการคำนำหน้า
|
||||
*
|
||||
* @summary ORG_056 - CRUD คำนำหน้า (ADMIN) #61
|
||||
*
|
||||
* @param {string} id Id คำนำหน้า
|
||||
* @param {string} id Id คำนำหน้า
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async Delete(@Path() id: string) {
|
||||
|
|
|
|||
|
|
@ -1,173 +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;
|
||||
}
|
||||
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/metadata/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, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
|
||||
order:{ createdAt:"ASC" }
|
||||
});
|
||||
|
||||
if (!rank) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(rank);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
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", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
|
||||
if (!rank) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(rank);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateRelationship, Relationship } from "../entities/Relationship";
|
||||
import { Not } from "typeorm";
|
||||
@Route("api/v1/org/relationship")
|
||||
@Route("api/v1/org/metadata/relationship")
|
||||
@Tags("Relationship")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
|
|
@ -83,7 +83,7 @@ export class RelationshipController extends Controller {
|
|||
}
|
||||
|
||||
const checkName = await this.relationshipRepository.findOne({
|
||||
where: {id:Not(id),name: requestBody.name },
|
||||
where: { id: Not(id), name: requestBody.name },
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
|
|
@ -156,8 +156,8 @@ export class RelationshipController extends Controller {
|
|||
@Get()
|
||||
async listRelationship() {
|
||||
const relationship = await this.relationshipRepository.find({
|
||||
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
|
||||
order:{ createdAt:"ASC" }
|
||||
select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
if (!relationship) {
|
||||
return new HttpSuccess([]);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateReligion, Religion } from "../entities/Religion";
|
||||
import { Not } from "typeorm";
|
||||
@Route("api/v1/org/religion")
|
||||
@Route("api/v1/org/metadata/religion")
|
||||
@Tags("Religion")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
|
|
@ -83,7 +83,7 @@ export class ReligionController extends Controller {
|
|||
}
|
||||
|
||||
const checkName = await this.religionRepository.findOne({
|
||||
where: { id:Not(id),name: requestBody.name },
|
||||
where: { id: Not(id), name: requestBody.name },
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
|
|
@ -156,10 +156,10 @@ export class ReligionController extends Controller {
|
|||
@Get()
|
||||
async listReligion() {
|
||||
const religion = await this.religionRepository.find({
|
||||
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
|
||||
order:{ createdAt:"ASC" }
|
||||
select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
|
||||
|
||||
if (!religion) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue