Merge branch 'develop' of https://github.com/Frappet/bma-ehr-probation into develop
This commit is contained in:
commit
86f04ed0f9
5 changed files with 128 additions and 15 deletions
|
|
@ -20,13 +20,15 @@ import { Survey } from "../entities/Survey";
|
|||
import { Assign } from "../entities/Assign";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import permission from "../interfaces/permission";
|
||||
import { Brackets } from "typeorm";
|
||||
|
||||
@Route("api/v1/probation/survey")
|
||||
@Tags("Survey")
|
||||
@Security("bearerAuth")
|
||||
// @Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
export class SurveyController extends Controller {
|
||||
private surveyRepository = AppDataSource.getRepository(Survey);
|
||||
|
|
@ -52,7 +54,10 @@ export class SurveyController extends Controller {
|
|||
order: { date_start: "DESC" },
|
||||
});
|
||||
if (!dataAssign) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบผลการประเมินการทดลองปฏิบัติหน้าที่ราชการนี้");
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบผลการประเมินการทดลองปฏิบัติหน้าที่ราชการนี้",
|
||||
);
|
||||
}
|
||||
const assign_id = dataAssign.id;
|
||||
|
||||
|
|
@ -74,17 +79,94 @@ export class SurveyController extends Controller {
|
|||
async PostSurvey(
|
||||
@Query() assign_id: string,
|
||||
@Body() requestBody: any,
|
||||
@Request() request: RequestWithUser
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const personalId = await new CallAPI()
|
||||
.GetData(request, "/org/profile/keycloak")
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
|
||||
const before = null;
|
||||
const data = await {
|
||||
...requestBody,
|
||||
personal_id: request.user.sub,
|
||||
personal_id: personalId,
|
||||
assign_id,
|
||||
createdUserId: request.user.sub,
|
||||
updateUserId: request.user.sub,
|
||||
};
|
||||
await this.surveyRepository.save(data, { data: request });
|
||||
setLogDataDiff(request, { before, after: data });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการผลสำรวจความคิดเห็นของ Admin
|
||||
*
|
||||
* @summary ผลสำรวจความคิดเห็นของ Admin
|
||||
*
|
||||
*/
|
||||
@Get("/admin")
|
||||
async GetSurveyAdmin(
|
||||
@Query() year: number = new Date().getFullYear(),
|
||||
@Query() keyword: string = "",
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
// await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||
const start = new Date("01-01-" + year);
|
||||
const end = new Date("12-31-" + year);
|
||||
|
||||
const searchKeyword = await (keyword ? keyword.trim() : null);
|
||||
|
||||
const [lists, total] = await AppDataSource.getRepository(Survey)
|
||||
.createQueryBuilder("survey")
|
||||
.leftJoinAndSelect("survey.personal", "personal")
|
||||
.where(`survey.createdAt BETWEEN '${start.toISOString()}' AND '${end.toISOString()}'`)
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(
|
||||
searchKeyword
|
||||
? `CONCAT(personal.prefixName, personal.firstName," ",personal.lastName) like '%${keyword}%'`
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${searchKeyword}%`,
|
||||
},
|
||||
);
|
||||
qb.orWhere(
|
||||
searchKeyword
|
||||
? `CONCAT(personal.positionName, personal.positionLevelName) like '%${keyword}%'`
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${searchKeyword}%`,
|
||||
},
|
||||
);
|
||||
}),
|
||||
)
|
||||
.orderBy("survey.createdAt", "DESC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
const data = lists.map((item) => {
|
||||
return {
|
||||
createdAt: item.createdAt,
|
||||
personal_id: item.personal_id,
|
||||
assign_id: item.assign_id,
|
||||
answer1: item.answer1,
|
||||
answer2: item.answer2,
|
||||
answer3: item.answer3,
|
||||
fullname: item.personal
|
||||
? `${item.personal.prefixName}${item.personal.firstName} ${item.personal.lastName}`
|
||||
: "",
|
||||
position: item.personal
|
||||
? `${item.personal.positionName}${item.personal.positionLevelName}`
|
||||
: "",
|
||||
};
|
||||
});
|
||||
|
||||
return new HttpSuccess({ data, total: total });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany
|
|||
import { EntityBase } from "./base/Base";
|
||||
import { Assign } from "./Assign";
|
||||
import { Appoint } from "./Appoint";
|
||||
import { Survey } from "./Survey";
|
||||
|
||||
@Entity("personal")
|
||||
export class Personal extends EntityBase {
|
||||
|
|
@ -124,9 +125,10 @@ export class Personal extends EntityBase {
|
|||
@OneToOne(() => Appoint, (appoint) => appoint.personal)
|
||||
@JoinColumn()
|
||||
appoint: Appoint;
|
||||
// @OneToOne(() => Appoint, (appoint: Appoint) => appoint.profileId)
|
||||
// @JoinColumn({ name: "personal_id" })
|
||||
// appoint: Appoint
|
||||
|
||||
@OneToOne(() => Survey, (survey) => survey.personal)
|
||||
@JoinColumn({ name: "personal_id" })
|
||||
survey: Survey;
|
||||
}
|
||||
|
||||
export class CreatePersonal {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from "typeorm";
|
||||
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn, OneToOne } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { Assign } from "./Assign";
|
||||
import { Personal } from "./Personal";
|
||||
|
||||
@Entity("survey")
|
||||
export class Survey extends EntityBase {
|
||||
|
|
@ -48,6 +43,10 @@ export class Survey extends EntityBase {
|
|||
@ManyToOne(() => Assign, (assign: Assign) => assign.surveys)
|
||||
@JoinColumn({ name: "assign_id" })
|
||||
assign: Assign;
|
||||
|
||||
@OneToOne(() => Personal, (person) => person.survey, { cascade: true })
|
||||
@JoinColumn({ name: "personal_id" })
|
||||
personal: Personal;
|
||||
}
|
||||
|
||||
export class CreateSurvel {
|
||||
|
|
|
|||
14
src/migration/1737442569342-updateRelationSurvey.ts
Normal file
14
src/migration/1737442569342-updateRelationSurvey.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateRelationSurvey1737442569342 implements MigrationInterface {
|
||||
name = 'UpdateRelationSurvey1737442569342'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX \`IDX_5c42dcafb9ff2c3785b9bf447a\` ON \`personal\``);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE UNIQUE INDEX \`IDX_5c42dcafb9ff2c3785b9bf447a\` ON \`personal\` (\`appointId\`)`);
|
||||
}
|
||||
|
||||
}
|
||||
16
src/migration/1737443725676-updateRelationSurvey.ts
Normal file
16
src/migration/1737443725676-updateRelationSurvey.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateRelationSurvey1737443725676 implements MigrationInterface {
|
||||
name = 'UpdateRelationSurvey1737443725676'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` ADD CONSTRAINT \`FK_53ffbd1e99fe0da682dab5c77ff\` FOREIGN KEY (\`personal_id\`, \`personal_id\`) REFERENCES \`survey\`(\`personal_id\`,\`assign_id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`survey\` ADD CONSTRAINT \`FK_9bae89d4bb00502e057fb619a70\` FOREIGN KEY (\`personal_id\`) REFERENCES \`personal\`(\`personal_id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`survey\` DROP FOREIGN KEY \`FK_9bae89d4bb00502e057fb619a70\``);
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` DROP FOREIGN KEY \`FK_53ffbd1e99fe0da682dab5c77ff\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue