feat: Convert model files to JS

This commit is contained in:
Faruk AYDIN
2024-01-04 19:27:13 +01:00
parent b693c12500
commit 8819ddefa7
20 changed files with 140 additions and 363 deletions

View File

@@ -0,0 +1,50 @@
import Base from './base';
import Permission from './permission';
import User from './user';
class Role extends Base {
static tableName = 'roles';
static jsonSchema = {
type: 'object',
required: ['name', 'key'],
properties: {
id: { type: 'string', format: 'uuid' },
name: { type: 'string', minLength: 1 },
key: { type: 'string', minLength: 1 },
description: { type: ['string', 'null'], maxLength: 255 },
createdAt: { type: 'string' },
updatedAt: { type: 'string' },
},
};
static get virtualAttributes() {
return ['isAdmin'];
}
static relationMappings = () => ({
users: {
relation: Base.HasManyRelation,
modelClass: User,
join: {
from: 'roles.id',
to: 'users.role_id',
},
},
permissions: {
relation: Base.HasManyRelation,
modelClass: Permission,
join: {
from: 'roles.id',
to: 'permissions.role_id',
},
},
});
get isAdmin() {
return this.key === 'admin';
}
}
export default Role;