forked from geolba/tethys.backend
- update to AdonisJS 6
This commit is contained in:
parent
f828ca4491
commit
cb51a4136f
167 changed files with 21485 additions and 21212 deletions
|
@ -1,23 +1,25 @@
|
|||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
||||
import Database from '@ioc:Adonis/Lucid/Database';
|
||||
import Config from '@ioc:Adonis/Core/Config';
|
||||
import User from 'app/Models/User';
|
||||
import { Exception } from '@adonisjs/core/build/standalone';
|
||||
import type { HttpContext } from '@adonisjs/core/http';
|
||||
import db from '@adonisjs/lucid/services/db';
|
||||
import config from '@adonisjs/core/services/config';
|
||||
import User from '#app/Models/User';
|
||||
import { Exception } from '@adonisjs/core/exceptions';
|
||||
|
||||
const roleTable = Config.get('rolePermission.role_table', 'roles');
|
||||
const userRoleTable = Config.get('rolePermission.user_role_table', 'link_accounts_roles');
|
||||
// const roleTable = Config.get('rolePermission.role_table', 'roles');
|
||||
const roleTable = config.get('rolePermission.role_table', 'roles');
|
||||
// const userRoleTable = Config.get('rolePermission.user_role_table', 'link_accounts_roles');
|
||||
const userRoleTable = config.get('rolePermission.user_role_table', 'user_roles');
|
||||
|
||||
// node ace make:middleware role
|
||||
export default class Role {
|
||||
// .middleware(['auth', 'role:admin,moderator'])
|
||||
public async handle({ auth, response }: HttpContextContract, next: () => Promise<void>, userRoles: string[]) {
|
||||
public async handle({ auth, response }: HttpContext, next: () => Promise<void>, userRoles: string[]) {
|
||||
// Check if user is logged-in or not.
|
||||
// let expression = "";
|
||||
// if (Array.isArray(args)) {
|
||||
// expression = args.join(" || ");
|
||||
// }
|
||||
|
||||
let user = await auth.user;
|
||||
let user = auth.user as User;
|
||||
if (!user) {
|
||||
return response.unauthorized({ error: 'Must be logged in' });
|
||||
}
|
||||
|
@ -28,7 +30,7 @@ export default class Role {
|
|||
// error: `Doesn't have required role(s): ${userRoles.join(',')}`,
|
||||
// // error: `Doesn't have required role(s)`,
|
||||
// });
|
||||
throw new Exception(`Doesn't have required role(s): ${userRoles.join(',')}`, 401);
|
||||
throw new Exception(`Doesn't have required role(s): ${userRoles.join(',')}`, { status: 401 });
|
||||
}
|
||||
|
||||
// code for middleware goes here. ABOVE THE NEXT CALL
|
||||
|
@ -62,7 +64,7 @@ export default class Role {
|
|||
rows: {
|
||||
0: { rolecount },
|
||||
},
|
||||
} = await Database.rawQuery(
|
||||
} = await db.rawQuery(
|
||||
'SELECT count("r"."id") as roleCount FROM ' +
|
||||
roleTable +
|
||||
' r INNER JOIN ' +
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue