Files
bigcapital/server/src/system/models/SystemUser.js
Ahmed Bouhuolia ad00f140d1 feat: licenses administration basic authentication.
feat: accounts slug.
feat: duplicate accounts_balance table and merge balance with accounts table.
feat: refactoring customers and vendors.
feat: system user soft deleting.
feat: preventing build tenant database without any subscription.
feat: remove 'password' property from 'req.user' object.
feat: refactoring JournalPoster class.
feat: delete duplicated directories and files.
2020-09-09 21:30:19 +02:00

56 lines
1.2 KiB
JavaScript

import { Model, mixin } from 'objection';
import bcrypt from 'bcryptjs';
import SoftDelete from 'objection-soft-delete';
import SystemModel from '@/system/models/SystemModel';
import moment from 'moment';
export default class SystemUser extends mixin(SystemModel, [SoftDelete({
columnName: 'deleted_at',
deletedValue: moment().format('YYYY-MM-DD HH:mm:ss'),
notDeletedValue: null,
})]) {
/**
* Table name.
*/
static get tableName() {
return 'users';
}
/**
* Timestamps columns.
*/
get timestamps() {
return ['createdAt', 'updatedAt'];
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const Tenant = require('@/system/models/Tenant');
return {
/**
* System user may belongs to tenant model.
*/
tenant: {
relation: Model.BelongsToOneRelation,
modelClass: Tenant.default,
join: {
from: 'users.tenantId',
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);
}
}