เพิ่มselect detail tree
This commit is contained in:
parent
35ba5b91f3
commit
cd21c42710
7 changed files with 175 additions and 147 deletions
|
|
@ -595,6 +595,7 @@ export class OrganizationController extends Controller {
|
|||
orgTreePhoneIn: orgChild2.orgChild2PhoneIn,
|
||||
orgTreeFax: orgChild2.orgChild2Fax,
|
||||
orgRevisionId: orgRoot.orgRevisionId,
|
||||
orgRootName: orgRoot.orgRootName,
|
||||
children: orgChild3Data
|
||||
.filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id)
|
||||
.map((orgChild3) => ({
|
||||
|
|
@ -802,119 +803,119 @@ export class OrganizationController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Post("sort")
|
||||
async Sort(
|
||||
@Body() requestBody: {
|
||||
id: string, type: number, sortId: string[]
|
||||
}
|
||||
){
|
||||
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);
|
||||
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){
|
||||
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
|
||||
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);
|
||||
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){
|
||||
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
|
||||
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);
|
||||
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){
|
||||
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
|
||||
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);
|
||||
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){
|
||||
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
|
||||
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);
|
||||
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){
|
||||
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
|
||||
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);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: " + requestBody.type);
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
catch(error){
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue