แก้ วันที่ update

This commit is contained in:
kittapath 2024-08-30 18:02:34 +07:00
parent 6d36c9b05f
commit 218886b3f4
83 changed files with 1671 additions and 3483 deletions

View file

@ -2,7 +2,6 @@ import {
Body,
Controller,
Delete,
Example,
Get,
Patch,
Path,
@ -18,9 +17,7 @@ import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { ProfileChangeNameHistory } from "../entities/ProfileChangeNameHistory";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import {
CreateProfileChangeName,
CreateProfileChangeNameEmployee,
ProfileChangeName,
UpdateProfileChangeName,
@ -44,78 +41,33 @@ export class ProfileChangeNameEmployeeController extends Controller {
}
const lists = await this.changeNameRepository.find({
where: { profileEmployeeId: profile.id },
select: ["id", "prefix", "firstName", "lastName", "status"],
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@Get("{profileEmployeeId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
prefix: "string",
firstName: "string",
lastName: "string",
status: "string",
},
],
})
public async getChangeName(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const lists = await this.changeNameRepository.find({
where: { profileEmployeeId: profileEmployeeId },
select: ["id", "prefix", "firstName", "lastName", "status"],
order: { createdAt: "ASC" },
});
return new HttpSuccess(lists);
}
@Get("history/{changeNameId}")
@Example({
status: 200,
message: "สำเร็จ",
result: [
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
prefix: "string",
firstName: "string",
lastName: "string",
status: "string",
createdFullName: "string",
createdAt: "string",
},
{
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
prefix: "string",
firstName: "string",
lastName: "string",
status: "string",
createdFullName: "string",
createdAt: "string",
},
],
})
public async changeNameHistory(@Path() changeNameId: string, @Request() req: RequestWithUser) {
const _record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId,
);
}
const _record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (_record) {
await new permission().PermissionOrgUserGet(
req,
"SYS_REGISTRY_EMP",
_record.profileEmployeeId,
);
}
const record = await this.changeNameHistoryRepository.find({
where: { profileChangeNameId: changeNameId },
select: [
"id",
"prefix",
"firstName",
"lastName",
"status",
"lastUpdateFullName",
"lastUpdatedAt",
],
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
@ -129,7 +81,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
}
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
@ -143,6 +95,8 @@ export class ProfileChangeNameEmployeeController extends Controller {
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
Object.assign(data, { ...body, ...meta });
@ -176,20 +130,27 @@ export class ProfileChangeNameEmployeeController extends Controller {
) {
const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId);
await new permission().PermissionOrgUserUpdate(
req,
"SYS_REGISTRY_EMP",
record.profileEmployeeId,
);
const history = new ProfileChangeNameHistory();
Object.assign(record, body);
Object.assign(history, body);
Object.assign(history, { ...body, id: undefined });
history.profileChangeNameId = changeNameId;
record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name;
record.lastUpdatedAt = new Date();
history.lastUpdateUserId = req.user.sub;
history.lastUpdateFullName = req.user.name;
history.createdUserId = req.user.sub;
history.createdFullName = req.user.name;
history.createdAt = new Date();
history.lastUpdatedAt = new Date();
await Promise.all([
this.changeNameRepository.save(record),
@ -220,10 +181,14 @@ export class ProfileChangeNameEmployeeController extends Controller {
@Delete("{changeNameId}")
public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) {
const _record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const _record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (_record) {
await new permission().PermissionOrgUserDelete(
req,
"SYS_REGISTRY_EMP",
_record.profileEmployeeId,
);
}
await this.changeNameHistoryRepository.delete({
profileChangeNameId: changeNameId,
});