ข้อมูลราชการเเละบันทึกไม่ได้รับเงินเดือน
วินัย การลา ปฎิบัติราชการพิเศษ
This commit is contained in:
parent
4faefe54f3
commit
ea31c06fba
4 changed files with 748 additions and 0 deletions
153
src/controllers/ProfileEmployeeNopaidController.ts
Normal file
153
src/controllers/ProfileEmployeeNopaidController.ts
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
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 { ProfileNopaidHistory } from "../entities/ProfileNopaidHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { CreateProfileNopaid, ProfileNopaid, UpdateProfileNopaid } from "../entities/ProfileNopaid";
|
||||
|
||||
@Route("api/v1/org/profile/nopaid")
|
||||
@Tags("ProfileNopaid")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileNopaidController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||
private nopaidRepository = AppDataSource.getRepository(ProfileNopaid);
|
||||
private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory);
|
||||
|
||||
@Get("{profileId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||
date: "2024-03-12T10:09:47.000Z",
|
||||
reference: "string",
|
||||
detail: "string",
|
||||
refCommandNo: "string",
|
||||
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getNopaid(@Path() profileId: string) {
|
||||
const lists = await this.nopaidRepository.find({
|
||||
where: { profileId },
|
||||
});
|
||||
return new HttpSuccess(lists);
|
||||
}
|
||||
|
||||
@Get("history/{nopaidId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||
date: "2024-03-12T10:09:47.000Z",
|
||||
reference: "string",
|
||||
detail: "string",
|
||||
refCommandNo: "string",
|
||||
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||
},
|
||||
{
|
||||
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||
date: "2024-03-12T10:09:47.000Z",
|
||||
reference: "string",
|
||||
detail: "string",
|
||||
refCommandNo: "string",
|
||||
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async nopaidHistory(@Path() nopaidId: string) {
|
||||
const record = await this.nopaidHistoryRepository.find({
|
||||
where: { profileNopaidId: nopaidId },
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newNopaid(@Request() req: RequestWithUser, @Body() body: CreateProfileNopaid) {
|
||||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
|
||||
}
|
||||
|
||||
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new ProfileNopaid();
|
||||
|
||||
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.nopaidRepository.save(data);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Patch("{nopaidId}")
|
||||
public async editNopaid(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: UpdateProfileNopaid,
|
||||
@Path() nopaidId: string,
|
||||
) {
|
||||
const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileNopaidHistory();
|
||||
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
Object.assign(record, body);
|
||||
history.profileNopaidId = nopaidId;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(record),
|
||||
this.nopaidHistoryRepository.save(history),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Delete("{nopaidId}")
|
||||
public async deleteTraning(@Path() nopaidId: string) {
|
||||
await this.nopaidHistoryRepository.delete({
|
||||
profileNopaidId: nopaidId,
|
||||
});
|
||||
|
||||
const result = await this.nopaidRepository.delete({ id: nopaidId });
|
||||
|
||||
if (result.affected && result.affected <= 0) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue