58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import { BaseModel } from './base.model';
|
|
|
|
export class User extends BaseModel {
|
|
static tableName = 'users';
|
|
|
|
id: string;
|
|
email: string;
|
|
password: string;
|
|
firstName?: string;
|
|
lastName?: string;
|
|
isActive: boolean;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
|
|
static get jsonSchema() {
|
|
return {
|
|
type: 'object',
|
|
required: ['email', 'password'],
|
|
properties: {
|
|
id: { type: 'string' },
|
|
email: { type: 'string', format: 'email' },
|
|
password: { type: 'string' },
|
|
firstName: { type: 'string' },
|
|
lastName: { type: 'string' },
|
|
isActive: { type: 'boolean' },
|
|
},
|
|
};
|
|
}
|
|
|
|
static get relationMappings() {
|
|
const { UserRole } = require('./user-role.model');
|
|
const { Role } = require('./role.model');
|
|
|
|
return {
|
|
userRoles: {
|
|
relation: BaseModel.HasManyRelation,
|
|
modelClass: UserRole,
|
|
join: {
|
|
from: 'users.id',
|
|
to: 'user_roles.userId',
|
|
},
|
|
},
|
|
roles: {
|
|
relation: BaseModel.ManyToManyRelation,
|
|
modelClass: Role,
|
|
join: {
|
|
from: 'users.id',
|
|
through: {
|
|
from: 'user_roles.userId',
|
|
to: 'user_roles.roleId',
|
|
},
|
|
to: 'roles.id',
|
|
},
|
|
},
|
|
};
|
|
}
|
|
}
|