feat: make role name unique and remove key usage

This commit is contained in:
Ali BARIN
2024-09-04 11:07:45 +00:00
parent b089069b8e
commit 63dfb6947e
33 changed files with 51 additions and 55 deletions

View File

@@ -7,22 +7,17 @@ class Role extends Base {
static jsonSchema = {
type: 'object',
required: ['name', 'key'],
required: ['name'],
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,
@@ -43,11 +38,11 @@ class Role extends Base {
});
get isAdmin() {
return this.key === 'admin';
return this.name === 'Admin';
}
static async findAdmin() {
return await this.query().findOne({ key: 'admin' });
return await this.query().findOne({ name: 'Admin' });
}
}