From 5b218662654eec8b7c68b9f2eb61546935bcf451 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 12 Jun 2024 14:55:20 +0700 Subject: [PATCH 1/2] fix created --- src/controllers/AuthRoleController.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index e747ec9f..fd8ad2c2 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -123,9 +123,24 @@ export class AuthRoleController extends Controller { return attr; }); + const newAttrs = body.authRoleAttrs + .filter((a) => !roleAttrData.some((attr) => attr.authSysId === a.authSysId)) + .map((attr) => { + const newAttr = new AuthRoleAttr(); + Object.assign(newAttr, attr, { + authRoleId: roleId, + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, + }); + return newAttr; + }); + await Promise.all([ this.authRoleRepo.save(record), ...updatedRoleAttrData.map((attr) => this.authRoleAttrRepo.save(attr)), + ...newAttrs.map((attr) => this.authRoleAttrRepo.save(attr)), ]); return new HttpSuccess(); From a4b29e0a1bdd29eb71c00ead583a4ca01b7b0b25 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 12 Jun 2024 15:10:36 +0700 Subject: [PATCH 2/2] fix --- src/controllers/AuthRoleController.ts | 59 ++++++++++++++++++--------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index fd8ad2c2..94c7012c 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -115,31 +115,50 @@ export class AuthRoleController extends Controller { where: { authRoleId: roleId }, }); - const updatedRoleAttrData = roleAttrData.map((attr) => { - const updatedAttr = body.authRoleAttrs.find((a) => a.authSysId === attr.authSysId); - if (updatedAttr) { - return Object.assign(attr, updatedAttr, { lastUpdateFullName: req.user.name }); - } - return attr; - }); + // const updatedRoleAttrData = roleAttrData.map((attr) => { + // const updatedAttr = body.authRoleAttrs.find((a) => a.authSysId === attr.authSysId); + // if (updatedAttr) { + // return Object.assign(attr, updatedAttr, { lastUpdateFullName: req.user.name }); + // } + // return attr; + // }); - const newAttrs = body.authRoleAttrs - .filter((a) => !roleAttrData.some((attr) => attr.authSysId === a.authSysId)) - .map((attr) => { - const newAttr = new AuthRoleAttr(); - Object.assign(newAttr, attr, { - authRoleId: roleId, - createdUserId: req.user.sub, - createdFullName: req.user.name, - lastUpdateUserId: req.user.sub, - lastUpdateFullName: req.user.name, - }); - return newAttr; + // const newAttrs = body.authRoleAttrs + // .filter((a) => !roleAttrData.some((attr) => attr.authSysId === a.authSysId)) + // .map((attr) => { + // const newAttr = new AuthRoleAttr(); + // Object.assign(newAttr, attr, { + // authRoleId: roleId, + // createdUserId: req.user.sub, + // createdFullName: req.user.name, + // lastUpdateUserId: req.user.sub, + // lastUpdateFullName: req.user.name, + // }); + // return newAttr; + // }); + + // await Promise.all([ + // this.authRoleRepo.save(record), + // ...updatedRoleAttrData.map((attr) => this.authRoleAttrRepo.save(attr)), + // ...newAttrs.map((attr) => this.authRoleAttrRepo.save(attr)), + // ]); + + await this.authRoleAttrRepo.remove(roleAttrData); + + const newAttrs = body.authRoleAttrs.map((attr) => { + const newAttr = new AuthRoleAttr(); + Object.assign(newAttr, attr, { + authRoleId: roleId, + createdUserId: req.user.sub, + createdFullName: req.user.name, + lastUpdateUserId: req.user.sub, + lastUpdateFullName: req.user.name, }); + return newAttr; + }); await Promise.all([ this.authRoleRepo.save(record), - ...updatedRoleAttrData.map((attr) => this.authRoleAttrRepo.save(attr)), ...newAttrs.map((attr) => this.authRoleAttrRepo.save(attr)), ]);