ข้อมูลอื่นๆ
This commit is contained in:
parent
2d582be2a1
commit
be804c356a
3 changed files with 179 additions and 1 deletions
155
src/controllers/ProfileEmployeeOtherController.ts
Normal file
155
src/controllers/ProfileEmployeeOtherController.ts
Normal file
|
|
@ -0,0 +1,155 @@
|
||||||
|
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 { ProfileOtherHistory } from "../entities/ProfileOtherHistory";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { Profile } from "../entities/Profile";
|
||||||
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
|
import {
|
||||||
|
CreateProfileEmployeeOther,
|
||||||
|
ProfileOther,
|
||||||
|
UpdateProfileOther,
|
||||||
|
} from "../entities/ProfileOther";
|
||||||
|
|
||||||
|
@Route("api/v1/org/profile/other")
|
||||||
|
@Tags("ProfileOther")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
export class ProfileOtherController extends Controller {
|
||||||
|
private profileRepository = AppDataSource.getRepository(ProfileEmployee);
|
||||||
|
private otherRepository = AppDataSource.getRepository(ProfileOther);
|
||||||
|
private otherHistoryRepository = AppDataSource.getRepository(ProfileOtherHistory);
|
||||||
|
|
||||||
|
@Get("{profileId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||||
|
isActive: true,
|
||||||
|
date: "2024-03-12T10:09:47.000Z",
|
||||||
|
reference: "string",
|
||||||
|
detail: "string",
|
||||||
|
refCommandNo: "string",
|
||||||
|
refCommandDate: "2024-03-12T10:09:47.000Z",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async getOther(@Path() profileId: string) {
|
||||||
|
const lists = await this.otherRepository.find({
|
||||||
|
where: { profileEmployeeId: profileId },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(lists);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("history/{otherId}")
|
||||||
|
@Example({
|
||||||
|
status: 200,
|
||||||
|
message: "สำเร็จ",
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||||
|
isActive: true,
|
||||||
|
date: "2024-03-12T10:09:47.000Z",
|
||||||
|
detail: "string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "debfa8a7-83fb-4801-a940-8ae74e7638d3",
|
||||||
|
isActive: true,
|
||||||
|
date: "2024-03-12T10:09:47.000Z",
|
||||||
|
detail: "string",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
public async otherHistory(@Path() otherId: string) {
|
||||||
|
const record = await this.otherHistoryRepository.find({
|
||||||
|
where: { profileOtherId: otherId },
|
||||||
|
order: { createdAt: "DESC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeOther) {
|
||||||
|
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 ProfileOther();
|
||||||
|
|
||||||
|
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.otherRepository.save(data);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("{otherId}")
|
||||||
|
public async editOther(
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
|
@Body() body: UpdateProfileOther,
|
||||||
|
@Path() otherId: string,
|
||||||
|
) {
|
||||||
|
const record = await this.otherRepository.findOneBy({ id: otherId });
|
||||||
|
|
||||||
|
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
|
const history = new ProfileOtherHistory();
|
||||||
|
|
||||||
|
Object.assign(history, { ...record, id: undefined });
|
||||||
|
Object.assign(record, body);
|
||||||
|
history.profileOtherId = otherId;
|
||||||
|
record.lastUpdateFullName = req.user.name;
|
||||||
|
history.lastUpdateFullName = req.user.name;
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
this.otherRepository.save(record),
|
||||||
|
this.otherHistoryRepository.save(history),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("{otherId}")
|
||||||
|
public async deleteTraning(@Path() otherId: string) {
|
||||||
|
await this.otherHistoryRepository.delete({
|
||||||
|
profileOtherId: otherId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.otherRepository.delete({ id: otherId });
|
||||||
|
|
||||||
|
if (result.affected && result.affected <= 0) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ import { ProfileChangeName } from "./ProfileChangeName";
|
||||||
import { ProfileFamilyHistory } from "./ProfileFamily";
|
import { ProfileFamilyHistory } from "./ProfileFamily";
|
||||||
import { ProfileEducation } from "./ProfileEducation";
|
import { ProfileEducation } from "./ProfileEducation";
|
||||||
import { ProfileAbility } from "./ProfileAbility";
|
import { ProfileAbility } from "./ProfileAbility";
|
||||||
|
import { ProfileOther } from "./ProfileOther";
|
||||||
@Entity("profileEmployee")
|
@Entity("profileEmployee")
|
||||||
export class ProfileEmployee extends EntityBase {
|
export class ProfileEmployee extends EntityBase {
|
||||||
@Column({
|
@Column({
|
||||||
|
|
@ -248,6 +249,9 @@ export class ProfileEmployee extends EntityBase {
|
||||||
@OneToMany(() => ProfileAbility, (v) => v.profileEmployee)
|
@OneToMany(() => ProfileAbility, (v) => v.profileEmployee)
|
||||||
profileAbilities: ProfileAbility[];
|
profileAbilities: ProfileAbility[];
|
||||||
|
|
||||||
|
@OneToMany(() => ProfileOther, (v) => v.profileEmployee)
|
||||||
|
profileOthers: ProfileOther[];
|
||||||
|
|
||||||
@ManyToOne(() => EmployeePosLevel, (v) => v.profiles)
|
@ManyToOne(() => EmployeePosLevel, (v) => v.profiles)
|
||||||
posLevel: EmployeePosLevel;
|
posLevel: EmployeePosLevel;
|
||||||
|
|
||||||
|
|
@ -291,7 +295,7 @@ export class CreateProfileEmployee {
|
||||||
gender: string | null;
|
gender: string | null;
|
||||||
relationship: string | null;
|
relationship: string | null;
|
||||||
bloodGroup: string | null;
|
bloodGroup: string | null;
|
||||||
email: string | null ;
|
email: string | null;
|
||||||
phone: string | null;
|
phone: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm";
|
import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm";
|
||||||
import { EntityBase } from "./base/Base";
|
import { EntityBase } from "./base/Base";
|
||||||
import { Profile } from "./Profile";
|
import { Profile } from "./Profile";
|
||||||
|
import { ProfileEmployee } from "./ProfileEmployee";
|
||||||
import { ProfileOtherHistory } from "./ProfileOtherHistory";
|
import { ProfileOtherHistory } from "./ProfileOtherHistory";
|
||||||
|
|
||||||
@Entity("profileOther")
|
@Entity("profileOther")
|
||||||
|
|
@ -13,6 +14,14 @@ export class ProfileOther extends EntityBase {
|
||||||
})
|
})
|
||||||
profileId: string;
|
profileId: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
length: 40,
|
||||||
|
comment: "คีย์นอก(FK)ของตาราง ProfileEmployee",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
profileEmployeeId: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
comment: "รายละเอียด",
|
comment: "รายละเอียด",
|
||||||
|
|
@ -35,6 +44,10 @@ export class ProfileOther extends EntityBase {
|
||||||
@ManyToOne(() => Profile, (profile) => profile.profileOthers)
|
@ManyToOne(() => Profile, (profile) => profile.profileOthers)
|
||||||
@JoinColumn({ name: "profileId" })
|
@JoinColumn({ name: "profileId" })
|
||||||
profile: Profile;
|
profile: Profile;
|
||||||
|
|
||||||
|
@ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileOthers)
|
||||||
|
@JoinColumn({ name: "profileEmployeeId" })
|
||||||
|
profileEmployee: ProfileEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateProfileOther {
|
export class CreateProfileOther {
|
||||||
|
|
@ -43,6 +56,12 @@ export class CreateProfileOther {
|
||||||
date: Date | null;
|
date: Date | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class CreateProfileEmployeeOther {
|
||||||
|
profileEmployeeId: string | null;
|
||||||
|
detail: string | null;
|
||||||
|
date: Date | null;
|
||||||
|
}
|
||||||
|
|
||||||
export type UpdateProfileOther = {
|
export type UpdateProfileOther = {
|
||||||
detail?: string | null;
|
detail?: string | null;
|
||||||
date?: Date | null;
|
date?: Date | null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue