From 1d6008a98b202cf9012c569a1b0c4c73d4966d40 Mon Sep 17 00:00:00 2001 From: Abdul Rahman Reza Date: Mon, 6 Jan 2025 12:09:56 +0700 Subject: [PATCH] add application in user roles --- src/controllers/user_roles.ts | 16 ++++++++++++---- src/swagger/builder.js | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/controllers/user_roles.ts b/src/controllers/user_roles.ts index 1126dee..a2a8f44 100644 --- a/src/controllers/user_roles.ts +++ b/src/controllers/user_roles.ts @@ -1,10 +1,10 @@ -import { Request, Response, NextFunction, Application } from "express"; +import { Request, Response, NextFunction } from "express"; import { ReturnHelper } from "../helpers/express/return"; import { OrmHelper } from "../helpers/orm"; import Joi from "joi"; import { ILogObj, Logger } from "tslog"; import { Language } from "../langs/lang"; -import { Paging, User, UserRole } from "entity"; +import { Application, Paging, User, UserRole } from "entity"; import CommonHelper from "../helpers/common"; import { Status } from "entity"; import { RoleList } from "entity"; @@ -257,14 +257,18 @@ export class UserRoleController { name: Joi.string().max(64).required().label('Name'), roles: Joi.array().required().label('Roles'), status: Joi.string().allow(...Object.values(Status)).required().label('Status'), + application: Joi.string().required().label('Application'), }); - const param: UserRole = await schema.validateAsync(req.body); + const param: UserRole & { application: string } = await schema.validateAsync(req.body); + + const repo_app = OrmHelper.DB.getRepository(Application); const data = new UserRole() data.name = param.name data.roles = param.roles data.status = param.status + data.application = await repo_app.findOneBy({ id: param.application }); await OrmHelper.DB.manager.save(data); @@ -309,20 +313,24 @@ export class UserRoleController { name: Joi.string().max(64).required().label('Name'), roles: Joi.array().required().label('Roles'), status: Joi.string().allow(...Object.values(Status)).required().label('Status'), + application: Joi.string().required().label('Application'), }); req.body.id = req.params['id']; - const param: UserRole = await schema.validateAsync(req.body); + const param: UserRole & { application: string } = await schema.validateAsync(req.body); const repo = OrmHelper.DB.getRepository(UserRole); const data = await repo.findOneBy({ id: param.id }); if (data != null) { + const repo_app = OrmHelper.DB.getRepository(Application); + data.name = param.name data.roles = param.roles data.status = param.status + data.application = await repo_app.findOneBy({ id: param.application }); await repo.save(data); diff --git a/src/swagger/builder.js b/src/swagger/builder.js index d15e563..4f7d2b0 100644 --- a/src/swagger/builder.js +++ b/src/swagger/builder.js @@ -46,7 +46,8 @@ const doc = { user_role: { $name: "Administrator", $roles: ["4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8", "1a1221b6-78a0-4b3b-bf5c-fa0af5f69be8"], - $status: "Y" + $status: "Y", + $application: "ukln" }, user_activity: { $id_user: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",