add application in user roles
This commit is contained in:
@ -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);
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
Reference in New Issue
Block a user