@foal/typeorm
Version:
FoalTS integration of TypeORM
44 lines (43 loc) • 1.7 kB
TypeScript
import { IUserWithPermissions } from '@foal/core';
import { BaseEntity } from 'typeorm';
import { Group } from './group.entity';
import { Permission } from './permission.entity';
/**
* Abstract class to define a user entity with a system of groups and permissions.
*
* A group can have permissions.
* A user can have permissions and belong to groups that have also permissions.
*
* @export
* @abstract
* @class UserWithPermissions
*/
export declare abstract class UserWithPermissions extends BaseEntity implements IUserWithPermissions {
/**
* Get all users with a given permission.
*
* This method returns all users that have this permission on their own or through the groups they belong to.
*
* @static
* @template T
* @param {string} codeName - The permission codename.
* @returns {Promise<T[]>}
* @memberof UserWithPermissions
*/
static withPerm<T extends UserWithPermissions>(this: (new () => T) & typeof UserWithPermissions, codeName: string): Promise<T[]>;
static findOneWithPermissionsBy<T extends UserWithPermissions>(this: (new () => T) & typeof UserWithPermissions, { id }: {
id: number;
}): Promise<T | null>;
id: number;
groups: Group[];
userPermissions: Permission[];
/**
* Check if a user has a given permission. The user must have been retreived from the db
* with their groups and permissions. Otherwise, the method will always return false.
*
* @param {string} codeName - Name of the permission.
* @returns {boolean} True if the user has the permission. False otherwise.
* @memberof UserWithPermissions
*/
hasPerm(codeName: string): boolean;
}