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 { ReturnHelper } from "../helpers/express/return";
|
||||||
import { OrmHelper } from "../helpers/orm";
|
import { OrmHelper } from "../helpers/orm";
|
||||||
import Joi from "joi";
|
import Joi from "joi";
|
||||||
import { ILogObj, Logger } from "tslog";
|
import { ILogObj, Logger } from "tslog";
|
||||||
import { Language } from "../langs/lang";
|
import { Language } from "../langs/lang";
|
||||||
import { Paging, User, UserRole } from "entity";
|
import { Application, Paging, User, UserRole } from "entity";
|
||||||
import CommonHelper from "../helpers/common";
|
import CommonHelper from "../helpers/common";
|
||||||
import { Status } from "entity";
|
import { Status } from "entity";
|
||||||
import { RoleList } from "entity";
|
import { RoleList } from "entity";
|
||||||
@ -257,14 +257,18 @@ export class UserRoleController {
|
|||||||
name: Joi.string().max(64).required().label('Name'),
|
name: Joi.string().max(64).required().label('Name'),
|
||||||
roles: Joi.array().required().label('Roles'),
|
roles: Joi.array().required().label('Roles'),
|
||||||
status: Joi.string().allow(...Object.values(Status)).required().label('Status'),
|
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()
|
const data = new UserRole()
|
||||||
data.name = param.name
|
data.name = param.name
|
||||||
data.roles = param.roles
|
data.roles = param.roles
|
||||||
data.status = param.status
|
data.status = param.status
|
||||||
|
data.application = await repo_app.findOneBy({ id: param.application });
|
||||||
|
|
||||||
await OrmHelper.DB.manager.save(data);
|
await OrmHelper.DB.manager.save(data);
|
||||||
|
|
||||||
@ -309,20 +313,24 @@ export class UserRoleController {
|
|||||||
name: Joi.string().max(64).required().label('Name'),
|
name: Joi.string().max(64).required().label('Name'),
|
||||||
roles: Joi.array().required().label('Roles'),
|
roles: Joi.array().required().label('Roles'),
|
||||||
status: Joi.string().allow(...Object.values(Status)).required().label('Status'),
|
status: Joi.string().allow(...Object.values(Status)).required().label('Status'),
|
||||||
|
application: Joi.string().required().label('Application'),
|
||||||
});
|
});
|
||||||
|
|
||||||
req.body.id = req.params['id'];
|
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 repo = OrmHelper.DB.getRepository(UserRole);
|
||||||
|
|
||||||
const data = await repo.findOneBy({ id: param.id });
|
const data = await repo.findOneBy({ id: param.id });
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
const repo_app = OrmHelper.DB.getRepository(Application);
|
||||||
|
|
||||||
data.name = param.name
|
data.name = param.name
|
||||||
data.roles = param.roles
|
data.roles = param.roles
|
||||||
data.status = param.status
|
data.status = param.status
|
||||||
|
data.application = await repo_app.findOneBy({ id: param.application });
|
||||||
|
|
||||||
await repo.save(data);
|
await repo.save(data);
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,8 @@ const doc = {
|
|||||||
user_role: {
|
user_role: {
|
||||||
$name: "Administrator",
|
$name: "Administrator",
|
||||||
$roles: ["4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8", "1a1221b6-78a0-4b3b-bf5c-fa0af5f69be8"],
|
$roles: ["4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8", "1a1221b6-78a0-4b3b-bf5c-fa0af5f69be8"],
|
||||||
$status: "Y"
|
$status: "Y",
|
||||||
|
$application: "ukln"
|
||||||
},
|
},
|
||||||
user_activity: {
|
user_activity: {
|
||||||
$id_user: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
|
$id_user: "4a6991b6-78a0-4b3b-bf5c-fa0af5f69be8",
|
||||||
|
|||||||
Reference in New Issue
Block a user