แก้ วันที่ 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

@ -44,34 +44,6 @@ export class ProfileSalaryController extends Controller {
}
@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, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
const record = await this.salaryRepo.find({
@ -92,63 +64,16 @@ export class ProfileSalaryController extends Controller {
}
@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, @Request() req: RequestWithUser) {
const _record = await this.salaryRepo.findOneBy({ id: salaryId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
}
const record = await this.salaryHistoryRepo.findBy({
profileSalaryId: salaryId,
const record = await this.salaryHistoryRepo.find({
where: {
profileSalaryId: salaryId,
},
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
}
@ -158,7 +83,7 @@ export class ProfileSalaryController extends Controller {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
@ -178,6 +103,8 @@ export class ProfileSalaryController 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 });
@ -200,19 +127,22 @@ export class ProfileSalaryController extends Controller {
const record = await this.salaryRepo.findOneBy({ id: salaryId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const history = new ProfileSalaryHistory();
Object.assign(record, body);
Object.assign(history, body);
Object.assign(history, { ...body, id: undefined });
history.profileSalaryId = salaryId;
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.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]);
@ -223,7 +153,11 @@ export class ProfileSalaryController extends Controller {
public async deleteSalary(@Path() salaryId: string, @Request() req: RequestWithUser) {
const _record = await this.salaryRepo.findOneBy({ id: salaryId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", _record.profileId);
await new permission().PermissionOrgUserDelete(
req,
"SYS_REGISTRY_OFFICER",
_record.profileId,
);
}
await this.salaryHistoryRepo.delete({
profileSalaryId: salaryId,
@ -239,7 +173,11 @@ export class ProfileSalaryController extends Controller {
}
@Get("swap/{direction}/{salaryId}")
public async swapSalary(@Path() direction: string, salaryId: string, @Request() req: RequestWithUser) {
public async swapSalary(
@Path() direction: string,
salaryId: string,
@Request() req: RequestWithUser,
) {
const source_item = await this.salaryRepo.findOne({ where: { id: salaryId } });
// if (source_item) {
// await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", source_item.profileId);//ไม่แน่ใจOFFปิดไว้ก่อน