mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
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}`;
|
|
}
|
|
} |