update auth menu role

This commit is contained in:
2024-12-01 00:03:23 +07:00
parent 44612b0050
commit 1e60f97208
2 changed files with 55 additions and 34 deletions

View File

@ -120,41 +120,44 @@ export class AuthController {
.andWhere('id_parent is null') .andWhere('id_parent is null')
.orderBy('order', 'ASC'); .orderBy('order', 'ASC');
const res_list_all = await repoMenu.createQueryBuilder().andWhere('id_parent is not null').getMany();
let list_data_final = await res_list.getMany(); let list_data_final = await res_list.getMany();
let list_child: any = {}; if (list_data_final.length > 0) {
for (let p of res_list_all) { const res_list_all = await repoMenu.createQueryBuilder().andWhere('id_parent is not null').getMany();
if (!list_child[p.id_parent]) {
list_child[p.id_parent] = []; let list_child: any = {};
for (let p of res_list_all) {
if (!list_child[p.id_parent]) {
list_child[p.id_parent] = [];
}
list_child[p.id_parent].push(p);
} }
list_child[p.id_parent].push(p); for (let f of list_data_final) {
} if (list_child[f.id]) {
f.children = list_child[f.id];
for (let f of list_data_final) { for (let g of f.children) {
if (list_child[f.id]) { if (list_child[g.id]) {
f.children = list_child[f.id]; g.children = list_child[g.id];
for (let g of f.children) { for (let h of g.children) {
if (list_child[g.id]) { if (list_child[h.id]) {
g.children = list_child[g.id]; h.children = list_child[h.id];
for (let h of g.children) { for (let i of h.children) {
if (list_child[h.id]) { if (list_child[i.id]) {
h.children = list_child[h.id]; i.children = list_child[i.id];
for (let i of h.children) { for (let j of i.children) {
if (list_child[i.id]) { if (list_child[j.id]) {
i.children = list_child[i.id]; j.children = list_child[j.id];
for (let j of i.children) { for (let k of j.children) {
if (list_child[j.id]) { if (list_child[k.id]) {
j.children = list_child[j.id]; k.children = list_child[k.id];
}
for (let k of j.children) {
if (list_child[k.id]) {
k.children = list_child[k.id];
} }
} }
} }
@ -166,9 +169,12 @@ export class AuthController {
} }
} }
} }
return list_data_final;
} }
return list_data_final; return {};
} }
static async logout(req: Request, res: Response, next: NextFunction): Promise<Response> { static async logout(req: Request, res: Response, next: NextFunction): Promise<Response> {

View File

@ -57,7 +57,7 @@ export class UserController {
try { try {
const schema = Joi.object().keys({ const schema = Joi.object().keys({
filter: Joi.string().allow('').optional().label('Filter'), filter: Joi.array().allow('').optional().label('Filter'),
page: Joi.number().required().min(1).label('Page'), page: Joi.number().required().min(1).label('Page'),
limit: Joi.number().required().min(1).label('Limit'), limit: Joi.number().required().min(1).label('Limit'),
with_deleted: Joi.bool().required().label('With Deleted'), with_deleted: Joi.bool().required().label('With Deleted'),
@ -72,13 +72,28 @@ export class UserController {
const offset = (param.page - 1) * param.limit const offset = (param.page - 1) * param.limit
let whereAttr = ''; let whereAttr = [];
let whereVal: any = {}; let whereVal: any = {};
if (param.filter) { if (param.filter && param.filter.length > 0) {
whereAttr = 'name like :filter_like or username like :filter_like or email = :filter '; let filter_any = false;
whereVal['filter'] = param.filter
whereVal['filter_like'] = '%' + param.filter + '%' for (let p in param.filter) {
if (p != 'any') {
let f = param.filter[p];
whereAttr.push(p + " = :" + p);
whereVal[p] = f;
} else {
filter_any = true;
}
}
if (filter_any) {
whereAttr.push('name like :filter_like or username like :filter_like or email = :filter ');
whereVal['filter'] = param.filter
whereVal['filter_like'] = '%' + param.filter + '%'
}
} }
const res_count = userRepository.createQueryBuilder() const res_count = userRepository.createQueryBuilder()
@ -140,7 +155,7 @@ export class UserController {
try { try {
const schema = Joi.object().keys({ const schema = Joi.object().keys({
filter: Joi.string().allow('').optional().label('Filter'), filter: Joi.array().allow('').optional().label('Filter'),
order_field: Joi.string().required().label('Order Field'), order_field: Joi.string().required().label('Order Field'),
order_direction: Joi.string().allow('asc', 'desc').required().label('Order Direction'), order_direction: Joi.string().allow('asc', 'desc').required().label('Order Direction'),
token: Joi.string().required().label('Token'), token: Joi.string().required().label('Token'),