api คำขอแก้ไข
This commit is contained in:
parent
0696672f86
commit
85c6093970
8 changed files with 546 additions and 30 deletions
|
|
@ -36,6 +36,7 @@ import {
|
||||||
calculateRetireDate,
|
calculateRetireDate,
|
||||||
calculateRetireLaw,
|
calculateRetireLaw,
|
||||||
calculateRetireYear,
|
calculateRetireYear,
|
||||||
|
removeProfileInOrganize,
|
||||||
} from "../interfaces/utils";
|
} from "../interfaces/utils";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import { Position } from "../entities/Position";
|
import { Position } from "../entities/Position";
|
||||||
|
|
@ -1451,6 +1452,7 @@ export class ProfileController extends Controller {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
||||||
}
|
}
|
||||||
let dateLeave_: any = body.date;
|
let dateLeave_: any = body.date;
|
||||||
|
await removeProfileInOrganize(profile.id);
|
||||||
profile.isLeave = true;
|
profile.isLeave = true;
|
||||||
profile.leaveReason =
|
profile.leaveReason =
|
||||||
"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด";
|
"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด";
|
||||||
|
|
@ -1523,6 +1525,7 @@ export class ProfileController extends Controller {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
||||||
}
|
}
|
||||||
let dateLeave_: any = body.date;
|
let dateLeave_: any = body.date;
|
||||||
|
await removeProfileInOrganize(profile.id);
|
||||||
profile.isLeave = true;
|
profile.isLeave = true;
|
||||||
profile.leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ";
|
profile.leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ";
|
||||||
profile.dateLeave = dateLeave_;
|
profile.dateLeave = dateLeave_;
|
||||||
|
|
@ -1594,6 +1597,7 @@ export class ProfileController extends Controller {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
||||||
}
|
}
|
||||||
let dateLeave_: any = body.date;
|
let dateLeave_: any = body.date;
|
||||||
|
await removeProfileInOrganize(profile.id);
|
||||||
profile.isLeave = true;
|
profile.isLeave = true;
|
||||||
profile.leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ";
|
profile.leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ";
|
||||||
profile.dateLeave = dateLeave_;
|
profile.dateLeave = dateLeave_;
|
||||||
|
|
@ -1679,6 +1683,7 @@ export class ProfileController extends Controller {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
||||||
}
|
}
|
||||||
let dateLeave_: any = body.date;
|
let dateLeave_: any = body.date;
|
||||||
|
await removeProfileInOrganize(profile.id);
|
||||||
profile.isLeave = true;
|
profile.isLeave = true;
|
||||||
profile.leaveReason = "ได้รับโทษทางวินัย พักจากราชการ";
|
profile.leaveReason = "ได้รับโทษทางวินัย พักจากราชการ";
|
||||||
profile.dateLeave = dateLeave_;
|
profile.dateLeave = dateLeave_;
|
||||||
|
|
@ -1750,6 +1755,7 @@ export class ProfileController extends Controller {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
||||||
}
|
}
|
||||||
let dateLeave_: any = body.date;
|
let dateLeave_: any = body.date;
|
||||||
|
await removeProfileInOrganize(profile.id);
|
||||||
profile.isLeave = true;
|
profile.isLeave = true;
|
||||||
profile.leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน";
|
profile.leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน";
|
||||||
profile.dateLeave = dateLeave_;
|
profile.dateLeave = dateLeave_;
|
||||||
|
|
@ -4879,6 +4885,9 @@ export class ProfileController extends Controller {
|
||||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
const _null: any = null;
|
const _null: any = null;
|
||||||
profile.isLeave = requestBody.isLeave;
|
profile.isLeave = requestBody.isLeave;
|
||||||
|
if (requestBody.isLeave == true) {
|
||||||
|
await removeProfileInOrganize(profile.id);
|
||||||
|
}
|
||||||
if (requestBody.leaveReason != undefined && requestBody.leaveReason != null) {
|
if (requestBody.leaveReason != undefined && requestBody.leaveReason != null) {
|
||||||
profile.leaveReason = requestBody.leaveReason;
|
profile.leaveReason = requestBody.leaveReason;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -4890,11 +4899,10 @@ export class ProfileController extends Controller {
|
||||||
profile.dateLeave = _null;
|
profile.dateLeave = _null;
|
||||||
}
|
}
|
||||||
await this.profileRepo.save(profile);
|
await this.profileRepo.save(profile);
|
||||||
|
// const profileSalary = await this.salaryRepository.findOne({
|
||||||
const profileSalary = await this.salaryRepository.findOne({
|
// where: { profileId: id },
|
||||||
where: { profileId: id },
|
// order: { createdAt: "DESC" },
|
||||||
order: { createdAt: "DESC" },
|
// });
|
||||||
});
|
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
190
src/controllers/ProfileEditController.ts
Normal file
190
src/controllers/ProfileEditController.ts
Normal file
|
|
@ -0,0 +1,190 @@
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Path,
|
||||||
|
Post,
|
||||||
|
Query,
|
||||||
|
Request,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
} from "tsoa";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import { Profile } from "../entities/Profile";
|
||||||
|
import { CreateProfileEdit, EditProfileEdit, ProfileEdit } from "../entities/ProfileEdit";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { IsNull, Not } from "typeorm";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile/edit")
|
||||||
|
@Tags("ProfileEdit")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileEditController extends Controller {
|
||||||
|
private profileRepo = AppDataSource.getRepository(Profile);
|
||||||
|
private profileEditRepo = AppDataSource.getRepository(ProfileEdit);
|
||||||
|
|
||||||
|
@Get("user")
|
||||||
|
public async detailProfileEditUser(
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
@Query("page") page: number = 1,
|
||||||
|
@Query("pageSize") pageSize: number = 10,
|
||||||
|
@Query("keyword") keyword: string = "",
|
||||||
|
) {
|
||||||
|
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
|
||||||
|
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
|
||||||
|
.createQueryBuilder("ProfileEdit")
|
||||||
|
.leftJoinAndSelect("ProfileEdit.profile", "profile")
|
||||||
|
.where({
|
||||||
|
profileId: profile.id,
|
||||||
|
})
|
||||||
|
.orderBy("ProfileEdit.createdAt", "ASC")
|
||||||
|
.skip((page - 1) * pageSize)
|
||||||
|
.take(pageSize)
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
|
const _data = getProfileEdit.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
topic: item.topic,
|
||||||
|
detail: item.detail,
|
||||||
|
status: item.status,
|
||||||
|
remark: item.remark,
|
||||||
|
createdAt: item.createdAt,
|
||||||
|
createdFullName: item.createdFullName,
|
||||||
|
lastUpdatedAt: item.lastUpdatedAt,
|
||||||
|
lastUpdateFullName: item.lastUpdateFullName,
|
||||||
|
fullname:
|
||||||
|
(item?.profile?.prefix ?? "") +
|
||||||
|
"" +
|
||||||
|
(item?.profile?.firstName ?? "") +
|
||||||
|
" " +
|
||||||
|
(item?.profile?.lastName ?? ""),
|
||||||
|
}));
|
||||||
|
return new HttpSuccess({ data: _data, total: total });
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("admin")
|
||||||
|
public async detailProfileEditAdmin(
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
@Query("page") page: number = 1,
|
||||||
|
@Query("pageSize") pageSize: number = 10,
|
||||||
|
@Query("keyword") keyword: string = "",
|
||||||
|
) {
|
||||||
|
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
|
||||||
|
.createQueryBuilder("ProfileEdit")
|
||||||
|
.leftJoinAndSelect("ProfileEdit.profile", "profile")
|
||||||
|
.where({
|
||||||
|
profileId: Not(IsNull()),
|
||||||
|
})
|
||||||
|
.orderBy("ProfileEdit.createdAt", "ASC")
|
||||||
|
.skip((page - 1) * pageSize)
|
||||||
|
.take(pageSize)
|
||||||
|
.getManyAndCount();
|
||||||
|
const _data = getProfileEdit.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
topic: item.topic,
|
||||||
|
detail: item.detail,
|
||||||
|
status: item.status,
|
||||||
|
remark: item.remark,
|
||||||
|
createdAt: item.createdAt,
|
||||||
|
createdFullName: item.createdFullName,
|
||||||
|
lastUpdatedAt: item.lastUpdatedAt,
|
||||||
|
lastUpdateFullName: item.lastUpdateFullName,
|
||||||
|
fullname:
|
||||||
|
(item?.profile?.prefix ?? "") +
|
||||||
|
"" +
|
||||||
|
(item?.profile?.firstName ?? "") +
|
||||||
|
" " +
|
||||||
|
(item?.profile?.lastName ?? ""),
|
||||||
|
}));
|
||||||
|
return new HttpSuccess({ data: _data, total: total });
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("{profileId}")
|
||||||
|
public async detailProfileEdit(@Path() profileId: string) {
|
||||||
|
const getProfileEdit = await this.profileEditRepo.findOne({
|
||||||
|
where: { profileId: profileId },
|
||||||
|
relations: ["profile"],
|
||||||
|
});
|
||||||
|
if (!getProfileEdit) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
const _data = {
|
||||||
|
id: getProfileEdit.id,
|
||||||
|
topic: getProfileEdit.topic,
|
||||||
|
detail: getProfileEdit.detail,
|
||||||
|
status: getProfileEdit.status,
|
||||||
|
remark: getProfileEdit.remark,
|
||||||
|
createdAt: getProfileEdit.createdAt,
|
||||||
|
createdFullName: getProfileEdit.createdFullName,
|
||||||
|
lastUpdatedAt: getProfileEdit.lastUpdatedAt,
|
||||||
|
lastUpdateFullName: getProfileEdit.lastUpdateFullName,
|
||||||
|
fullname:
|
||||||
|
(getProfileEdit?.profile?.prefix ?? "") +
|
||||||
|
"" +
|
||||||
|
(getProfileEdit?.profile?.firstName ?? "") +
|
||||||
|
" " +
|
||||||
|
(getProfileEdit?.profile?.lastName ?? ""),
|
||||||
|
};
|
||||||
|
return new HttpSuccess(_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newProfileEdit(@Request() req: RequestWithUser, @Body() body: CreateProfileEdit) {
|
||||||
|
const profile = await this.profileRepo.findOneBy({ keycloak: req.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = new ProfileEdit();
|
||||||
|
const meta = {
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.assign(data, { ...body, ...meta });
|
||||||
|
data.status = "PENDING";
|
||||||
|
await this.profileEditRepo.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess(data.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{editId}")
|
||||||
|
public async editProfileEdit(
|
||||||
|
@Body() requestBody: EditProfileEdit,
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Path() editId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.profileEditRepo.findOneBy({ id: editId });
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
Object.assign(record, requestBody);
|
||||||
|
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
record.lastUpdateUserId = req.user.sub;
|
||||||
|
record.lastUpdatedAt = new Date();
|
||||||
|
await Promise.all([this.profileEditRepo.save(record)]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{editId}")
|
||||||
|
public async deleteProfileEdit(@Path() editId: string) {
|
||||||
|
const result = await this.profileEditRepo.delete({ id: editId });
|
||||||
|
|
||||||
|
if (result.affected == undefined || result.affected <= 0)
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
197
src/controllers/ProfileEditEmployeeController.ts
Normal file
197
src/controllers/ProfileEditEmployeeController.ts
Normal file
|
|
@ -0,0 +1,197 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Post,
|
||||||
|
Delete,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
Body,
|
||||||
|
Path,
|
||||||
|
Request,
|
||||||
|
Get,
|
||||||
|
Patch,
|
||||||
|
Query,
|
||||||
|
} from "tsoa";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import {
|
||||||
|
CreateProfileEmployeeEdit,
|
||||||
|
EditProfileEmployeeEdit,
|
||||||
|
ProfileEdit,
|
||||||
|
} from "../entities/ProfileEdit";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { IsNull, Not } from "typeorm";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile-employee/edit")
|
||||||
|
@Tags("ProfileEmployeeEdit")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileEditEmployeeController extends Controller {
|
||||||
|
private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private profileEditRepository = AppDataSource.getRepository(ProfileEdit);
|
||||||
|
|
||||||
|
@Get("user")
|
||||||
|
public async detailProfileEditUser(
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
@Query("page") page: number = 1,
|
||||||
|
@Query("pageSize") pageSize: number = 10,
|
||||||
|
@Query("keyword") keyword: string = "",
|
||||||
|
) {
|
||||||
|
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
|
||||||
|
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
|
||||||
|
.createQueryBuilder("ProfileEdit")
|
||||||
|
.leftJoinAndSelect("ProfileEdit.profileEmployeeId", "profileEmployeeId")
|
||||||
|
.where({
|
||||||
|
profileEmployeeId: profile.id,
|
||||||
|
})
|
||||||
|
.orderBy("ProfileEdit.createdAt", "ASC")
|
||||||
|
.skip((page - 1) * pageSize)
|
||||||
|
.take(pageSize)
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
|
const _data = getProfileEdit.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
topic: item.topic,
|
||||||
|
detail: item.detail,
|
||||||
|
status: item.status,
|
||||||
|
remark: item.remark,
|
||||||
|
createdAt: item.createdAt,
|
||||||
|
createdFullName: item.createdFullName,
|
||||||
|
lastUpdatedAt: item.lastUpdatedAt,
|
||||||
|
lastUpdateFullName: item.lastUpdateFullName,
|
||||||
|
fullname:
|
||||||
|
(item?.profileEmployee?.prefix ?? "") +
|
||||||
|
"" +
|
||||||
|
(item?.profileEmployee?.firstName ?? "") +
|
||||||
|
" " +
|
||||||
|
(item?.profileEmployee?.lastName ?? ""),
|
||||||
|
}));
|
||||||
|
return new HttpSuccess({ data: _data, total: total });
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("admin")
|
||||||
|
public async detailProfileEditAdmin(
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
@Query("page") page: number = 1,
|
||||||
|
@Query("pageSize") pageSize: number = 10,
|
||||||
|
@Query("keyword") keyword: string = "",
|
||||||
|
) {
|
||||||
|
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
|
||||||
|
.createQueryBuilder("ProfileEdit")
|
||||||
|
.leftJoinAndSelect("ProfileEdit.profileEmployee", "profileEmployee")
|
||||||
|
.where({
|
||||||
|
profileEmployeeId: Not(IsNull()),
|
||||||
|
})
|
||||||
|
.orderBy("ProfileEdit.createdAt", "ASC")
|
||||||
|
.skip((page - 1) * pageSize)
|
||||||
|
.take(pageSize)
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
|
const _data = getProfileEdit.map((item) => ({
|
||||||
|
id: item.id,
|
||||||
|
topic: item.topic,
|
||||||
|
detail: item.detail,
|
||||||
|
status: item.status,
|
||||||
|
remark: item.remark,
|
||||||
|
createdAt: item.createdAt,
|
||||||
|
createdFullName: item.createdFullName,
|
||||||
|
lastUpdatedAt: item.lastUpdatedAt,
|
||||||
|
lastUpdateFullName: item.lastUpdateFullName,
|
||||||
|
fullname:
|
||||||
|
(item?.profileEmployee?.prefix ?? "") +
|
||||||
|
"" +
|
||||||
|
(item?.profileEmployee?.firstName ?? "") +
|
||||||
|
" " +
|
||||||
|
(item?.profileEmployee?.lastName ?? ""),
|
||||||
|
}));
|
||||||
|
return new HttpSuccess({ data: _data, total: total });
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("{profileEmployeeId}")
|
||||||
|
public async detailProfileEdit(@Path() profileEmployeeId: string) {
|
||||||
|
const getProfileEdit = await this.profileEditRepository.findOne({
|
||||||
|
where: { profileEmployeeId: profileEmployeeId },
|
||||||
|
relations: ["profileEmployee"],
|
||||||
|
});
|
||||||
|
if (!getProfileEdit) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
const _data = {
|
||||||
|
id: getProfileEdit.id,
|
||||||
|
topic: getProfileEdit.topic,
|
||||||
|
detail: getProfileEdit.detail,
|
||||||
|
status: getProfileEdit.status,
|
||||||
|
remark: getProfileEdit.remark,
|
||||||
|
createdAt: getProfileEdit.createdAt,
|
||||||
|
createdFullName: getProfileEdit.createdFullName,
|
||||||
|
lastUpdatedAt: getProfileEdit.lastUpdatedAt,
|
||||||
|
lastUpdateFullName: getProfileEdit.lastUpdateFullName,
|
||||||
|
fullname:
|
||||||
|
(getProfileEdit?.profileEmployee?.prefix ?? "") +
|
||||||
|
"" +
|
||||||
|
(getProfileEdit?.profileEmployee?.firstName ?? "") +
|
||||||
|
" " +
|
||||||
|
(getProfileEdit?.profileEmployee?.lastName ?? ""),
|
||||||
|
};
|
||||||
|
return new HttpSuccess(_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async profileEdit(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: CreateProfileEmployeeEdit,
|
||||||
|
) {
|
||||||
|
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: req.user.sub });
|
||||||
|
if (!profile) {
|
||||||
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = new ProfileEdit();
|
||||||
|
const meta = {
|
||||||
|
createdUserId: req.user.sub,
|
||||||
|
createdFullName: req.user.name,
|
||||||
|
lastUpdateUserId: req.user.sub,
|
||||||
|
lastUpdateFullName: req.user.name,
|
||||||
|
};
|
||||||
|
Object.assign(data, { ...body, ...meta });
|
||||||
|
data.status = "PENDING";
|
||||||
|
await this.profileEditRepository.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess(data.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{editId}")
|
||||||
|
public async editProfileEdit(
|
||||||
|
@Body() requestBody: EditProfileEmployeeEdit,
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Path() editId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.profileEditRepository.findOneBy({ id: editId });
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
Object.assign(record, requestBody);
|
||||||
|
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
record.lastUpdateUserId = req.user.sub;
|
||||||
|
record.lastUpdatedAt = new Date();
|
||||||
|
|
||||||
|
await Promise.all([this.profileEditRepository.save(record)]);
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{editId}")
|
||||||
|
public async deleteProfileEdit(@Path() editId: string) {
|
||||||
|
const result = await this.profileEditRepository.delete({ id: editId });
|
||||||
|
|
||||||
|
if (result.affected == undefined || result.affected <= 0)
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,7 +20,11 @@ import HttpStatus from "../interfaces/http-status";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { Brackets, Double, In, IsNull, Like, Not } from "typeorm";
|
import { Brackets, Double, In, IsNull, Like, Not } from "typeorm";
|
||||||
import { OrgRevision } from "../entities/OrgRevision";
|
import { OrgRevision } from "../entities/OrgRevision";
|
||||||
import { calculateRetireDate, calculateRetireLaw } from "../interfaces/utils";
|
import {
|
||||||
|
calculateRetireDate,
|
||||||
|
calculateRetireLaw,
|
||||||
|
removeProfileInOrganize,
|
||||||
|
} from "../interfaces/utils";
|
||||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||||
import {
|
import {
|
||||||
ProfileEmployee,
|
ProfileEmployee,
|
||||||
|
|
@ -400,8 +404,8 @@ export class ProfileEmployeeController extends Controller {
|
||||||
profiles.dateRetireLaw != null
|
profiles.dateRetireLaw != null
|
||||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw))
|
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw))
|
||||||
: "",
|
: "",
|
||||||
CurrentAddress:
|
CurrentAddress:
|
||||||
profiles.currentAddress != null ? Extension.ToThaiNumber(profiles.currentAddress) : "",
|
profiles.currentAddress != null ? Extension.ToThaiNumber(profiles.currentAddress) : "",
|
||||||
CurrentSubDistrict:
|
CurrentSubDistrict:
|
||||||
profiles.currentSubDistrict != null
|
profiles.currentSubDistrict != null
|
||||||
? Extension.ToThaiNumber(profiles.currentSubDistrict.name)
|
? Extension.ToThaiNumber(profiles.currentSubDistrict.name)
|
||||||
|
|
@ -438,9 +442,7 @@ export class ProfileEmployeeController extends Controller {
|
||||||
? ""
|
? ""
|
||||||
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)),
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)),
|
||||||
End:
|
End:
|
||||||
item.endDate == null
|
item.endDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)),
|
||||||
? ""
|
|
||||||
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)),
|
|
||||||
Date:
|
Date:
|
||||||
item.startDate && item.endDate
|
item.startDate && item.endDate
|
||||||
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
|
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
|
||||||
|
|
@ -1329,8 +1331,8 @@ export class ProfileEmployeeController extends Controller {
|
||||||
.map((x) => x.next_holderId),
|
.map((x) => x.next_holderId),
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.andWhere("profileEmployee.employeeClass = :employeeClass", {employeeClass:"PERM"})
|
.andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "PERM" })
|
||||||
.skip((requestBody.page - 1) * requestBody.pageSize)
|
.skip((requestBody.page - 1) * requestBody.pageSize)
|
||||||
.take(requestBody.pageSize)
|
.take(requestBody.pageSize)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
@ -2757,6 +2759,9 @@ export class ProfileEmployeeController extends Controller {
|
||||||
profile.isLeave = requestBody.isLeave;
|
profile.isLeave = requestBody.isLeave;
|
||||||
profile.leaveReason = requestBody.leaveReason;
|
profile.leaveReason = requestBody.leaveReason;
|
||||||
profile.dateLeave = requestBody.dateLeave;
|
profile.dateLeave = requestBody.dateLeave;
|
||||||
|
if (requestBody.isLeave == true) {
|
||||||
|
await removeProfileInOrganize(profile.id);
|
||||||
|
}
|
||||||
await this.profileRepo.save(profile);
|
await this.profileRepo.save(profile);
|
||||||
|
|
||||||
const profileSalary = await this.salaryRepository.findOne({
|
const profileSalary = await this.salaryRepository.findOne({
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import { ProfileFamilyCouple } from "./ProfileFamilyCouple";
|
||||||
import { ProfileChildren } from "./ProfileChildren";
|
import { ProfileChildren } from "./ProfileChildren";
|
||||||
import { ProfileDiscipline } from "./ProfileDiscipline";
|
import { ProfileDiscipline } from "./ProfileDiscipline";
|
||||||
import { ProfileEmployee } from "./ProfileEmployee";
|
import { ProfileEmployee } from "./ProfileEmployee";
|
||||||
|
import { ProfileEdit } from "./ProfileEdit";
|
||||||
|
|
||||||
@Entity("profile")
|
@Entity("profile")
|
||||||
export class Profile extends EntityBase {
|
export class Profile extends EntityBase {
|
||||||
|
|
@ -340,6 +341,9 @@ export class Profile extends EntityBase {
|
||||||
@OneToMany(() => ProfileAvatar, (profileAvatar) => profileAvatar.profile)
|
@OneToMany(() => ProfileAvatar, (profileAvatar) => profileAvatar.profile)
|
||||||
profileAvatars: ProfileAvatar[];
|
profileAvatars: ProfileAvatar[];
|
||||||
|
|
||||||
|
@OneToMany(() => ProfileEdit, (profileEdit) => profileEdit.profile)
|
||||||
|
profileEdits: ProfileEdit[];
|
||||||
|
|
||||||
@OneToMany(() => ProfileFamilyHistory, (profileFamily) => profileFamily.profile)
|
@OneToMany(() => ProfileFamilyHistory, (profileFamily) => profileFamily.profile)
|
||||||
profileFamily: ProfileFamilyHistory[];
|
profileFamily: ProfileFamilyHistory[];
|
||||||
|
|
||||||
|
|
|
||||||
90
src/entities/ProfileEdit.ts
Normal file
90
src/entities/ProfileEdit.ts
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm";
|
||||||
|
import { EntityBase } from "./base/Base";
|
||||||
|
import { Profile } from "./Profile";
|
||||||
|
import { ProfileEmployee } from "./ProfileEmployee";
|
||||||
|
|
||||||
|
@Entity("profileEdit")
|
||||||
|
export class ProfileEdit extends EntityBase {
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
length: 40,
|
||||||
|
comment: "คีย์นอก(FK)ของตาราง Profile",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
profileId: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
length: 40,
|
||||||
|
comment: "คีย์นอก(FK)ของตาราง ProfileEmployee",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
profileEmployeeId: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "สถานะคำร้อง", //PENDING = รอดำเนินการ, COMPLETE = ดำเนินการแก้ไขแล้ว, REJECT = ไม่อนุมัตการแก้ไข
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
status: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "ชื่อเรื่อง",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
topic: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "รายละเอียด",
|
||||||
|
type: "text",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
detail: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "หมายเหตุ",
|
||||||
|
type: "text",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
remark: string;
|
||||||
|
|
||||||
|
@ManyToOne(() => Profile, (profile) => profile.profileEdits)
|
||||||
|
@JoinColumn({ name: "profileId" })
|
||||||
|
profile: Profile;
|
||||||
|
|
||||||
|
@ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileEdits)
|
||||||
|
@JoinColumn({ name: "profileEmployeeId" })
|
||||||
|
profileEmployee: ProfileEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateProfileEdit {
|
||||||
|
topic: string | null;
|
||||||
|
detail: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class EditProfileEdit {
|
||||||
|
topic?: string | null;
|
||||||
|
detail?: string | null;
|
||||||
|
remark?: string | null;
|
||||||
|
status?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateProfileEmployeeEdit {
|
||||||
|
topic: string | null;
|
||||||
|
detail: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class EditProfileEmployeeEdit {
|
||||||
|
topic?: string | null;
|
||||||
|
detail?: string | null;
|
||||||
|
remark?: string | null;
|
||||||
|
status?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdateProfileEdit = {
|
||||||
|
detail?: string | null;
|
||||||
|
date?: Date | null;
|
||||||
|
};
|
||||||
|
|
@ -28,8 +28,9 @@ import { Profile, ProfileAddressHistory } from "./Profile";
|
||||||
import { Province } from "./Province";
|
import { Province } from "./Province";
|
||||||
import { District } from "./District";
|
import { District } from "./District";
|
||||||
import { SubDistrict } from "./SubDistrict";
|
import { SubDistrict } from "./SubDistrict";
|
||||||
import { ProfileEmployeeInformationHistory } from "./ProfileEmployeeInformationHistory"
|
import { ProfileEmployeeInformationHistory } from "./ProfileEmployeeInformationHistory";
|
||||||
import { ProfileEmployeeEmployment } from "./ProfileEmployeeEmployment"
|
import { ProfileEmployeeEmployment } from "./ProfileEmployeeEmployment";
|
||||||
|
import { ProfileEdit } from "./ProfileEdit";
|
||||||
|
|
||||||
@Entity("profileEmployee")
|
@Entity("profileEmployee")
|
||||||
export class ProfileEmployee extends EntityBase {
|
export class ProfileEmployee extends EntityBase {
|
||||||
|
|
@ -628,6 +629,9 @@ export class ProfileEmployee extends EntityBase {
|
||||||
@OneToMany(() => ProfileAvatar, (v) => v.profileEmployee)
|
@OneToMany(() => ProfileAvatar, (v) => v.profileEmployee)
|
||||||
profileAvatars: ProfileAvatar[];
|
profileAvatars: ProfileAvatar[];
|
||||||
|
|
||||||
|
@OneToMany(() => ProfileEdit, (v) => v.profileEmployee)
|
||||||
|
profileEdits: ProfileEdit[];
|
||||||
|
|
||||||
@ManyToOne(() => EmployeePosLevel, (v) => v.profiles)
|
@ManyToOne(() => EmployeePosLevel, (v) => v.profiles)
|
||||||
posLevel: EmployeePosLevel;
|
posLevel: EmployeePosLevel;
|
||||||
|
|
||||||
|
|
|
||||||
18
src/migration/1721360319146-add_table_profileedit.ts
Normal file
18
src/migration/1721360319146-add_table_profileedit.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class AddTableProfileedit1721360319146 implements MigrationInterface {
|
||||||
|
name = 'AddTableProfileedit1721360319146'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`CREATE TABLE \`profileEdit\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง Profile', \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee', \`status\` varchar(255) NULL COMMENT 'สถานะคำร้อง', \`topic\` varchar(255) NULL COMMENT 'ชื่อเรื่อง', \`detail\` text NULL COMMENT 'รายละเอียด', \`remark\` text NULL COMMENT 'หมายเหตุ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileEdit\` ADD CONSTRAINT \`FK_2b0d0e34814f699c610b4643612\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileEdit\` ADD CONSTRAINT \`FK_d0f0021e6c8ba05a7b0b3e552e6\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileEdit\` DROP FOREIGN KEY \`FK_d0f0021e6c8ba05a7b0b3e552e6\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileEdit\` DROP FOREIGN KEY \`FK_2b0d0e34814f699c610b4643612\``);
|
||||||
|
await queryRunner.query(`DROP TABLE \`profileEdit\``);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue