Merge branch 'develop' into adiDev
This commit is contained in:
commit
42bd8cd77b
2 changed files with 57 additions and 21 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1";
|
import { OrgChild1, CreateOrgChild1, UpdateOrgChild1 } from "../entities/OrgChild1";
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Delete,
|
Delete,
|
||||||
|
|
@ -29,10 +29,11 @@ import HttpError from "../interfaces/http-error";
|
||||||
|
|
||||||
export class OrgChild1Controller {
|
export class OrgChild1Controller {
|
||||||
private child1Repository = AppDataSource.getRepository(OrgChild1)
|
private child1Repository = AppDataSource.getRepository(OrgChild1)
|
||||||
/**
|
|
||||||
|
/**
|
||||||
* API สร้างโครงสร้างระดับ1
|
* API สร้างโครงสร้างระดับ1
|
||||||
*
|
*
|
||||||
* @summary ORG_004 - สร้างโครงสร้างระดับ1 (ADMIN)
|
* @summary ORG_004 - สร้างโครงสร้างระดับ1 (ADMIN) #4
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post()
|
@Post()
|
||||||
|
|
@ -40,24 +41,60 @@ export class OrgChild1Controller {
|
||||||
@Body() requestBody: CreateOrgChild1,
|
@Body() requestBody: CreateOrgChild1,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
){
|
){
|
||||||
const chkOrder = await this.child1Repository.findOne({ where: { orgRootId:requestBody.orgRootId, orgChild1Order:requestBody.orgChild1Order }});
|
try {
|
||||||
if (chkOrder != null) {
|
const chkOrder = await this.child1Repository.findOne({ where: { orgRootId:requestBody.orgRootId, orgChild1Order:requestBody.orgChild1Order }});
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
if (chkOrder != null) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
const chkCode = await this.child1Repository.findOne({ where: { orgRootId:requestBody.orgRootId, orgChild1Code:requestBody.orgChild1Code }});
|
||||||
|
if (chkCode != null) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
|
||||||
|
child1.orgChild1Name = requestBody.orgChild1Name
|
||||||
|
child1.createdUserId = request.user.sub
|
||||||
|
child1.createdFullName = request.user.name
|
||||||
|
child1.createdAt = new Date()
|
||||||
|
child1.lastUpdateUserId = request.user.sub
|
||||||
|
child1.lastUpdateFullName= request.user.name
|
||||||
|
child1.lastUpdatedAt = new Date()
|
||||||
|
await this.child1Repository.save(child1);
|
||||||
|
return new HttpSuccess();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
// return new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, String(error))
|
||||||
|
return error
|
||||||
}
|
}
|
||||||
const chkCode = await this.child1Repository.findOne({ where: { orgRootId:requestBody.orgRootId, orgChild1Code:requestBody.orgChild1Code }});
|
}
|
||||||
if (chkCode != null) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
/**
|
||||||
|
* API แก้ไขโครงสร้างระดับ1
|
||||||
|
*
|
||||||
|
* @summary ORG_005 - แก้ไขโครงสร้างระดับ1 (ADMIN) #5
|
||||||
|
*
|
||||||
|
* @param {string} id id สร้างโครงสร้างระดับ1
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
async Edit(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body() requestBody: UpdateOrgChild1,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const child1 = await this.child1Repository.findOne({ where: { id } });
|
||||||
|
if (!child1) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||||
}
|
}
|
||||||
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
|
child1.lastUpdateUserId = request.user.sub;
|
||||||
child1.orgChild1Name = requestBody.orgChild1Name
|
child1.lastUpdateFullName = request.user.name;
|
||||||
child1.createdUserId = request.user.sub
|
child1.lastUpdatedAt = new Date();
|
||||||
child1.createdFullName = request.user.name
|
this.child1Repository.merge(child1, requestBody);
|
||||||
child1.createdAt = new Date()
|
|
||||||
child1.lastUpdateUserId = request.user.sub
|
|
||||||
child1.lastUpdateFullName= request.user.name
|
|
||||||
child1.lastUpdatedAt = new Date()
|
|
||||||
await this.child1Repository.save(child1);
|
await this.child1Repository.save(child1);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany, PrimaryGene
|
||||||
import { EntityBase } from "./base/Base";
|
import { EntityBase } from "./base/Base";
|
||||||
import { OrgRoot } from "./OrgRoot";
|
import { OrgRoot } from "./OrgRoot";
|
||||||
import { OrgChild2 } from "./OrgChild2";
|
import { OrgChild2 } from "./OrgChild2";
|
||||||
import { OrgChild3 } from "./OrgChild3";
|
|
||||||
import { OrgChild4 } from "./OrgChild4";
|
|
||||||
|
|
||||||
enum OrgChild1Rank {
|
enum OrgChild1Rank {
|
||||||
DEPARTMENT = "department",
|
DEPARTMENT = "department",
|
||||||
|
|
@ -11,6 +9,7 @@ enum OrgChild1Rank {
|
||||||
DIVISION = "division",
|
DIVISION = "division",
|
||||||
SECTION = "section",
|
SECTION = "section",
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity("orgChild1")
|
@Entity("orgChild1")
|
||||||
export class OrgChild1 extends EntityBase {
|
export class OrgChild1 extends EntityBase {
|
||||||
|
|
||||||
|
|
@ -124,9 +123,9 @@ export class CreateOrgChild1 {
|
||||||
@Column()
|
@Column()
|
||||||
orgChild1IsNormal: boolean;
|
orgChild1IsNormal: boolean;
|
||||||
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@Column('uuid')
|
||||||
orgRootId: string;
|
orgRootId: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UpdateOrgChild1 = Partial<OrgChild1>;
|
export type UpdateOrgChild1 = Partial<CreateOrgChild1> & { orgChild1Rank?: OrgChild1Rank };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue