แก้apiข้อมูลหลัก

This commit is contained in:
Kittapath 2024-03-26 23:07:55 +07:00
parent 73e07dfed6
commit 6b78a365fa
26 changed files with 1816 additions and 988 deletions

View file

@ -0,0 +1,153 @@
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 { District, CreateDistrict, UpdateDistrict } from "../entities/District";
import { Not } from "typeorm";
@Route("api/v1/org/metadata/district")
@Tags("District")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class DistrictController extends Controller {
private districtRepository = AppDataSource.getRepository(District);
/**
* API list
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
*/
@Get()
async GetResult() {
const _district = await this.districtRepository.find({
select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
order: { createdAt: "ASC" },
});
return new HttpSuccess(_district);
}
/**
* API
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
* @param {string} id Id
*/
@Get("{id}")
async GetById(@Path() id: string) {
const _district = await this.districtRepository.findOne({
where: { id },
select: ["id", "name"],
relations: { subDistricts: true },
});
if (!_district) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
}
return new HttpSuccess(_district);
}
/**
* API body
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
*/
@Post()
async Post(
@Body()
requestBody: CreateDistrict,
@Request() request: { user: Record<string, any> },
) {
const _district = Object.assign(new District(), requestBody);
if (!_district) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
}
const checkName = await this.districtRepository.findOne({
where: { name: requestBody.name },
});
if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
_district.createdUserId = request.user.sub;
_district.createdFullName = request.user.name;
_district.lastUpdateUserId = request.user.sub;
_district.lastUpdateFullName = request.user.name;
await this.districtRepository.save(_district);
return new HttpSuccess();
}
/**
* API body
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
* @param {string} id Id
*/
@Put("{id}")
async Put(
@Path() id: string,
@Body()
requestBody: UpdateDistrict,
@Request() request: { user: Record<string, any> },
) {
const _district = await this.districtRepository.findOne({ where: { id: id } });
if (!_district) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
}
const checkName = await this.districtRepository.findOne({
where: { id: Not(id), name: requestBody.name },
});
if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
_district.lastUpdateUserId = request.user.sub;
_district.lastUpdateFullName = request.user.name;
this.districtRepository.merge(_district, requestBody);
await this.districtRepository.save(_district);
return new HttpSuccess();
}
/**
* API
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
* @param {string} id Id
*/
@Delete("{id}")
async Delete(@Path() id: string) {
const _delDistrict = await this.districtRepository.findOne({
where: { id: id },
});
if (!_delDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเขตนี้");
}
await this.districtRepository.delete(_delDistrict.id);
return new HttpSuccess();
}
}

View file

@ -33,6 +33,7 @@ import { Gender } from "../entities/Gender";
import { Prefixe } from "../entities/Prefixe";
import { Relationship } from "../entities/Relationship";
import { Religion } from "../entities/Religion";
import { Rank } from "../entities/Rank";
@Route("api/v1/org/metadata")
@Tags("Profile")
@ -49,6 +50,7 @@ export class MainController extends Controller {
private prefixeRepo = AppDataSource.getRepository(Prefixe);
private relationshipRepo = AppDataSource.getRepository(Relationship);
private religionRepo = AppDataSource.getRepository(Religion);
private rankRepo = AppDataSource.getRepository(Rank);
/**
* API
*
@ -62,7 +64,8 @@ export class MainController extends Controller {
const prefixs = await this.prefixeRepo.find();
const relationships = await this.relationshipRepo.find();
const religions = await this.religionRepo.find();
const rank = await this.rankRepo.find();
return new HttpSuccess({ bloodGroups, genders, prefixs, relationships, religions });
return new HttpSuccess({ bloodGroups, genders, prefixs, relationships, religions, rank });
}
}

View file

@ -0,0 +1,128 @@
import {
Controller,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
SuccessResponse,
Response,
Get,
Query,
Patch,
Example,
} from "tsoa";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import { RequestWithUser } from "../middlewares/user";
import { Profile, ProfileAddressHistory, UpdateProfileAddress } from "../entities/Profile";
import { AppDataSource } from "../database/data-source";
import { Province } from "../entities/Province";
import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict";
@Route("api/v1/org/profile/address")
@Tags("ProfileAddress")
@Security("bearerAuth")
export class ProfileAddressController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory);
/**
*
* @summary
*
*/
@Get("{profileId}")
public async detailProfileAddress(@Path() profileId: string) {
const getProfileAddress = await this.profileRepo.findOne({
where: { id: profileId },
select: [
"id",
"registrationAddress",
"registrationProvinceId",
"registrationDistrictId",
"registrationSubDistrictId",
"registrationZipCode",
"currentAddress",
"currentProvinceId",
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
],
});
if (!getProfileAddress) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(getProfileAddress);
}
/**
*
* @summary
*
*/
@Get("history/{addressId}")
public async getProfileAddressHistory(@Path() addressId: string) {
const record = await this.profileAddressHistoryRepo.find({
where: {
id: addressId,
},
select: [
"registrationAddress",
"registrationProvinceId",
"registrationDistrictId",
"registrationSubDistrictId",
"registrationZipCode",
"currentAddress",
"currentProvinceId",
"currentDistrictId",
"currentSubDistrictId",
"currentZipCode",
"createdFullName",
"createdAt",
],
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
/**
*
* @summary
*
*/
@Patch("{addressId}")
public async editProfileAddress(
@Body() requestBody: UpdateProfileAddress,
@Request() req: RequestWithUser,
@Path() addressId: string,
) {
const record = await this.profileRepo.findOneBy({ id: addressId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileAddressHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, requestBody);
history.profileId = addressId;
history.lastUpdateFullName = req.user.name;
record.lastUpdateFullName = req.user.name;
await Promise.all([
this.profileRepo.save(record),
this.profileAddressHistoryRepo.save(history),
]);
return new HttpSuccess();
}
}

View file

@ -51,6 +51,7 @@ export class ProfileChangeNameController extends Controller {
const lists = await this.changeNameRepository.find({
where: { profileId: profileId },
select: ["id", "prefix", "firstName", "lastName", "status"],
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@ -117,7 +118,7 @@ export class ProfileChangeNameController extends Controller {
await this.changeNameRepository.save(data);
return new HttpSuccess();
return new HttpSuccess(data.id);
}
@Patch("{changeNameId}")

View file

@ -179,9 +179,6 @@ export class ProfileController extends Controller {
relations: {
posLevel: true,
posType: true,
gender: true,
relationship: true,
bloodGroup: true,
},
where: { id },
});
@ -197,9 +194,6 @@ export class ProfileController extends Controller {
relations: {
posLevel: true,
posType: true,
gender: true,
relationship: true,
bloodGroup: true,
},
where: { profileId: id },
});
@ -229,6 +223,7 @@ export class ProfileController extends Controller {
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string",
lastUpdateFullName: "string",
rank: null,
prefix: null,
firstName: "Methapon",
lastName: "Metanipat",
@ -244,21 +239,8 @@ export class ProfileController extends Controller {
birthDate: null,
ethnicity: null,
telephoneNumber: null,
genderId: "22041841-3149-4b40-ab0e-0d4e98ffd2e1",
gender: {
id: "22041841-3149-4b40-ab0e-0d4e98ffd2e1",
createdAt: "2024-03-24T12:35:45.693Z",
createdUserId: "00000000-0000-0000-0000-000000000000",
lastUpdatedAt: "2024-03-24T12:35:45.693Z",
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string",
lastUpdateFullName: "string",
name: "Male",
},
relationshipId: null,
gender: null,
relationship: null,
religionId: null,
bloodGroupId: null,
bloodGroup: null,
posLevel: null,
posType: null,
@ -289,9 +271,6 @@ export class ProfileController extends Controller {
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel")
.leftJoinAndSelect("profile.posType", "posType")
.leftJoinAndSelect("profile.gender", "gender")
.leftJoinAndSelect("profile.relationship", "relationship")
.leftJoinAndSelect("profile.bloodGroup", "bloodGroup")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
@ -300,6 +279,7 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.select([
"profile.id",
"profile.rank",
"profile.prefix",
"profile.firstName",
"profile.lastName",
@ -455,9 +435,14 @@ export class ProfileController extends Controller {
.andWhere(
new Brackets((qb) => {
qb.where("profile.id NOT IN (:...ids)", {
ids: orgRevision.posMasters
.filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId),
ids:
orgRevision.posMasters
.filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId).length == 0
? ["zxc"]
: orgRevision.posMasters
.filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId),
});
}),
)
@ -468,6 +453,7 @@ export class ProfileController extends Controller {
const data = profiles.map((_data) => ({
id: _data.id,
prefix: _data.prefix,
rank: _data.rank,
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
@ -507,6 +493,7 @@ export class ProfileController extends Controller {
const _profile = {
profileId: profile.id,
prefix: profile.prefix,
rank: profile.rank,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
@ -640,6 +627,7 @@ export class ProfileController extends Controller {
return {
id: item.id,
prefix: item.prefix,
rank: item.rank,
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
@ -906,6 +894,7 @@ export class ProfileController extends Controller {
return {
id: item.id,
prefix: item.prefix,
rank: item.rank,
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
@ -1137,6 +1126,7 @@ export class ProfileController extends Controller {
return {
prefix: item.current_holder.prefix,
rank: item.current_holder.rank,
firstName: item.current_holder.firstName,
lastName: item.current_holder.lastName,
citizenId: item.current_holder.citizenId,
@ -1212,6 +1202,7 @@ export class ProfileController extends Controller {
const _profile = {
profileId: profile.id,
prefix: profile.prefix,
rank: profile.rank,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,

View file

@ -170,9 +170,9 @@ export class ProfileEmployeeController extends Controller {
relations: {
posLevel: true,
posType: true,
gender: true,
relationship: true,
bloodGroup: true,
// gender: true,
// relationship: true,
// bloodGroup: true,
},
where: { id },
});
@ -199,9 +199,9 @@ export class ProfileEmployeeController extends Controller {
relations: {
posLevel: true,
posType: true,
gender: true,
relationship: true,
bloodGroup: true,
// gender: true,
// relationship: true,
// bloodGroup: true,
},
where:
searchField && searchKeyword ? [{ [searchField]: Like(`%${searchKeyword}%`) }] : undefined,
@ -218,9 +218,9 @@ export class ProfileEmployeeController extends Controller {
relations: {
posLevel: true,
posType: true,
gender: true,
relationship: true,
bloodGroup: true,
// gender: true,
// relationship: true,
// bloodGroup: true,
},
where: { profileEmployeeId: id },
});
@ -250,10 +250,10 @@ export class ProfileEmployeeController extends Controller {
) {
const orgRevision = await this.orgRevisionRepo.findOne({
where: {
orgRevisionIsDraft: true,
orgRevisionIsCurrent: false,
orgRevisionIsDraft: false,
orgRevisionIsCurrent: true,
},
relations: ["posMasters"],
relations: ["employeePosMasters"],
});
if (!orgRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
@ -326,19 +326,24 @@ export class ProfileEmployeeController extends Controller {
.andWhere(
new Brackets((qb) => {
qb.where("profileEmployee.id NOT IN (:...ids)", {
ids: orgRevision.posMasters
.filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId),
ids:
orgRevision.employeePosMasters
.filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId).length == 0
? ["zxc"]
: orgRevision.employeePosMasters
.filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId),
});
}),
)
.skip((requestBody.page - 1) * requestBody.pageSize)
.take(requestBody.pageSize)
.getManyAndCount();
const data = profiles.map((_data) => ({
id: _data.id,
prefix: _data.prefix,
rank: _data.rank,
firstName: _data.firstName,
lastName: _data.lastName,
citizenId: _data.citizenId,
@ -377,6 +382,7 @@ export class ProfileEmployeeController extends Controller {
const _profile = {
profileId: profile.id,
rank: profile.rank,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
@ -510,6 +516,7 @@ export class ProfileEmployeeController extends Controller {
findProfile.map(async (item: ProfileEmployee) => {
return {
id: item.id,
rank: item.rank,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
@ -776,6 +783,7 @@ export class ProfileEmployeeController extends Controller {
findProfile.map(async (item: ProfileEmployee) => {
return {
id: item.id,
rank: item.rank,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
@ -998,6 +1006,7 @@ export class ProfileEmployeeController extends Controller {
return {
salaryLevel: item.current_holder.salaryLevel,
group: item.current_holder.group,
rank: item.current_holder.rank,
prefix: item.current_holder.prefix,
firstName: item.current_holder.firstName,
lastName: item.current_holder.lastName,
@ -1073,6 +1082,7 @@ export class ProfileEmployeeController extends Controller {
const _profile = {
profileId: profile.id,
rank: profile.rank,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,

View file

@ -24,6 +24,7 @@ import HttpError from "../interfaces/http-error";
import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { Insignia } from "../entities/Insignia";
@Route("api/v1/org/profile/insignia")
@Tags("ProfileInsignia")
@ -32,6 +33,7 @@ export class ProfileInsigniaController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
private insigniaMetaRepo = AppDataSource.getRepository(Insignia);
@Get("{profileId}")
@Example({
@ -157,6 +159,13 @@ export class ProfileInsigniaController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const insignia = await this.insigniaMetaRepo.findOne({
where: { id: body.insigniaId },
});
if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
}
const data = new ProfileInsignia();
const meta = {
@ -183,6 +192,13 @@ export class ProfileInsigniaController extends Controller {
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const insignia = await this.insigniaMetaRepo.findOne({
where: { id: body.insigniaId },
});
if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
}
const history = new ProfileInsigniaHistory();
Object.assign(history, { ...record, id: undefined });

View file

@ -25,6 +25,7 @@ import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { LeaveType } from "../entities/LeaveType";
@Route("api/v1/org/profile/leave")
@Tags("ProfileLeave")
@ -33,6 +34,7 @@ export class ProfileLeaveController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private leaveRepo = AppDataSource.getRepository(ProfileLeave);
private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory);
private leaveTypeRepository = AppDataSource.getRepository(LeaveType);
@Get("{profileId}")
@Example({
@ -48,7 +50,8 @@ export class ProfileLeaveController extends Controller {
lastUpdateFullName: "สาวิตรี ศรีสมัย",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
leaveTypeId: "8dc5e672-b416-4323-b086-06dde8c4353c",
dateLeave: "2024-03-21T06:39:46.000Z",
dateLeaveStart: "2024-03-21T06:39:46.000Z",
dateLeaveEnd: "2024-03-21T06:39:46.000Z",
leaveDays: 0,
leaveCount: null,
totalLeave: 0,
@ -69,7 +72,7 @@ export class ProfileLeaveController extends Controller {
},
})
public async getLeave(@Path() profileId: string) {
const record = await this.leaveRepo.findOne({
const record = await this.leaveRepo.find({
relations: { leaveType: true },
where: { profileId },
});
@ -91,7 +94,8 @@ export class ProfileLeaveController extends Controller {
lastUpdateFullName: "สาวิตรี ศรีสมัย",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
leaveTypeId: "8dc5e672-b416-4323-b086-06dde8c4353c",
dateLeave: "2024-03-21T06:39:46.000Z",
dateLeaveStart: "2024-03-21T06:39:46.000Z",
dateLeaveEnd: "2024-03-21T06:39:46.000Z",
leaveDays: 0,
leaveCount: null,
totalLeave: 0,
@ -121,7 +125,8 @@ export class ProfileLeaveController extends Controller {
lastUpdateFullName: "สาวิตรี ศรีสมัย",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
leaveTypeId: "7dc4e314-b456-4323-b086-06dde8c4353c",
dateLeave: "2024-03-21T06:34:49.000Z",
dateLeaveStart: "2024-03-21T06:34:49.000Z",
dateLeaveEnd: "2024-03-21T06:34:49.000Z",
leaveDays: 2,
leaveCount: null,
totalLeave: 200,
@ -162,6 +167,12 @@ export class ProfileLeaveController extends Controller {
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const leaveType = await this.leaveTypeRepository.findOne({
where: { id: body.leaveTypeId },
});
if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
}
const data = new ProfileLeave();
@ -189,6 +200,13 @@ export class ProfileLeaveController extends Controller {
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const leaveType = await this.leaveTypeRepository.findOne({
where: { id: body.leaveTypeId },
});
if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
}
const history = new ProfileLeaveHistory();
Object.assign(history, { ...record, id: undefined });

View file

@ -1,150 +1,189 @@
import {
Body,
Controller,
Post,
Put,
Delete,
Example,
Get,
Patch,
Path,
Post,
Request,
Route,
Security,
Tags,
Body,
Path,
Request,
SuccessResponse,
Response,
Get,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { CreateProfileSalary, ProfileSalary, UpdateProfileSalary } from "../entities/ProfileSalary";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { ProfileSalary, CreateProfileSalary, UpdateProfileSalary } from "../entities/ProfileSalary";
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import { Not } from "typeorm";
@Route("api/v1/org/profileSalary")
@Route("api/v1/org/profile/salary")
@Tags("ProfileSalary")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class ProfileSalaryController extends Controller {
private profileSalaryRepository = AppDataSource.getRepository(ProfileSalary);
private profileRepository = AppDataSource.getRepository(Profile);
private profileRepo = AppDataSource.getRepository(Profile);
private salaryRepo = AppDataSource.getRepository(ProfileSalary);
private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory);
@Get("{profileId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "3cf02fb7-2f0c-471b-b641-51d557375c0a",
createdAt: "2024-03-12T02:55:56.915Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-12T02:55:56.915Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
isActive: true,
startDate: "2024-03-12T09:55:23.000Z",
endDate: "2024-03-12T09:55:23.000Z",
numberOrder: "string",
topic: "string",
place: "string",
dateOrder: "2024-03-12T09:55:23.000Z",
department: "string",
duration: "string",
name: "string",
yearly: 0,
isDate: true,
},
],
})
public async getSalary(@Path() profileId: string) {
const record = await this.salaryRepo.findBy({ profileId });
return new HttpSuccess(record);
}
@Get("history/{salaryId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "6d4e9dbe-8697-4546-9651-0a1c3ea0a82d",
createdAt: "2024-03-12T02:55:56.971Z",
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
lastUpdatedAt: "2024-03-12T02:55:56.971Z",
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
createdFullName: "สาวิตรี ศรีสมัย",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
isActive: true,
startDate: "2024-03-12T09:55:23.000Z",
endDate: "2024-03-12T09:55:23.000Z",
numberOrder: "string",
topic: "string",
place: "string",
dateOrder: "2024-03-12T09:55:23.000Z",
department: "string",
duration: "string",
name: "string",
yearly: 0,
isDate: true,
profileSalaryId: "3cf02fb7-2f0c-471b-b641-51d557375c0a",
},
{
id: "a251c176-3dac-4d09-9813-38c8db1127e3",
createdAt: "2024-03-12T02:58:17.917Z",
createdUserId: "00000000-0000-0000-0000-000000000000",
lastUpdatedAt: "2024-03-12T02:58:17.917Z",
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
createdFullName: "string",
lastUpdateFullName: "สาวิตรี ศรีสมัย",
isActive: true,
startDate: "2024-03-12T09:57:44.000Z",
endDate: "2024-03-12T09:57:44.000Z",
numberOrder: "string",
topic: "topic",
place: "place",
dateOrder: "2024-03-12T09:57:44.000Z",
department: "department",
duration: "string",
name: "name",
yearly: 0,
isDate: true,
profileSalaryId: "3cf02fb7-2f0c-471b-b641-51d557375c0a",
},
],
})
public async salaryHistory(@Path() salaryId: string) {
const record = await this.salaryHistoryRepo.findBy({
profileSalaryId: salaryId,
});
return new HttpSuccess(record);
}
/**
* API Create profile salary
*
* @summary Create profile salary
*
*/
@Post()
async CreateProfileSalary(
@Body()
requestBody: CreateProfileSalary,
@Request() request: { user: Record<string, any> },
) {
const profileSalary = Object.assign(new ProfileSalary(), requestBody);
if (!profileSalary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
public async newSalary(@Request() req: RequestWithUser, @Body() body: CreateProfileSalary) {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepository.findOne({
where: { id: profileSalary.profileId },
});
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
profileSalary.createdUserId = request.user.sub;
profileSalary.createdFullName = request.user.name;
profileSalary.lastUpdateUserId = request.user.sub;
profileSalary.lastUpdateFullName = request.user.name;
await this.profileSalaryRepository.save(profileSalary);
const data = new ProfileSalary();
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.salaryRepo.save(data);
return new HttpSuccess();
}
/**
* API Update profile salary
*
* @summary Update profile salary
*
* @param {string} id Id ProfileSalaryId
*/
@Put("{id}")
async UpdateProfileSalary(
@Path() id: string,
@Body()
requestBody: UpdateProfileSalary,
@Request() request: { user: Record<string, any> },
@Patch("{salaryId}")
public async editSalary(
@Request() req: RequestWithUser,
@Body() body: UpdateProfileSalary,
@Path() salaryId: string,
) {
const profileSalary = await this.profileSalaryRepository.findOne({ where: { id: id } });
if (!profileSalary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
}
const record = await this.salaryRepo.findOneBy({ id: salaryId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileSalaryHistory();
Object.assign(history, { ...record, id: undefined });
Object.assign(record, body);
history.profileSalaryId = salaryId;
record.lastUpdateFullName = req.user.name;
history.lastUpdateFullName = req.user.name;
await Promise.all([this.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]);
profileSalary.lastUpdateUserId = request.user.sub;
profileSalary.lastUpdateFullName = request.user.name;
this.profileSalaryRepository.merge(profileSalary, requestBody);
await this.profileSalaryRepository.save(profileSalary);
return new HttpSuccess();
}
/**
* API Delete profile salary
*
* @summary Delete profile salary
*
* @param {string} id Id ProfileSalaryId
*/
@Delete("{id}")
async DeleteProfileSalary(@Path() id: string) {
const delprofileSalary = await this.profileSalaryRepository.findOne({
where: { id },
@Delete("{salaryId}")
public async deleteSalary(@Path() salaryId: string) {
await this.salaryHistoryRepo.delete({
profileSalaryId: salaryId,
});
if (!delprofileSalary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
const result = await this.salaryRepo.delete({ id: salaryId });
if (result.affected && result.affected <= 0) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
await this.profileSalaryRepository.delete({ id: id });
return new HttpSuccess();
}
/**
* API GetById ProfileSalary
*
* @summary GetById Profile
*
* @param {string} id Id ProfileId
*/
@Get("{id}")
async GetById(@Path() id: string) {
const profileSalary = await this.profileSalaryRepository.find({
where: { profileId:id },
select: ["id", "date", "amount", "positionSalaryAmount", "mouthSalaryAmount", "profileId"],
});
if (!profileSalary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(profileSalary);
}
// /**
// * API GetLists profile salary
// *
// * @summary GetLists profile salary
// *
// */
// @Get()
// async GetLists() {
// const profileSalary = await this.profileSalaryRepository.find({
// select: ["id", "date", "amount", "positionSalaryAmount", "mouthSalaryAmount", "profileId"],
// order: { createdAt: "ASC" },
// });
// if (!profileSalary) {
// return new HttpSuccess([]);
// }
// return new HttpSuccess(profileSalary);
// }
}

View file

@ -0,0 +1,153 @@
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 { Province, CreateProvince, UpdateProvince } from "../entities/Province";
import { Not } from "typeorm";
@Route("api/v1/org/metadata/province")
@Tags("Province")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class ProvinceController extends Controller {
private provinceRepository = AppDataSource.getRepository(Province);
/**
* API list
*
* @summary CRUD (ADMIN)
*
*/
@Get()
async GetResult() {
const _province = await this.provinceRepository.find({
select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
order: { createdAt: "ASC" },
});
return new HttpSuccess(_province);
}
/**
* API
*
* @summary CRUD (ADMIN)
*
* @param {string} id Id
*/
@Get("{id}")
async GetById(@Path() id: string) {
const _province = await this.provinceRepository.findOne({
where: { id },
select: ["id", "name"],
relations: { districts: true },
});
if (!_province) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
}
return new HttpSuccess(_province);
}
/**
* API body
*
* @summary CRUD (ADMIN)
*
*/
@Post()
async Post(
@Body()
requestBody: CreateProvince,
@Request() request: { user: Record<string, any> },
) {
const _province = Object.assign(new Province(), requestBody);
if (!_province) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
}
const checkName = await this.provinceRepository.findOne({
where: { name: requestBody.name },
});
if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
_province.createdUserId = request.user.sub;
_province.createdFullName = request.user.name;
_province.lastUpdateUserId = request.user.sub;
_province.lastUpdateFullName = request.user.name;
await this.provinceRepository.save(_province);
return new HttpSuccess();
}
/**
* API body
*
* @summary CRUD (ADMIN)
*
* @param {string} id Id
*/
@Put("{id}")
async Put(
@Path() id: string,
@Body()
requestBody: UpdateProvince,
@Request() request: { user: Record<string, any> },
) {
const _province = await this.provinceRepository.findOne({ where: { id: id } });
if (!_province) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
}
const checkName = await this.provinceRepository.findOne({
where: { id: Not(id), name: requestBody.name },
});
if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
_province.lastUpdateUserId = request.user.sub;
_province.lastUpdateFullName = request.user.name;
this.provinceRepository.merge(_province, requestBody);
await this.provinceRepository.save(_province);
return new HttpSuccess();
}
/**
* API
*
* @summary CRUD (ADMIN)
*
* @param {string} id Id
*/
@Delete("{id}")
async Delete(@Path() id: string) {
const _delProvince = await this.provinceRepository.findOne({
where: { id: id },
});
if (!_delProvince) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางจังหวัดนี้");
}
await this.provinceRepository.delete(_delProvince.id);
return new HttpSuccess();
}
}

View file

@ -0,0 +1,152 @@
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 { SubDistrict, CreateSubDistrict, UpdateSubDistrict } from "../entities/SubDistrict";
import { Not } from "typeorm";
@Route("api/v1/org/metadata/subDistrict")
@Tags("SubDistrict")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class SubDistrictController extends Controller {
private subDistrictRepository = AppDataSource.getRepository(SubDistrict);
/**
* API list
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
*/
@Get()
async GetResult() {
const _subDistrict = await this.subDistrictRepository.find({
select: ["id", "name", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
order: { createdAt: "ASC" },
});
return new HttpSuccess(_subDistrict);
}
/**
* API
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
* @param {string} id Id
*/
@Get("{id}")
async GetById(@Path() id: string) {
const _subDistrict = await this.subDistrictRepository.findOne({
where: { id },
select: ["id", "name"],
});
if (!_subDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
}
return new HttpSuccess(_subDistrict);
}
/**
* API body
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
*/
@Post()
async Post(
@Body()
requestBody: CreateSubDistrict,
@Request() request: { user: Record<string, any> },
) {
const _subDistrict = Object.assign(new SubDistrict(), requestBody);
if (!_subDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
}
const checkName = await this.subDistrictRepository.findOne({
where: { name: requestBody.name },
});
if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
_subDistrict.createdUserId = request.user.sub;
_subDistrict.createdFullName = request.user.name;
_subDistrict.lastUpdateUserId = request.user.sub;
_subDistrict.lastUpdateFullName = request.user.name;
await this.subDistrictRepository.save(_subDistrict);
return new HttpSuccess();
}
/**
* API body
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
* @param {string} id Id
*/
@Put("{id}")
async Put(
@Path() id: string,
@Body()
requestBody: UpdateSubDistrict,
@Request() request: { user: Record<string, any> },
) {
const _subDistrict = await this.subDistrictRepository.findOne({ where: { id: id } });
if (!_subDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
}
const checkName = await this.subDistrictRepository.findOne({
where: { id: Not(id), name: requestBody.name },
});
if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
_subDistrict.lastUpdateUserId = request.user.sub;
_subDistrict.lastUpdateFullName = request.user.name;
this.subDistrictRepository.merge(_subDistrict, requestBody);
await this.subDistrictRepository.save(_subDistrict);
return new HttpSuccess();
}
/**
* API
*
* @summary ORG_058 - CRUD (ADMIN) #62
*
* @param {string} id Id
*/
@Delete("{id}")
async Delete(@Path() id: string) {
const _delSubDistrict = await this.subDistrictRepository.findOne({
where: { id: id },
});
if (!_delSubDistrict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพทางเพศนี้");
}
await this.subDistrictRepository.delete(_delSubDistrict.id);
return new HttpSuccess();
}
}