update province

This commit is contained in:
kittapath 2025-01-17 17:52:13 +07:00
parent 668b05a511
commit 19598f1f81
9 changed files with 64 additions and 67 deletions

View file

@ -32,7 +32,6 @@ import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople";
import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople";
import { ActualGoal, CreateActualGoal } from "../entities/ActualGoal";
import { CreatePlannedGoal, PlannedGoal } from "../entities/PlannedGoal";
import { Province } from "../entities/Province";
import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import { PlannedGoalPosition } from "../entities/PlannedGoalPosition";
@ -83,7 +82,6 @@ export class DevelopmentController extends Controller {
private actualGoalRepository = AppDataSource.getRepository(ActualGoal);
private plannedGoalRepository = AppDataSource.getRepository(PlannedGoal);
private plannedGoalPositionRepository = AppDataSource.getRepository(PlannedGoalPosition);
private provinceRepository = AppDataSource.getRepository(Province);
private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
private strategyChild1Repository = AppDataSource.getRepository(StrategyChild1);
@ -1224,19 +1222,14 @@ export class DevelopmentController extends Controller {
// const before = structuredClone(development);
await Promise.all(
requestBody.developmentAddresss.map(async (x) => {
let _null: any = null;
const data = Object.assign(new DevelopmentAddress(), x);
if (x.provinceId != null) {
const chkProvince = await this.provinceRepository.findOne({
where: {
id: x.provinceId,
},
});
if (chkProvince == null) {
data.provinceId = _null;
}
}
if (x.address) {
await new CallAPI()
.GetData(request, `/org/metadata/province/${x.provinceId}`)
.then(async (item) => {
data.provinceName = item.name;
})
.catch(async (x) => {});
data.developmentId = development.id;
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
@ -1433,16 +1426,14 @@ export class DevelopmentController extends Controller {
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
if (requestBody.provinceActualId != null) {
const checkId = await this.provinceRepository.findOne({
where: { id: requestBody.provinceActualId },
});
if (!checkId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ");
}
}
const before = structuredClone(development);
const data = Object.assign(new DevelopmentOther(), requestBody);
await new CallAPI()
.GetData(request, `/org/metadata/province/${requestBody.provinceActualId}`)
.then(async (item) => {
data.provinceActualName = item.name;
})
.catch(async (x) => {});
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
@ -1496,6 +1487,12 @@ export class DevelopmentController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
}
Object.assign(development, requestBody);
await new CallAPI()
.GetData(request, `/org/metadata/province/${requestBody.provinceActualId}`)
.then(async (item) => {
development.provinceActualName = item.name;
})
.catch(async (x) => {});
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();

View file

@ -360,18 +360,17 @@ export class DevelopmentEmployeeHistoryController extends Controller {
relations: [
"development",
"development.developmentOthers",
"development.developmentOthers.province",
"employeePosLevel",
"employeePosType",
],
where: { id: id, type: type },
order: {
development:{
development: {
developmentOthers: {
createdAt: "ASC"
}
}
}
createdAt: "ASC",
},
},
},
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประวัติการฝึกอบรม/ดูงานนี้");
@ -416,7 +415,7 @@ export class DevelopmentEmployeeHistoryController extends Controller {
? getDevelopment.development.developmentOthers.map((dev) => ({
topicAcademic: dev.topicAcademic,
addressAcademic: dev.addressAcademic,
province: dev.province.name
province: dev.provinceActualName,
}))
: [],
};

View file

@ -27,7 +27,6 @@ import { PosLevel } from "../entities/PosLevel";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
import permission from "../interfaces/permission";
import { Province } from "../entities/Province";
@Route("api/v1/development/history/officer")
@Tags("DevelopmentOfficerHistory")
@ -352,13 +351,7 @@ export class DevelopmentOfficerHistoryController extends Controller {
await new permission().PermissionGet(request, "SYS_DEV_HISTORY_OFFICER");
const type = "OFFICER";
const getDevelopment = await this.developmentHistoryRepository.findOne({
relations: [
"development",
"development.developmentOthers",
"development.developmentOthers.province",
"posLevel",
"posType",
],
relations: ["development", "development.developmentOthers", "posLevel", "posType"],
where: { id: id, type: type },
order: {
development: {
@ -408,7 +401,7 @@ export class DevelopmentOfficerHistoryController extends Controller {
? getDevelopment.development.developmentOthers.map((dev) => ({
topicAcademic: dev.topicAcademic,
addressAcademic: dev.addressAcademic,
province: dev.province.name,
province: dev.provinceActualName,
}))
: [],
};

View file

@ -1,6 +1,5 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToMany, Double } from "typeorm";
import { EntityBase } from "./base/Base";
import { Province } from "./Province";
import { ActualPeople, CreateActualPeople } from "./ActualPeople";
import { CreatePlannedPeople, PlannedPeople } from "./PlannedPeople";
import { ActualGoal, CreateActualGoal } from "./ActualGoal";
@ -566,10 +565,6 @@ export class Development extends EntityBase {
})
provinceActualId: string;
@ManyToOne(() => Province, (province: Province) => province.developmentActuals)
@JoinColumn({ name: "provinceActualId" })
provinceActual: Province;
@Column({
nullable: true,
type: "datetime",

View file

@ -1,7 +1,6 @@
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { Development } from "./Development";
import { Province } from "./Province";
@Entity("developmentAddress")
export class DevelopmentAddress extends EntityBase {
@ -19,9 +18,12 @@ export class DevelopmentAddress extends EntityBase {
})
provinceId: string;
@ManyToOne(() => Province, (province: Province) => province.developmentAddresss)
@JoinColumn({ name: "provinceId" })
province: Province;
@Column({
nullable: true,
comment: "โครงการ/หลักสูตรการฝึกอบรม",
default: null,
})
provinceName: string;
@Column({
nullable: true,

View file

@ -1,7 +1,6 @@
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { Development } from "./Development";
import { Province } from "./Province";
@Entity("developmentOther")
export class DevelopmentOther extends EntityBase {
@ -26,6 +25,13 @@ export class DevelopmentOther extends EntityBase {
})
provinceActualId: string;
@Column({
nullable: true,
comment: "จังหวัด(ข้อมูลวิชาการ)",
default: null,
})
provinceActualName: string;
@Column({
nullable: true,
comment: "คีย์นอก(FK)ของตาราง development",
@ -36,10 +42,6 @@ export class DevelopmentOther extends EntityBase {
@ManyToOne(() => Development, (development: Development) => development.developmentOthers)
@JoinColumn({ name: "developmentId" })
development: Development;
@ManyToOne(() => Province, (province: Province) => province.developmentOthers)
@JoinColumn({ name: "provinceActualId" })
province: Province;
}
export class UpdateDevelopmentOther {

View file

@ -1,7 +1,6 @@
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base";
import { Development } from "./Development";
import { Province } from "./Province";
@Entity("developmentRisk")
export class DevelopmentRisk extends EntityBase {
@ -47,9 +46,9 @@ export class DevelopmentRisk extends EntityBase {
})
developmentId: string;
@ManyToOne(() => Development, (development: Development) => development.developmentRisks)
@JoinColumn({ name: "developmentId" })
development: Development;
@ManyToOne(() => Development, (development: Development) => development.developmentRisks)
@JoinColumn({ name: "developmentId" })
development: Development;
}
export class UpdateDevelopmentRisk {

View file

@ -13,18 +13,6 @@ export class Province extends EntityBase {
default: null,
})
name: string;
@OneToMany(
() => DevelopmentAddress,
(developmentAddress: DevelopmentAddress) => developmentAddress.province,
)
developmentAddresss: DevelopmentAddress[];
@OneToMany(() => Development, (development: Development) => development.provinceActual)
developmentActuals: Development[];
@OneToMany(() => DevelopmentOther, (developmentOther: DevelopmentOther) => developmentOther.province)
developmentOthers: Development[];
}
export class CreateProvince {

View file

@ -0,0 +1,22 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateDeleteDevProvincename1737111015155 implements MigrationInterface {
name = 'UpdateDeleteDevProvincename1737111015155'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP FOREIGN KEY \`FK_e2721b3f440256b56ce83a04fb2\``);
await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_47bbbecaea9b7b31d2536054656\``);
await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_bdafbb824b88c3bdb73adf7f220\``);
await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD \`provinceName\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม'`);
await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD \`provinceActualName\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP COLUMN \`provinceActualName\``);
await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP COLUMN \`provinceName\``);
await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_bdafbb824b88c3bdb73adf7f220\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_47bbbecaea9b7b31d2536054656\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD CONSTRAINT \`FK_e2721b3f440256b56ce83a04fb2\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
}