user request data
This commit is contained in:
parent
939ed6ddfd
commit
d899039b9d
9 changed files with 688 additions and 6 deletions
377
src/controllers/DevelopmentRequestController.ts
Normal file
377
src/controllers/DevelopmentRequestController.ts
Normal file
|
|
@ -0,0 +1,377 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Query,
|
||||
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 { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { CreateDevelopmentRequest, DevelopmentRequest } from "../entities/DevelopmentRequest";
|
||||
import permission from "../interfaces/permission";
|
||||
import { Brackets } from "typeorm";
|
||||
import { DevelopmentProject } from "../entities/DevelopmentProject";
|
||||
import { ProfileDevelopment } from "../entities/ProfileDevelopment";
|
||||
import { ProfileDevelopmentHistory } from "../entities/ProfileDevelopmentHistory";
|
||||
@Route("api/v1/org/profile/development-request")
|
||||
@Tags("DevelopmentRequest")
|
||||
@Security("bearerAuth")
|
||||
export class DevelopmentRequestController extends Controller {
|
||||
private profileRepository = AppDataSource.getRepository(Profile);
|
||||
private profileDevelopmentRepository = AppDataSource.getRepository(ProfileDevelopment);
|
||||
private developmentRequestRepository = AppDataSource.getRepository(DevelopmentRequest);
|
||||
private developmentProjectRepository = AppDataSource.getRepository(DevelopmentProject);
|
||||
private developmentHistoryRepository = AppDataSource.getRepository(ProfileDevelopmentHistory);
|
||||
|
||||
@Get("user")
|
||||
public async getDevelopmentRequestUser(
|
||||
@Request() req: RequestWithUser,
|
||||
@Query("keyword") keyword: string = "",
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("status") status?: string,
|
||||
) {
|
||||
const profile = await this.profileRepository.findOneBy({ keycloak: req.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const [lists, total] = await AppDataSource.getRepository(DevelopmentRequest)
|
||||
.createQueryBuilder("developmentRequest")
|
||||
.andWhere(
|
||||
status == undefined || status.trim().toUpperCase() == "ALL" || status == ""
|
||||
? "1=1"
|
||||
: "developmentRequest.status = :status",
|
||||
{
|
||||
status: status == undefined || status == null ? "" : status.trim().toUpperCase(),
|
||||
},
|
||||
)
|
||||
.andWhere("developmentRequest.profileId = :profileId", { profileId: profile.id })
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != null && keyword != "" ? "developmentRequest.reason LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != "" ? "developmentRequest.name LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != ""
|
||||
? "developmentRequest.developmentTarget LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != ""
|
||||
? "developmentRequest.developmentResults LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != ""
|
||||
? "developmentRequest.developmentReport LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.orderBy("developmentRequest.createdAt", "ASC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
return new HttpSuccess({ data: lists, total });
|
||||
}
|
||||
|
||||
@Get("admin")
|
||||
public async getDevelopmentRequestAdmin(
|
||||
@Request() req: RequestWithUser,
|
||||
@Query("status") status: string,
|
||||
@Query("keyword") keyword: string = "",
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
) {
|
||||
// await new permission().PermissionList(req, "SYS_REGISTRY_OFFICER");
|
||||
const [lists, total] = await AppDataSource.getRepository(DevelopmentRequest)
|
||||
.createQueryBuilder("developmentRequest")
|
||||
.andWhere(
|
||||
status == undefined || status.trim().toUpperCase() == "ALL" || status == ""
|
||||
? "1=1"
|
||||
: "developmentRequest.status = :status",
|
||||
{
|
||||
status: status == undefined || status == null ? "" : status.trim().toUpperCase(),
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != null && keyword != "" ? "developmentRequest.reason LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != "" ? "developmentRequest.name LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != ""
|
||||
? "developmentRequest.developmentTarget LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != ""
|
||||
? "developmentRequest.developmentResults LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != null && keyword != ""
|
||||
? "developmentRequest.developmentReport LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.orderBy("developmentRequest.createdAt", "ASC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
return new HttpSuccess({ data: lists, total });
|
||||
}
|
||||
|
||||
@Get("admin/{id}")
|
||||
public async getDevelopmentRequestByUser(@Path() id: string, @Request() req: RequestWithUser) {
|
||||
await new permission().PermissionGet(req, "SYS_REGISTRY_OFFICER");
|
||||
const data = await this.developmentRequestRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["developmentProjects"],
|
||||
});
|
||||
if (!data) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const _data = {
|
||||
...data,
|
||||
developmentProjects: data.developmentProjects.map((x) => x.name),
|
||||
};
|
||||
return new HttpSuccess(_data);
|
||||
}
|
||||
|
||||
@Get("user/{id}")
|
||||
public async getDevelopmentRequestByAdmin(@Path() id: string, @Request() req: RequestWithUser) {
|
||||
const data = await this.developmentRequestRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["developmentProjects"],
|
||||
});
|
||||
if (!data) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const _data = {
|
||||
...data,
|
||||
developmentProjects: data.developmentProjects.map((x) => x.name),
|
||||
};
|
||||
return new HttpSuccess(_data);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newDevelopmentRequest(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateDevelopmentRequest,
|
||||
) {
|
||||
const profile = await this.profileRepository.findOneBy({ keycloak: req.user.sub });
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const data = new DevelopmentRequest();
|
||||
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
data.profileId = profile.id;
|
||||
data.status = "PENDING";
|
||||
await this.developmentRequestRepository.save(data);
|
||||
|
||||
if (body.developmentProjects != null) {
|
||||
await Promise.all(
|
||||
body.developmentProjects.map(async (x) => {
|
||||
let developmentProject = new DevelopmentProject();
|
||||
developmentProject.name = x;
|
||||
developmentProject.createdUserId = req.user.sub;
|
||||
developmentProject.createdFullName = req.user.name;
|
||||
developmentProject.lastUpdateUserId = req.user.sub;
|
||||
developmentProject.lastUpdateFullName = req.user.name;
|
||||
developmentProject.createdAt = new Date();
|
||||
developmentProject.lastUpdatedAt = new Date();
|
||||
developmentProject.developmentRequestId = data.id;
|
||||
await this.developmentProjectRepository.save(developmentProject);
|
||||
}),
|
||||
);
|
||||
}
|
||||
return new HttpSuccess(data.id);
|
||||
}
|
||||
|
||||
@Patch("user/{developmentId}")
|
||||
public async editUserDevelopmentRequest(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateDevelopmentRequest,
|
||||
@Path() developmentId: string,
|
||||
) {
|
||||
const record = await this.developmentRequestRepository.findOne({
|
||||
where: { id: developmentId },
|
||||
relations: ["developmentProjects"],
|
||||
});
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
Object.assign(record, body);
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdatedAt = new Date();
|
||||
|
||||
await this.developmentRequestRepository.save(record);
|
||||
await this.developmentProjectRepository.delete({ developmentRequestId: record.id });
|
||||
if (body.developmentProjects != null) {
|
||||
await Promise.all(
|
||||
body.developmentProjects.map(async (x) => {
|
||||
let developmentProject = new DevelopmentProject();
|
||||
developmentProject.name = x;
|
||||
developmentProject.createdUserId = req.user.sub;
|
||||
developmentProject.createdFullName = req.user.name;
|
||||
developmentProject.lastUpdateUserId = req.user.sub;
|
||||
developmentProject.lastUpdateFullName = req.user.name;
|
||||
developmentProject.createdAt = new Date();
|
||||
developmentProject.lastUpdatedAt = new Date();
|
||||
developmentProject.developmentRequestId = record.id;
|
||||
await this.developmentProjectRepository.save(developmentProject);
|
||||
}),
|
||||
);
|
||||
}
|
||||
return new HttpSuccess(record.id);
|
||||
}
|
||||
|
||||
@Patch("admin/{developmentId}")
|
||||
public async editAdminDevelopmentRequest(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body()
|
||||
requestBody: { reason?: string | null; status: string },
|
||||
@Path() developmentId: string,
|
||||
) {
|
||||
const record = await this.developmentRequestRepository.findOne({
|
||||
where: { id: developmentId },
|
||||
relations: ["developmentProjects"],
|
||||
});
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_OFFICER");
|
||||
requestBody.status = requestBody.status.trim().toUpperCase();
|
||||
Object.assign(record, requestBody);
|
||||
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdatedAt = new Date();
|
||||
|
||||
await this.developmentRequestRepository.save(record);
|
||||
if (requestBody.status == "APPROVE") {
|
||||
let profileDevelopment = new ProfileDevelopment();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
Object.assign(profileDevelopment, {
|
||||
...record,
|
||||
...meta,
|
||||
id: undefined,
|
||||
type: "REQUEST",
|
||||
developmentProject: [],
|
||||
});
|
||||
await this.profileDevelopmentRepository.save(profileDevelopment);
|
||||
|
||||
const history = new ProfileDevelopmentHistory();
|
||||
Object.assign(history, {
|
||||
...profileDevelopment,
|
||||
id: undefined,
|
||||
type: "REQUEST",
|
||||
developmentProject: [],
|
||||
});
|
||||
history.profileDevelopmentId = profileDevelopment.id;
|
||||
await this.developmentHistoryRepository.save(history);
|
||||
|
||||
if (record.developmentProjects != null) {
|
||||
await Promise.all(
|
||||
record.developmentProjects.map(async (x) => {
|
||||
let developmentProject = new DevelopmentProject();
|
||||
let developmentProjectHistory = new DevelopmentProject();
|
||||
Object.assign(developmentProject, {
|
||||
...meta,
|
||||
id: undefined,
|
||||
name: record.name,
|
||||
profileDevelopmentId: profileDevelopment.id,
|
||||
});
|
||||
Object.assign(developmentProject, {
|
||||
...meta,
|
||||
id: undefined,
|
||||
name: record.name,
|
||||
profileDevelopmentHistoryId: history.id,
|
||||
});
|
||||
await Promise.all([
|
||||
this.developmentProjectRepository.save(developmentProject),
|
||||
this.developmentProjectRepository.save(developmentProjectHistory),
|
||||
]);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpSuccess(record.id);
|
||||
}
|
||||
|
||||
@Delete("{id}")
|
||||
public async deleteDevelopmentRequest(@Path() id: string, @Request() req: RequestWithUser) {
|
||||
const developmentRequest = await this.developmentRequestRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!developmentRequest) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลคำขอนี้");
|
||||
}
|
||||
await this.developmentProjectRepository.delete({ developmentRequestId: id });
|
||||
await this.developmentRequestRepository.delete({ id });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -154,7 +154,7 @@ export class ProfileController extends Controller {
|
|||
},
|
||||
});
|
||||
ImgUrl = response_.data.downloadUrl;
|
||||
} catch { }
|
||||
} catch {}
|
||||
}
|
||||
const province = await this.provinceRepository.findOneBy({
|
||||
id: profile.registrationProvinceId,
|
||||
|
|
@ -319,7 +319,7 @@ export class ProfileController extends Controller {
|
|||
},
|
||||
});
|
||||
ImgUrl = response_.data.downloadUrl;
|
||||
} catch { }
|
||||
} catch {}
|
||||
}
|
||||
const profileOc = await this.profileRepo.findOne({
|
||||
relations: [
|
||||
|
|
@ -2679,7 +2679,7 @@ export class ProfileController extends Controller {
|
|||
|
||||
@Get("admin/{id}")
|
||||
async getProfileAdmin(@Path() id: string) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
const profile: any = await this.profileRepo.findOne({
|
||||
relations: {
|
||||
posLevel: true,
|
||||
posType: true,
|
||||
|
|
@ -2688,7 +2688,7 @@ export class ProfileController extends Controller {
|
|||
});
|
||||
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
profile.profileType = "OFFICER";
|
||||
return new HttpSuccess(profile);
|
||||
}
|
||||
|
||||
|
|
|
|||
139
src/entities/DevelopmentRequest.ts
Normal file
139
src/entities/DevelopmentRequest.ts
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
import { Entity, Column, OneToMany, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { Profile } from "./Profile";
|
||||
import { ProfileEmployee } from "./ProfileEmployee";
|
||||
import { DevelopmentProject } from "./DevelopmentProject";
|
||||
|
||||
@Entity("developmentRequest")
|
||||
export class DevelopmentRequest extends EntityBase {
|
||||
//PENDING รอดำเนินการ
|
||||
//APPROVE อนุมัติ
|
||||
//REJECT ไม่อนุมัติ
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "สถานะ",
|
||||
default: null,
|
||||
})
|
||||
status: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "หมายเหตุ",
|
||||
default: null,
|
||||
})
|
||||
reason: string;
|
||||
|
||||
@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: "ชื่อเรื่อง",
|
||||
default: null,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
comment: "วิธีพัฒนา70",
|
||||
default: false,
|
||||
})
|
||||
isDevelopment70: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "วิธีพัฒนา20",
|
||||
default: false,
|
||||
})
|
||||
isDevelopment20: boolean;
|
||||
|
||||
@Column({
|
||||
comment: "วิธีพัฒนา10",
|
||||
default: false,
|
||||
})
|
||||
isDevelopment10: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รายละเอียดอื่นๆ 70 แผน",
|
||||
default: null,
|
||||
})
|
||||
reasonDevelopment70: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รายละเอียดอื่นๆ 20 แผน",
|
||||
default: null,
|
||||
})
|
||||
reasonDevelopment20: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รายละเอียดอื่นๆ 10 แผน",
|
||||
default: null,
|
||||
})
|
||||
reasonDevelopment10: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "เป้าหมายการนำไปพัฒนางาน",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
developmentTarget: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "วิธีการวัดผลการพัฒนา",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
developmentResults: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รายงานผลการพัฒนา",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
developmentReport: string;
|
||||
|
||||
@ManyToOne(() => Profile, (profile) => profile.developmentRequests)
|
||||
@JoinColumn({ name: "profileId" })
|
||||
profile: Profile;
|
||||
|
||||
@ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.developmentRequests)
|
||||
@JoinColumn({ name: "profileEmployeeId" })
|
||||
profileEmployee: ProfileEmployee;
|
||||
|
||||
@OneToMany(
|
||||
() => DevelopmentProject,
|
||||
(developmentProject) => developmentProject.developmentRequest,
|
||||
)
|
||||
developmentProjects: DevelopmentProject[];
|
||||
}
|
||||
|
||||
export class CreateDevelopmentRequest {
|
||||
name: string | null;
|
||||
developmentTarget: string | null;
|
||||
developmentResults: string | null;
|
||||
developmentReport: string | null;
|
||||
reasonDevelopment70?: string | null;
|
||||
reasonDevelopment20?: string | null;
|
||||
reasonDevelopment10?: string | null;
|
||||
isDevelopment70: boolean | null;
|
||||
isDevelopment20: boolean | null;
|
||||
isDevelopment10: boolean | null;
|
||||
developmentProjects?: string[];
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ import { OrgRoot } from "./OrgRoot";
|
|||
import { PermissionOrg } from "./PermissionOrg";
|
||||
import { CommandSend } from "./CommandSend";
|
||||
import { CommandRecive } from "./CommandRecive";
|
||||
import { DevelopmentRequest } from "./DevelopmentRequest";
|
||||
|
||||
@Entity("profile")
|
||||
export class Profile extends EntityBase {
|
||||
|
|
@ -346,6 +347,9 @@ export class Profile extends EntityBase {
|
|||
@OneToMany(() => ProfileDevelopment, (profileDevelopment) => profileDevelopment.profile)
|
||||
profileDevelopments: ProfileDevelopment[];
|
||||
|
||||
@OneToMany(() => DevelopmentRequest, (developmentRequest) => developmentRequest.profile)
|
||||
developmentRequests: DevelopmentRequest[];
|
||||
|
||||
@OneToMany(() => ProfileAvatar, (profileAvatar) => profileAvatar.profile)
|
||||
profileAvatars: ProfileAvatar[];
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,20 @@ import { EntityBase } from "./base/Base";
|
|||
import { Profile } from "./Profile";
|
||||
import { ProfileEmployee } from "./ProfileEmployee";
|
||||
import { ProfileDevelopmentHistory } from "./ProfileDevelopmentHistory";
|
||||
import { DevelopmentProject } from "./DevelopmentProject";
|
||||
|
||||
@Entity("profileDevelopment")
|
||||
export class ProfileDevelopment extends EntityBase {
|
||||
// REQUEST = ขอแก้ไข
|
||||
// DEVELOP = พัฒนา
|
||||
// KPI = ประเมิน
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ระบบ",
|
||||
default: null,
|
||||
})
|
||||
type: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
|
|
@ -111,6 +122,30 @@ export class ProfileDevelopment extends EntityBase {
|
|||
})
|
||||
reasonDevelopment10: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "เป้าหมายการนำไปพัฒนางาน",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
developmentTarget: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "วิธีการวัดผลการพัฒนา",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
developmentResults: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รายงานผลการพัฒนา",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
developmentReport: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
|
|
@ -132,9 +167,16 @@ export class ProfileDevelopment extends EntityBase {
|
|||
@ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileDevelopments)
|
||||
@JoinColumn({ name: "profileEmployeeId" })
|
||||
profileEmployee: ProfileEmployee;
|
||||
|
||||
@OneToMany(
|
||||
() => DevelopmentProject,
|
||||
(developmentProject) => developmentProject.profileDevelopment,
|
||||
)
|
||||
developmentProjects: DevelopmentProject[];
|
||||
}
|
||||
|
||||
export class CreateProfileDevelopment {
|
||||
type?: string | null;
|
||||
profileId: string | null;
|
||||
name: string | null;
|
||||
target: string | null;
|
||||
|
|
@ -153,6 +195,7 @@ export class CreateProfileDevelopment {
|
|||
}
|
||||
|
||||
export class CreateProfileEmployeeDevelopment {
|
||||
type?: string | null;
|
||||
profileEmployeeId: string | null;
|
||||
name: string | null;
|
||||
target: string | null;
|
||||
|
|
@ -171,6 +214,7 @@ export class CreateProfileEmployeeDevelopment {
|
|||
}
|
||||
|
||||
export type UpdateProfileDevelopment = {
|
||||
type?: string | null;
|
||||
name: string | null;
|
||||
target: string | null;
|
||||
achievement10?: string | null;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,20 @@
|
|||
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { ProfileDevelopment } from "./ProfileDevelopment";
|
||||
import { DevelopmentProject } from "./DevelopmentProject";
|
||||
|
||||
@Entity("profileDevelopmentHistory")
|
||||
export class ProfileDevelopmentHistory extends EntityBase {
|
||||
// REQUEST = ขอแก้ไข
|
||||
// DEVELOP = พัฒนา
|
||||
// KPI = ประเมิน
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ระบบ",
|
||||
default: null,
|
||||
})
|
||||
type: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ชื่อเรื่อง",
|
||||
|
|
@ -93,6 +104,30 @@ export class ProfileDevelopmentHistory extends EntityBase {
|
|||
})
|
||||
reasonDevelopment10: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "เป้าหมายการนำไปพัฒนางาน",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
developmentTarget: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "วิธีการวัดผลการพัฒนา",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
developmentResults: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รายงานผลการพัฒนา",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
developmentReport: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
|
|
@ -115,4 +150,10 @@ export class ProfileDevelopmentHistory extends EntityBase {
|
|||
)
|
||||
@JoinColumn({ name: "profileDevelopmentId" })
|
||||
histories: ProfileDevelopment;
|
||||
|
||||
@OneToMany(
|
||||
() => DevelopmentProject,
|
||||
(developmentProject) => developmentProject.profileDevelopmentHistory,
|
||||
)
|
||||
developmentProjects: DevelopmentProject[];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import { ProfileEmployeeInformationHistory } from "./ProfileEmployeeInformationH
|
|||
import { ProfileEmployeeEmployment } from "./ProfileEmployeeEmployment";
|
||||
import { ProfileEdit } from "./ProfileEdit";
|
||||
import { ProfileDevelopment } from "./ProfileDevelopment";
|
||||
import { DevelopmentRequest } from "./DevelopmentRequest";
|
||||
|
||||
@Entity("profileEmployee")
|
||||
export class ProfileEmployee extends EntityBase {
|
||||
|
|
@ -630,6 +631,9 @@ export class ProfileEmployee extends EntityBase {
|
|||
@OneToMany(() => ProfileDevelopment, (v) => v.profileEmployee)
|
||||
profileDevelopments: ProfileDevelopment[];
|
||||
|
||||
@OneToMany(() => DevelopmentRequest, (v) => v.profileEmployee)
|
||||
developmentRequests: DevelopmentRequest[];
|
||||
|
||||
@OneToMany(() => ProfileAvatar, (v) => v.profileEmployee)
|
||||
profileAvatars: ProfileAvatar[];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import { Entity, Column } from "typeorm";
|
||||
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { ProfileDevelopment } from "./ProfileDevelopment";
|
||||
import { ProfileDevelopmentHistory } from "./ProfileDevelopmentHistory";
|
||||
import { DevelopmentRequest } from "./DevelopmentRequest";
|
||||
|
||||
@Entity("developmentProject")
|
||||
export class DevelopmentProject extends EntityBase {
|
||||
|
|
@ -27,12 +30,40 @@ export class DevelopmentProject extends EntityBase {
|
|||
})
|
||||
profileDevelopmentId: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => ProfileDevelopment,
|
||||
(profileDevelopment) => profileDevelopment.developmentProjects,
|
||||
)
|
||||
@JoinColumn({ name: "profileDevelopmentId" })
|
||||
profileDevelopment: ProfileDevelopment;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "โครงการ/หลักสูตรการฝึกอบรม",
|
||||
default: null,
|
||||
})
|
||||
profileDevelopmentHistoryId: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => ProfileDevelopmentHistory,
|
||||
(profileDevelopmentHistory) => profileDevelopmentHistory.developmentProjects,
|
||||
)
|
||||
@JoinColumn({ name: "profileDevelopmentHistoryId" })
|
||||
profileDevelopmentHistory: ProfileDevelopmentHistory;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "โครงการ/หลักสูตรการฝึกอบรม",
|
||||
default: null,
|
||||
})
|
||||
developmentRequestId: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => DevelopmentRequest,
|
||||
(developmentRequest) => developmentRequest.developmentProjects,
|
||||
)
|
||||
@JoinColumn({ name: "developmentRequestId" })
|
||||
developmentRequest: DevelopmentRequest;
|
||||
}
|
||||
export class CreateDevelopmentProject {
|
||||
@Column()
|
||||
|
|
|
|||
42
src/migration/1727689358961-add_table_developmentRequest.ts
Normal file
42
src/migration/1727689358961-add_table_developmentRequest.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddTableDevelopmentRequest1727689358961 implements MigrationInterface {
|
||||
name = 'AddTableDevelopmentRequest1727689358961'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE \`developmentRequest\` (\`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', \`status\` varchar(255) NULL COMMENT 'สถานะ', \`reason\` varchar(255) NULL COMMENT 'หมายเหตุ', \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง Profile', \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee', \`name\` varchar(255) NULL COMMENT 'ชื่อเรื่อง', \`isDevelopment70\` tinyint NOT NULL COMMENT 'วิธีพัฒนา70' DEFAULT 0, \`isDevelopment20\` tinyint NOT NULL COMMENT 'วิธีพัฒนา20' DEFAULT 0, \`isDevelopment10\` tinyint NOT NULL COMMENT 'วิธีพัฒนา10' DEFAULT 0, \`reasonDevelopment70\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 70 แผน', \`reasonDevelopment20\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 20 แผน', \`reasonDevelopment10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน', \`developmentTarget\` varchar(255) NULL COMMENT 'เป้าหมายการนำไปพัฒนางาน', \`developmentResults\` varchar(255) NULL COMMENT 'วิธีการวัดผลการพัฒนา', \`developmentReport\` varchar(255) NULL COMMENT 'รายงานผลการพัฒนา', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` ADD \`developmentRequestId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopmentHistory\` ADD \`type\` varchar(255) NULL COMMENT 'ระบบ'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopmentHistory\` ADD \`developmentTarget\` varchar(255) NULL COMMENT 'เป้าหมายการนำไปพัฒนางาน'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopmentHistory\` ADD \`developmentResults\` varchar(255) NULL COMMENT 'วิธีการวัดผลการพัฒนา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopmentHistory\` ADD \`developmentReport\` varchar(255) NULL COMMENT 'รายงานผลการพัฒนา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopment\` ADD \`type\` varchar(255) NULL COMMENT 'ระบบ'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopment\` ADD \`developmentTarget\` varchar(255) NULL COMMENT 'เป้าหมายการนำไปพัฒนางาน'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopment\` ADD \`developmentResults\` varchar(255) NULL COMMENT 'วิธีการวัดผลการพัฒนา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopment\` ADD \`developmentReport\` varchar(255) NULL COMMENT 'รายงานผลการพัฒนา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentRequest\` ADD CONSTRAINT \`FK_0dd78a592b78ee0db5b2c8386d2\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentRequest\` ADD CONSTRAINT \`FK_0c08cab1ebc7e022cad0c6a7556\` FOREIGN KEY (\`profileEmployeeId\`) REFERENCES \`profileEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` ADD CONSTRAINT \`FK_4913ef1466f9f35c1429e213d4b\` FOREIGN KEY (\`profileDevelopmentId\`) REFERENCES \`profileDevelopment\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` ADD CONSTRAINT \`FK_8e3f2e86427befeff4283ae80f0\` FOREIGN KEY (\`profileDevelopmentHistoryId\`) REFERENCES \`profileDevelopmentHistory\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` ADD CONSTRAINT \`FK_e2819f1edc526aa71ac127418fa\` FOREIGN KEY (\`developmentRequestId\`) REFERENCES \`developmentRequest\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` DROP FOREIGN KEY \`FK_e2819f1edc526aa71ac127418fa\``);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` DROP FOREIGN KEY \`FK_8e3f2e86427befeff4283ae80f0\``);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` DROP FOREIGN KEY \`FK_4913ef1466f9f35c1429e213d4b\``);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentRequest\` DROP FOREIGN KEY \`FK_0c08cab1ebc7e022cad0c6a7556\``);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentRequest\` DROP FOREIGN KEY \`FK_0dd78a592b78ee0db5b2c8386d2\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopment\` DROP COLUMN \`developmentReport\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopment\` DROP COLUMN \`developmentResults\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopment\` DROP COLUMN \`developmentTarget\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopment\` DROP COLUMN \`type\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopmentHistory\` DROP COLUMN \`developmentReport\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopmentHistory\` DROP COLUMN \`developmentResults\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopmentHistory\` DROP COLUMN \`developmentTarget\``);
|
||||
await queryRunner.query(`ALTER TABLE \`profileDevelopmentHistory\` DROP COLUMN \`type\``);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` DROP COLUMN \`developmentRequestId\``);
|
||||
await queryRunner.query(`DROP TABLE \`developmentRequest\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue