Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-01-31 17:23:24 +07:00
commit 923d75ebe3
4 changed files with 191 additions and 23 deletions

View file

@ -688,12 +688,18 @@ export class OrganizationController extends Controller {
* @summary ORG_039 - (ADMIN) #42
*
*/
@Get("/history/publish")
async GetHistoryPublish(@Query("id") id: string, @Query("type") type: number = 1) {
const _data = new Array();
if (type == 1) {
@Post("/history/publish")
async GetHistoryPublish(
@Body()
requestBody: {
id: string;
type: number;
},
@Request() request: { user: Record<string, any> },
) {
if (requestBody.type == 1) {
const orgChild1 = await this.child1Repository.findOne({
where: { id: id },
where: { id: requestBody.id },
});
if (!orgChild1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child1");
@ -710,9 +716,9 @@ export class OrganizationController extends Controller {
lastUpdatedAt: item.lastUpdatedAt,
}));
return new HttpSuccess(_data);
} else if (type == 2) {
} else if (requestBody.type == 2) {
const orgChild2 = await this.child2Repository.findOne({
where: { id: id },
where: { id: requestBody.id },
});
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child2");
@ -729,9 +735,9 @@ export class OrganizationController extends Controller {
lastUpdatedAt: item.lastUpdatedAt,
}));
return new HttpSuccess(_data);
} else if (type == 3) {
} else if (requestBody.type == 3) {
const orgChild3 = await this.child3Repository.findOne({
where: { id: id },
where: { id: requestBody.id },
});
if (!orgChild3) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child3");
@ -748,9 +754,9 @@ export class OrganizationController extends Controller {
lastUpdatedAt: item.lastUpdatedAt,
}));
return new HttpSuccess(_data);
} else if (type == 4) {
} else if (requestBody.type == 4) {
const orgChild4 = await this.child4Repository.findOne({
where: { id: id },
where: { id: requestBody.id },
});
if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child4");
@ -769,7 +775,7 @@ export class OrganizationController extends Controller {
return new HttpSuccess(_data);
} else {
const orgRoot = await this.orgRootRepository.findOne({
where: { id: id },
where: { id: requestBody.id },
});
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root");
@ -788,4 +794,128 @@ export class OrganizationController extends Controller {
return new HttpSuccess(_data);
}
}
/**
* API
*
* @summary ORG_038 - (ADMIN) #41
*
*/
@Post("sort")
async Sort(
@Body() requestBody: {
id: string, type: number, sortId: string[]
}
){
try {
switch(requestBody.type){
case 0 :{
const revisionId = await this.orgRevisionRepository.findOne({ where: {id : requestBody.id} })
if(!revisionId?.id){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found revisionId: "+ requestBody.id);
}
const listRootId = await this.orgRootRepository.find({
where: { orgRevisionId: requestBody.id},
select: ["id", "orgRootOrder"],
})
if(!listRootId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId.");
}
const sortData = listRootId.map((data) => ({
id : data.id,
orgRootOrder: requestBody.sortId.indexOf(data.id) + 1
}));
await this.orgRootRepository.save(sortData);
break;
}
case 1 :{
const rootId = await this.orgRootRepository.findOne({ where: {id : requestBody.id} })
if(!rootId?.id){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId: "+ requestBody.id);
}
const listChild1Id = await this.child1Repository.find({
where: { orgRootId: requestBody.id},
select: ["id", "orgChild1Order"],
})
if(!listChild1Id){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id.");
}
const sortData = listChild1Id.map((data) => ({
id : data.id,
orgChild1Order: requestBody.sortId.indexOf(data.id) + 1
}));
await this.child1Repository.save(sortData);
break;
}
case 2 :{
const child1Id = await this.child1Repository.findOne({ where: {id : requestBody.id} })
if(!child1Id?.id){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id: "+ requestBody.id);
}
const listChild2Id = await this.child2Repository.find({
where: { orgChild1Id: requestBody.id},
select: ["id", "orgChild2Order"],
})
if(!listChild2Id){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id.");
}
const sortData = listChild2Id.map((data) => ({
id : data.id,
orgChild2Order: requestBody.sortId.indexOf(data.id) + 1
}));
await this.child2Repository.save(sortData);
break;
}
case 3 :{
const child2Id = await this.child2Repository.findOne({ where: {id : requestBody.id} })
if(!child2Id?.id){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id: "+ requestBody.id);
}
const listChild3Id = await this.child3Repository.find({
where: { orgChild2Id: requestBody.id},
select: ["id", "orgChild3Order"],
})
if(!listChild3Id){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id.");
}
const sortData = listChild3Id.map((data) => ({
id : data.id,
orgChild3Order: requestBody.sortId.indexOf(data.id) + 1
}));
await this.child3Repository.save(sortData);
break;
}
case 4 :{
const child3Id = await this.child3Repository.findOne({ where: {id : requestBody.id} })
if(!child3Id?.id){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id: "+ requestBody.id);
}
const listChild4Id = await this.child4Repository.find({
where: { orgChild3Id: requestBody.id},
select: ["id", "orgChild4Order"],
})
if(!listChild4Id){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4Id.");
}
const sortData = listChild4Id.map((data) => ({
id : data.id,
orgChild4Order: requestBody.sortId.indexOf(data.id) + 1
}));
await this.child4Repository.save(sortData);
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: "+ requestBody.type);
}
return new HttpSuccess();
}
catch(error){
return error;
}
}
}

View file

@ -505,7 +505,7 @@ export class PositionController extends Controller {
@Put("master/{id}")
@Example({
posMasterNoPrefix: "กบ.",
posMasterNo: 1,
posMasterNo: "1",
posMasterNoSuffix: "ช",
posId: ["08db9e81-fc46-4e95-8b33-be4ca0016abf", "08db9e81-fc46-4e95-8b33-be4ca0016abf"],
orgRootId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",

View file

@ -79,37 +79,37 @@ export class PosMaster extends EntityBase {
@Column({
nullable: true,
length: 40,
default: "00000000-0000-0000-0000-000000000000",
default: null,
})
orgRootId: string;
orgRootId?: string;
@Column({
nullable: true,
length: 40,
default: "00000000-0000-0000-0000-000000000000",
default: null,
})
orgChild1Id: string;
orgChild1Id?: string;
@Column({
nullable: true,
length: 40,
default: "00000000-0000-0000-0000-000000000000",
default: null,
})
orgChild2Id: string;
orgChild2Id?: string;
@Column({
nullable: true,
length: 40,
default: "00000000-0000-0000-0000-000000000000",
default: null,
})
orgChild3Id: string;
orgChild3Id?: string;
@Column({
nullable: true,
length: 40,
default: "00000000-0000-0000-0000-000000000000",
default: null,
})
orgChild4Id: string;
orgChild4Id?: string;
@Column({
nullable: true,

View file

@ -0,0 +1,38 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTablePosMaster21706696231054 implements MigrationInterface {
name = 'AddTablePosMaster21706696231054'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild2\` varchar(36) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild3OrgChild3Id\` varchar(36) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild4\` varchar(36) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgRootId\` \`orgRootId\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild1Id\` \`orgChild1Id\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild2Id\` \`orgChild2Id\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild3Id\` \`orgChild3Id\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild4Id\` \`orgChild4Id\` varchar(40) NULL`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_7da46fc341b77ebd43f28a8cf47\` FOREIGN KEY (\`orgRootId\`) REFERENCES \`orgRoot\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_7e3ee4640d067c5563c060e2c6b\` FOREIGN KEY (\`orgChild1Id\`) REFERENCES \`orgChild1\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_685b7779aa6d8897d5f3c899bf2\` FOREIGN KEY (\`orgChild2\`) REFERENCES \`orgChild2\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_838fef6a73e9cc70147b8f85bf7\` FOREIGN KEY (\`orgChild3OrgChild3Id\`) REFERENCES \`orgChild3\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_0564eef8bec8347d6b782a67537\` FOREIGN KEY (\`orgChild4\`) REFERENCES \`orgChild4\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_0564eef8bec8347d6b782a67537\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_838fef6a73e9cc70147b8f85bf7\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_685b7779aa6d8897d5f3c899bf2\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_7e3ee4640d067c5563c060e2c6b\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_7da46fc341b77ebd43f28a8cf47\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild4Id\` \`orgChild4Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild3Id\` \`orgChild3Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild2Id\` \`orgChild2Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild1Id\` \`orgChild1Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgRootId\` \`orgRootId\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild4\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild3OrgChild3Id\``);
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild2\``);
}
}