WIP Multi-tenant architecture.

This commit is contained in:
Ahmed Bouhuolia
2020-04-21 22:47:27 +02:00
parent 4e0d3feebe
commit 8f588ffc51
64 changed files with 812 additions and 447 deletions

View File

@@ -0,0 +1,39 @@
import { Model } from 'objection';
import bcrypt from 'bcryptjs';
import SystemModel from '@/system/models/SystemModel';
export default class SystemUser extends SystemModel {
/**
* Table name.
*/
static get tableName() {
return 'users';
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const Tenant = require('@/system/models/Tenant');
return {
tenant: {
relation: Model.BelongsToOneRelation,
modelClass: Tenant.default,
join: {
from: 'users.tenant_id',
to: 'tenants.id',
},
},
};
}
/**
* Verify the password of the user.
* @param {String} password - The given password.
* @return {Boolean}
*/
verifyPassword(password) {
return bcrypt.compareSync(password, this.password);
}
}