add sort
This commit is contained in:
parent
bd00213596
commit
00f76bbd2b
14 changed files with 187 additions and 166 deletions
|
|
@ -6,6 +6,7 @@ import {
|
|||
Patch,
|
||||
Path,
|
||||
Post,
|
||||
Put,
|
||||
Request,
|
||||
Route,
|
||||
Security,
|
||||
|
|
@ -44,12 +45,12 @@ export class StrategyController extends Controller {
|
|||
"strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s",
|
||||
],
|
||||
order: {
|
||||
createdAt: "ASC",
|
||||
order: "ASC",
|
||||
strategyChild2s: {
|
||||
createdAt: "ASC",
|
||||
order: "ASC",
|
||||
strategyChild3s: {
|
||||
createdAt: "ASC",
|
||||
strategyChild4s: { createdAt: "ASC", strategyChild5s: { createdAt: "ASC" } },
|
||||
order: "ASC",
|
||||
strategyChild4s: { order: "ASC", strategyChild5s: { order: "ASC" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -59,25 +60,30 @@ export class StrategyController extends Controller {
|
|||
id: item.id,
|
||||
level: 1,
|
||||
name: item.strategyChild1Name,
|
||||
order: item.order,
|
||||
children: item.strategyChild2s.map((child2) => ({
|
||||
id: child2.id,
|
||||
level: 2,
|
||||
name: child2.strategyChild2Name,
|
||||
order: child2.order,
|
||||
children: child2.strategyChild3s
|
||||
? child2.strategyChild3s.map((child3) => ({
|
||||
id: child3.id,
|
||||
level: 3,
|
||||
name: child3.strategyChild3Name,
|
||||
order: child3.order,
|
||||
children: child3.strategyChild4s
|
||||
? child3.strategyChild4s.map((child4) => ({
|
||||
id: child4.id,
|
||||
level: 4,
|
||||
name: child4.strategyChild4Name,
|
||||
order: child4.order,
|
||||
children: child4.strategyChild5s
|
||||
? child4.strategyChild5s.map((child5) => ({
|
||||
id: child5.id,
|
||||
level: 5,
|
||||
name: child5.strategyChild5Name,
|
||||
order: child5.order,
|
||||
}))
|
||||
: [],
|
||||
}))
|
||||
|
|
@ -110,12 +116,12 @@ export class StrategyController extends Controller {
|
|||
"strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s",
|
||||
],
|
||||
order: {
|
||||
createdAt: "ASC",
|
||||
order: "ASC",
|
||||
strategyChild2s: {
|
||||
createdAt: "ASC",
|
||||
order: "ASC",
|
||||
strategyChild3s: {
|
||||
createdAt: "ASC",
|
||||
strategyChild4s: { createdAt: "ASC", strategyChild5s: { createdAt: "ASC" } },
|
||||
order: "ASC",
|
||||
strategyChild4s: { order: "ASC", strategyChild5s: { order: "ASC" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -129,25 +135,30 @@ export class StrategyController extends Controller {
|
|||
id: item.id,
|
||||
level: 1,
|
||||
name: item.strategyChild1Name,
|
||||
order: item.order,
|
||||
children: item.strategyChild2s.map((child2) => ({
|
||||
id: child2.id,
|
||||
level: 2,
|
||||
name: child2.strategyChild2Name,
|
||||
order: child2.order,
|
||||
children: child2.strategyChild3s
|
||||
? child2.strategyChild3s.map((child3) => ({
|
||||
id: child3.id,
|
||||
level: 3,
|
||||
name: child3.strategyChild3Name,
|
||||
order: child3.order,
|
||||
children: child3.strategyChild4s
|
||||
? child3.strategyChild4s.map((child4) => ({
|
||||
id: child4.id,
|
||||
level: 4,
|
||||
name: child4.strategyChild4Name,
|
||||
order: child4.order,
|
||||
children: child4.strategyChild5s
|
||||
? child4.strategyChild5s.map((child5) => ({
|
||||
id: child5.id,
|
||||
level: 5,
|
||||
name: child5.strategyChild5Name,
|
||||
order: child5.order,
|
||||
}))
|
||||
: [],
|
||||
}))
|
||||
|
|
@ -170,12 +181,12 @@ export class StrategyController extends Controller {
|
|||
"strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s",
|
||||
],
|
||||
order: {
|
||||
createdAt: "ASC",
|
||||
order: "ASC",
|
||||
strategyChild2s: {
|
||||
createdAt: "ASC",
|
||||
order: "ASC",
|
||||
strategyChild3s: {
|
||||
createdAt: "ASC",
|
||||
strategyChild4s: { createdAt: "ASC", strategyChild5s: { createdAt: "ASC" } },
|
||||
order: "ASC",
|
||||
strategyChild4s: { order: "ASC", strategyChild5s: { order: "ASC" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -189,25 +200,30 @@ export class StrategyController extends Controller {
|
|||
id: item.id,
|
||||
level: 1,
|
||||
name: item.strategyChild1Name,
|
||||
order: item.order,
|
||||
children: item.strategyChild2s.map((child2) => ({
|
||||
id: child2.id,
|
||||
level: 2,
|
||||
name: child2.strategyChild2Name,
|
||||
order: child2.order,
|
||||
children: child2.strategyChild3s
|
||||
? child2.strategyChild3s.map((child3) => ({
|
||||
id: child3.id,
|
||||
level: 3,
|
||||
name: child3.strategyChild3Name,
|
||||
order: child3.order,
|
||||
children: child3.strategyChild4s
|
||||
? child3.strategyChild4s.map((child4) => ({
|
||||
id: child4.id,
|
||||
level: 4,
|
||||
name: child4.strategyChild4Name,
|
||||
order: child4.order,
|
||||
children: child4.strategyChild5s
|
||||
? child4.strategyChild5s.map((child5) => ({
|
||||
id: child5.id,
|
||||
level: 5,
|
||||
name: child5.strategyChild5Name,
|
||||
order: child5.order,
|
||||
}))
|
||||
: [],
|
||||
}))
|
||||
|
|
@ -237,22 +253,30 @@ export class StrategyController extends Controller {
|
|||
|
||||
switch (body.levelnode) {
|
||||
case 0:
|
||||
const ckOrder = await this.strategy1Repo.findOne({
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
strategyRepo = this.strategy1Repo;
|
||||
strategyRepo = this.strategy1Repo;
|
||||
repoSave = this.strategy1Repo;
|
||||
strategyChild = new StrategyChild1();
|
||||
strategyChild.strategyChild1Name = body.name;
|
||||
strategyChild.order = ckOrder ? ckOrder.order + 1 : 1;
|
||||
break;
|
||||
case 1:
|
||||
strategyRepo = this.strategy1Repo;
|
||||
repoSave = this.strategy2Repo;
|
||||
strategyChild = new StrategyChild2();
|
||||
strategyChild.strategyChild2Name = body.name;
|
||||
strategyChild.order = 1;
|
||||
if (body.idnode) {
|
||||
const chk1 = await this.strategy1Repo.findOne({
|
||||
where: { id: body.idnode },
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
if (chk1) {
|
||||
strategyChild.strategyChild1Id = chk1.id;
|
||||
strategyChild.order = chk1 ? chk1.order + 1 : 1;
|
||||
} else {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์");
|
||||
}
|
||||
|
|
@ -263,13 +287,16 @@ export class StrategyController extends Controller {
|
|||
repoSave = this.strategy3Repo;
|
||||
strategyChild = new StrategyChild3();
|
||||
strategyChild.strategyChild3Name = body.name;
|
||||
strategyChild.order = 1;
|
||||
if (body.idnode) {
|
||||
const chk2 = await this.strategy2Repo.findOne({
|
||||
where: { id: body.idnode },
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
if (chk2) {
|
||||
strategyChild.strategyChild1Id = chk2.strategyChild1Id;
|
||||
strategyChild.strategyChild2Id = chk2.id;
|
||||
strategyChild.order = chk2 ? chk2.order + 1 : 1;
|
||||
} else {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์");
|
||||
}
|
||||
|
|
@ -280,14 +307,17 @@ export class StrategyController extends Controller {
|
|||
repoSave = this.strategy4Repo;
|
||||
strategyChild = new StrategyChild4();
|
||||
strategyChild.strategyChild4Name = body.name;
|
||||
strategyChild.order = 1;
|
||||
if (body.idnode) {
|
||||
const chk3 = await this.strategy3Repo.findOne({
|
||||
where: { id: body.idnode },
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
if (chk3) {
|
||||
strategyChild.strategyChild1Id = chk3.strategyChild1Id;
|
||||
strategyChild.strategyChild2Id = chk3.strategyChild2Id;
|
||||
strategyChild.strategyChild3Id = chk3.id;
|
||||
strategyChild.order = chk3 ? chk3.order + 1 : 1;
|
||||
} else {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์");
|
||||
}
|
||||
|
|
@ -298,15 +328,18 @@ export class StrategyController extends Controller {
|
|||
repoSave = this.strategy5Repo;
|
||||
strategyChild = new StrategyChild5();
|
||||
strategyChild.strategyChild5Name = body.name;
|
||||
strategyChild.order = 1;
|
||||
if (body.idnode) {
|
||||
const chk4 = await this.strategy4Repo.findOne({
|
||||
where: { id: body.idnode },
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
if (chk4) {
|
||||
strategyChild.strategyChild1Id = chk4.strategyChild1Id;
|
||||
strategyChild.strategyChild2Id = chk4.strategyChild2Id;
|
||||
strategyChild.strategyChild3Id = chk4.strategyChild3Id;
|
||||
strategyChild.strategyChild4Id = chk4.id;
|
||||
strategyChild.order = chk4 ? chk4.order + 1 : 1;
|
||||
} else {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์");
|
||||
}
|
||||
|
|
@ -621,4 +654,89 @@ export class StrategyController extends Controller {
|
|||
throw new HttpError(HttpStatus.NOT_FOUND, "not found type: " + requestBody.strategy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API เรียงลำดับ
|
||||
*
|
||||
* @summary เรียงลำดับ (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Post("sort")
|
||||
async sortNode(
|
||||
@Body() requestBody: { strategy: number; strategyId: string[]; id: string | null },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
switch (requestBody.strategy) {
|
||||
case 1: {
|
||||
const data = await this.strategy1Repo.find();
|
||||
if (data == null) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy1.");
|
||||
}
|
||||
const sortLevel = data.map((data) => ({
|
||||
...data,
|
||||
level: requestBody.strategyId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.strategy1Repo.save(sortLevel);
|
||||
return new HttpSuccess(sortLevel);
|
||||
}
|
||||
case 2: {
|
||||
const data = await this.strategy2Repo.find({
|
||||
where: { id: requestBody.id ?? "" },
|
||||
});
|
||||
if (data == null) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy2.");
|
||||
}
|
||||
const sortLevel = data.map((data) => ({
|
||||
...data,
|
||||
level: requestBody.strategyId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.strategy2Repo.save(sortLevel);
|
||||
return new HttpSuccess(sortLevel);
|
||||
}
|
||||
case 3: {
|
||||
const data = await this.strategy3Repo.find({
|
||||
where: { id: requestBody.id ?? "" },
|
||||
});
|
||||
if (data == null) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy3.");
|
||||
}
|
||||
const sortLevel = data.map((data) => ({
|
||||
...data,
|
||||
level: requestBody.strategyId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.strategy3Repo.save(sortLevel);
|
||||
return new HttpSuccess(sortLevel);
|
||||
}
|
||||
case 4: {
|
||||
const data = await this.strategy4Repo.find({
|
||||
where: { id: requestBody.id ?? "" },
|
||||
});
|
||||
if (data == null) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy4.");
|
||||
}
|
||||
const sortLevel = data.map((data) => ({
|
||||
...data,
|
||||
level: requestBody.strategyId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.strategy4Repo.save(sortLevel);
|
||||
return new HttpSuccess(sortLevel);
|
||||
}
|
||||
case 5: {
|
||||
const data = await this.strategy5Repo.find({
|
||||
where: { id: requestBody.id ?? "" },
|
||||
});
|
||||
if (data == null) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy5.");
|
||||
}
|
||||
const sortLevel = data.map((data) => ({
|
||||
...data,
|
||||
level: requestBody.strategyId.indexOf(data.id) + 1,
|
||||
}));
|
||||
await this.strategy5Repo.save(sortLevel);
|
||||
return new HttpSuccess(sortLevel);
|
||||
}
|
||||
default:
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found type: " + requestBody.strategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue