Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
db06615e5a
6 changed files with 123 additions and 19 deletions
|
|
@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success";
|
|||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { District, CreateDistrict, UpdateDistrict } from "../entities/District";
|
||||
import { Province } from "../entities/Province";
|
||||
import { Not } from "typeorm";
|
||||
|
||||
@Route("api/v1/org/metadata/district")
|
||||
|
|
@ -30,6 +31,7 @@ import { Not } from "typeorm";
|
|||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class DistrictController extends Controller {
|
||||
private districtRepository = AppDataSource.getRepository(District);
|
||||
private provinceRepository = AppDataSource.getRepository(Province);
|
||||
|
||||
/**
|
||||
* API list รายการเขต
|
||||
|
|
@ -84,6 +86,13 @@ export class DistrictController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
|
||||
}
|
||||
|
||||
const chkProvince = await this.provinceRepository.findOne({
|
||||
where: { id: requestBody.provinceId }
|
||||
})
|
||||
if(!chkProvince){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
|
||||
}
|
||||
|
||||
const checkName = await this.districtRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
});
|
||||
|
|
@ -118,6 +127,14 @@ export class DistrictController extends Controller {
|
|||
if (!_district) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
|
||||
}
|
||||
|
||||
const chkProvince = await this.provinceRepository.findOne({
|
||||
where: { id: requestBody.provinceId }
|
||||
})
|
||||
if(!chkProvince){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
|
||||
}
|
||||
|
||||
const checkName = await this.districtRepository.findOne({
|
||||
where: { id: Not(id), name: requestBody.name },
|
||||
});
|
||||
|
|
|
|||
|
|
@ -195,6 +195,33 @@ export class ProfileController extends Controller {
|
|||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
}
|
||||
|
||||
if (body.citizenId) {
|
||||
const citizenIdDigits = body.citizenId.toString().split("").map(Number);
|
||||
const cal =
|
||||
citizenIdDigits[0] * 13 +
|
||||
citizenIdDigits[1] * 12 +
|
||||
citizenIdDigits[2] * 11 +
|
||||
citizenIdDigits[3] * 10 +
|
||||
citizenIdDigits[4] * 9 +
|
||||
citizenIdDigits[5] * 8 +
|
||||
citizenIdDigits[6] * 7 +
|
||||
citizenIdDigits[7] * 6 +
|
||||
citizenIdDigits[8] * 5 +
|
||||
citizenIdDigits[9] * 4 +
|
||||
citizenIdDigits[10] * 3 +
|
||||
citizenIdDigits[11] * 2;
|
||||
const calStp2 = cal % 11;
|
||||
let chkDigit = 11 - calStp2;
|
||||
if(chkDigit === 10){
|
||||
chkDigit = 1;
|
||||
}else if(chkDigit === 11){
|
||||
chkDigit = cal % 10;
|
||||
}
|
||||
// if(chkDigit && citizenIdDigits[12] !== chkDigit){
|
||||
// throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
|
||||
// }
|
||||
}
|
||||
|
||||
if (body.citizenId && (await this.profileRepo.findOneBy({ citizenId: body.citizenId }))) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,33 @@ export class ProfileEmployeeController extends Controller {
|
|||
if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
}
|
||||
|
||||
if (body.citizenId) {
|
||||
const citizenIdDigits = body.citizenId.toString().split("").map(Number);
|
||||
const cal =
|
||||
citizenIdDigits[0] * 13 +
|
||||
citizenIdDigits[1] * 12 +
|
||||
citizenIdDigits[2] * 11 +
|
||||
citizenIdDigits[3] * 10 +
|
||||
citizenIdDigits[4] * 9 +
|
||||
citizenIdDigits[5] * 8 +
|
||||
citizenIdDigits[6] * 7 +
|
||||
citizenIdDigits[7] * 6 +
|
||||
citizenIdDigits[8] * 5 +
|
||||
citizenIdDigits[9] * 4 +
|
||||
citizenIdDigits[10] * 3 +
|
||||
citizenIdDigits[11] * 2;
|
||||
const calStp2 = cal % 11;
|
||||
let chkDigit = 11 - calStp2;
|
||||
if(chkDigit === 10){
|
||||
chkDigit = 1;
|
||||
}else if(chkDigit === 11){
|
||||
chkDigit = cal % 10;
|
||||
}
|
||||
// if(chkDigit && citizenIdDigits[12] !== chkDigit){
|
||||
// throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
|
||||
// }
|
||||
}
|
||||
|
||||
const profile = Object.assign(new ProfileEmployee(), body);
|
||||
profile.createdUserId = request.user.sub;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success";
|
|||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { SubDistrict, CreateSubDistrict, UpdateSubDistrict } from "../entities/SubDistrict";
|
||||
import { District } from "../entities/District";
|
||||
import { Not } from "typeorm";
|
||||
|
||||
@Route("api/v1/org/metadata/subDistrict")
|
||||
|
|
@ -30,11 +31,12 @@ import { Not } from "typeorm";
|
|||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class SubDistrictController extends Controller {
|
||||
private subDistrictRepository = AppDataSource.getRepository(SubDistrict);
|
||||
private districtRepository = AppDataSource.getRepository(District);
|
||||
|
||||
/**
|
||||
* API list รายการเพศ
|
||||
* API list รายการแขวง
|
||||
*
|
||||
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||
* @summary ORG_058 - CRUD แขวง (ADMIN) #62
|
||||
*
|
||||
*/
|
||||
@Get()
|
||||
|
|
@ -47,11 +49,11 @@ export class SubDistrictController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดรายการเพศ
|
||||
* API รายละเอียดรายการแขวง
|
||||
*
|
||||
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||
* @summary ORG_058 - CRUD แขวง (ADMIN) #62
|
||||
*
|
||||
* @param {string} id Id เพศ
|
||||
* @param {string} id Id แขวง
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetById(@Path() id: string) {
|
||||
|
|
@ -60,16 +62,16 @@ export class SubDistrictController extends Controller {
|
|||
select: ["id", "name"],
|
||||
});
|
||||
if (!_subDistrict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้");
|
||||
}
|
||||
|
||||
return new HttpSuccess(_subDistrict);
|
||||
}
|
||||
|
||||
/**
|
||||
* API สร้างรายการ body เพศ
|
||||
* API สร้างรายการ body แขวง
|
||||
*
|
||||
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||
* @summary ORG_058 - CRUD แขวง (ADMIN) #62
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
|
|
@ -80,11 +82,21 @@ export class SubDistrictController extends Controller {
|
|||
) {
|
||||
const _subDistrict = Object.assign(new SubDistrict(), requestBody);
|
||||
if (!_subDistrict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้");
|
||||
}
|
||||
|
||||
const chkDistrict = await this.districtRepository.findOne({
|
||||
where: { id: requestBody.districtId }
|
||||
})
|
||||
if (!chkDistrict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
|
||||
}
|
||||
|
||||
const checkName = await this.subDistrictRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
where: {
|
||||
name: requestBody.name,
|
||||
districtId: requestBody.districtId
|
||||
},
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
|
|
@ -100,11 +112,11 @@ export class SubDistrictController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขรายการ body เพศ
|
||||
* API แก้ไขรายการ body แขวง
|
||||
*
|
||||
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||
* @summary ORG_058 - CRUD แขวง (ADMIN) #62
|
||||
*
|
||||
* @param {string} id Id เพศ
|
||||
* @param {string} id Id แขวง
|
||||
*/
|
||||
@Put("{id}")
|
||||
async Put(
|
||||
|
|
@ -115,10 +127,22 @@ export class SubDistrictController extends Controller {
|
|||
) {
|
||||
const _subDistrict = await this.subDistrictRepository.findOne({ where: { id: id } });
|
||||
if (!_subDistrict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้");
|
||||
}
|
||||
|
||||
const chkDistrict = await this.districtRepository.findOne({
|
||||
where: { id: requestBody.districtId }
|
||||
})
|
||||
if (!chkDistrict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
|
||||
}
|
||||
|
||||
const checkName = await this.subDistrictRepository.findOne({
|
||||
where: { id: Not(id), name: requestBody.name },
|
||||
where: {
|
||||
id: Not(id),
|
||||
name: requestBody.name,
|
||||
districtId: requestBody.districtId
|
||||
},
|
||||
});
|
||||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
|
|
@ -132,11 +156,11 @@ export class SubDistrictController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* API ลบรายการเพศ
|
||||
* API ลบรายการแขวง
|
||||
*
|
||||
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||
* @summary ORG_058 - CRUD แขวง (ADMIN) #62
|
||||
*
|
||||
* @param {string} id Id เพศ
|
||||
* @param {string} id Id แขวง
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async Delete(@Path() id: string) {
|
||||
|
|
@ -144,7 +168,7 @@ export class SubDistrictController extends Controller {
|
|||
where: { id: id },
|
||||
});
|
||||
if (!_delSubDistrict) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางแขวงนี้");
|
||||
}
|
||||
await this.subDistrictRepository.delete(_delSubDistrict.id);
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ export class District extends EntityBase {
|
|||
export class CreateDistrict {
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
provinceId: string;
|
||||
}
|
||||
|
||||
export type UpdateDistrict = Partial<CreateDistrict>;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@ export class SubDistrict extends EntityBase {
|
|||
export class CreateSubDistrict {
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
districtId: string;
|
||||
|
||||
@Column()
|
||||
zipCode: string;
|
||||
}
|
||||
|
||||
export type UpdateSubDistrict = Partial<CreateSubDistrict>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue