Merge branch 'develop' into adiDev
This commit is contained in:
commit
a6f575bff3
22 changed files with 1298 additions and 152 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 },
|
||||
});
|
||||
|
|
|
|||
117
src/controllers/ProfileChildrenController.ts
Normal file
117
src/controllers/ProfileChildrenController.ts
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import {
|
||||
CreateProfileChildren,
|
||||
ProfileChildren,
|
||||
UpdateProfileChildren,
|
||||
} from "../entities/ProfileChildren";
|
||||
|
||||
@Route("api/v1/org/profile/children")
|
||||
@Tags("ProfileChildren")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileChildrenController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(Profile);
|
||||
private childrenRepository = AppDataSource.getRepository(ProfileChildren);
|
||||
private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory);
|
||||
|
||||
@Get("{profileId}")
|
||||
public async getChildren(@Path() profileId: string) {
|
||||
const lists = await this.childrenRepository.find({
|
||||
where: { profileId: profileId },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("history/{childrenId}")
|
||||
public async childrenHistory(@Path() childrenId: string) {
|
||||
const record = await this.childrenHistoryRepository.find({
|
||||
where: { profileChildrenId: childrenId },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newChildren(@Request() req: RequestWithUser, @Body() body: CreateProfileChildren) {
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileChildren();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.childrenRepository.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{childrenId}")
|
||||
public async editChildren(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileChildren,
|
||||
@Path() childrenId: string,
|
||||
) {
|
||||
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileChildrenHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileChildrenId = childrenId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(record),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{childrenId}")
|
||||
public async deleteTraning(@Path() childrenId: string) {
|
||||
await this.childrenHistoryRepository.delete({
|
||||
profileChildrenId: childrenId,
|
||||
});
|
||||
|
||||
const result = await this.childrenRepository.delete({ id: childrenId });
|
||||
|
||||
if (result.affected && result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
122
src/controllers/ProfileChildrenEmployeeController.ts
Normal file
122
src/controllers/ProfileChildrenEmployeeController.ts
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Example,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import {
|
||||
CreateProfileChildren,
|
||||
CreateProfileChildrenEmployee,
|
||||
ProfileChildren,
|
||||
UpdateProfileChildren,
|
||||
} from "../entities/ProfileChildren";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
|
||||
@Route("api/v1/org/profile-employee/children")
|
||||
@Tags("ProfileChildren")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileChildrenEmployeeController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
private childrenRepository = AppDataSource.getRepository(ProfileChildren);
|
||||
private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory);
|
||||
|
||||
@Get("{profileId}")
|
||||
public async getChildren(@Path() profileId: string) {
|
||||
const lists = await this.childrenRepository.find({
|
||||
where: { profileEmployeeId: profileId },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("history/{childrenId}")
|
||||
public async childrenHistory(@Path() childrenId: string) {
|
||||
const record = await this.childrenHistoryRepository.find({
|
||||
where: { profileChildrenId: childrenId },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newChildren(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileChildrenEmployee,
|
||||
) {
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileChildren();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.childrenRepository.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{childrenId}")
|
||||
public async editChildren(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileChildren,
|
||||
@Path() childrenId: string,
|
||||
) {
|
||||
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileChildrenHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileChildrenId = childrenId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(record),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{childrenId}")
|
||||
public async deleteTraning(@Path() childrenId: string) {
|
||||
await this.childrenHistoryRepository.delete({
|
||||
profileChildrenId: childrenId,
|
||||
});
|
||||
|
||||
const result = await this.childrenRepository.delete({ id: childrenId });
|
||||
|
||||
if (result.affected && result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -16,8 +16,6 @@ import { AppDataSource } from "../database/data-source";
|
|||
import {
|
||||
CreateChildren,
|
||||
CreateProfileFamily,
|
||||
ProfileChildren,
|
||||
ProfileChildrenHistory,
|
||||
ProfileFamilyHistory,
|
||||
UpdateProfileFamily,
|
||||
} from "../entities/ProfileFamily";
|
||||
|
|
@ -26,6 +24,8 @@ import HttpStatus from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { ProfileChildren } from "../entities/ProfileChildren";
|
||||
import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory";
|
||||
|
||||
@Route("api/v1/org/profile/family")
|
||||
@Tags("ProfileFamilyHistory")
|
||||
|
|
@ -228,7 +228,7 @@ export class ProfileFamilyHistoryController extends Controller {
|
|||
...v,
|
||||
children: await this.childrenHistoryRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
where: { profileFamilyHistoryId: v.id },
|
||||
// where: { profileFamilyHistoryId: v.id },
|
||||
}),
|
||||
})),
|
||||
);
|
||||
|
|
@ -340,7 +340,7 @@ export class ProfileFamilyHistoryController extends Controller {
|
|||
return await this.childrenHistoryRepo.save(
|
||||
this.childrenHistoryRepo.create({
|
||||
...v,
|
||||
profileFamilyHistoryId: familyRecord.id,
|
||||
// profileFamilyHistoryId: familyRecord.id,
|
||||
profileChildrenId: v.id,
|
||||
id: undefined,
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -15,10 +15,7 @@ import {
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
CreateChildren,
|
||||
CreateProfileFamily,
|
||||
CreateProfileFamilyEmployee,
|
||||
ProfileChildren,
|
||||
ProfileChildrenHistory,
|
||||
ProfileFamilyHistory,
|
||||
UpdateProfileFamily,
|
||||
} from "../entities/ProfileFamily";
|
||||
|
|
@ -26,8 +23,9 @@ import HttpSuccess from "../interfaces/http-success";
|
|||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { ProfileChildren } from "../entities/ProfileChildren";
|
||||
import { ProfileChildrenHistory } from "../entities/ProfileChildrenHistory";
|
||||
|
||||
@Route("api/v1/org/profile-employee/family")
|
||||
@Tags("ProfileFamilyHistoryEmployee")
|
||||
|
|
@ -230,7 +228,7 @@ export class ProfileFamilyHistoryEmployeeController extends Controller {
|
|||
...v,
|
||||
children: await this.childrenHistoryRepo.find({
|
||||
order: { createdAt: "ASC" },
|
||||
where: { profileFamilyHistoryId: v.id },
|
||||
// where: { profileFamilyHistoryId: v.id },
|
||||
}),
|
||||
})),
|
||||
);
|
||||
|
|
@ -342,7 +340,7 @@ export class ProfileFamilyHistoryEmployeeController extends Controller {
|
|||
return await this.childrenHistoryRepo.save(
|
||||
this.childrenHistoryRepo.create({
|
||||
...v,
|
||||
profileFamilyHistoryId: familyRecord.id,
|
||||
// profileFamilyHistoryId: familyRecord.id,
|
||||
profileChildrenId: v.id,
|
||||
id: undefined,
|
||||
}),
|
||||
|
|
@ -361,7 +359,7 @@ export class ProfileFamilyHistoryEmployeeController extends Controller {
|
|||
if (result.affected == undefined || result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue