mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
WIP Multi-tenant architecture.
This commit is contained in:
54
server/src/models/TenantUser.js
Normal file
54
server/src/models/TenantUser.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import bcrypt from 'bcryptjs';
|
||||
import { Model } from 'objection';
|
||||
import BaseModel from '@/models/Model';
|
||||
// import PermissionsService from '@/services/PermissionsService';
|
||||
|
||||
export default class TenantUser extends BaseModel {
|
||||
// ...PermissionsService
|
||||
|
||||
static get virtualAttributes() {
|
||||
return ['fullName'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'users';
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Role = require('@/models/Role');
|
||||
|
||||
return {
|
||||
roles: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: this.relationBindKnex(Role.default),
|
||||
join: {
|
||||
from: 'users.id',
|
||||
through: {
|
||||
from: 'user_has_roles.userId',
|
||||
to: 'user_has_roles.roleId',
|
||||
},
|
||||
to: 'roles.id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the password of the user.
|
||||
* @param {String} password - The given password.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
verifyPassword(password) {
|
||||
return bcrypt.compareSync(password, this.password);
|
||||
}
|
||||
|
||||
fullName() {
|
||||
return `${this.firstName} ${this.lastName}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user