mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-14 20:00:33 +00:00
61 lines
1.0 KiB
TypeScript
61 lines
1.0 KiB
TypeScript
import { Model } from 'objection';
|
|
import TenantModel from 'models/TenantModel';
|
|
|
|
export default class User extends TenantModel {
|
|
/**
|
|
* Table name.
|
|
*/
|
|
static get tableName() {
|
|
return 'users';
|
|
}
|
|
|
|
/**
|
|
* Timestamps columns.
|
|
*/
|
|
get timestamps() {
|
|
return ['created_at', 'updated_at'];
|
|
}
|
|
|
|
/**
|
|
* Virtual attributes.
|
|
*/
|
|
static get virtualAttributes() {
|
|
return ['isInviteAccepted', 'fullName'];
|
|
}
|
|
|
|
/**
|
|
* Detarmines whether the user ivnite is accept.
|
|
*/
|
|
get isInviteAccepted() {
|
|
return !!this.inviteAcceptedAt;
|
|
}
|
|
|
|
/**
|
|
* Full name attribute.
|
|
*/
|
|
get fullName() {
|
|
return `${this.firstName} ${this.lastName}`.trim();
|
|
}
|
|
|
|
/**
|
|
* Relationship mapping.
|
|
*/
|
|
static get relationMappings() {
|
|
const Role = require('models/Role');
|
|
|
|
return {
|
|
/**
|
|
* User belongs to user.
|
|
*/
|
|
role: {
|
|
relation: Model.BelongsToOneRelation,
|
|
modelClass: Role.default,
|
|
join: {
|
|
from: 'users.roleId',
|
|
to: 'roles.id',
|
|
},
|
|
},
|
|
};
|
|
}
|
|
}
|