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,59 @@
import App from './app';
import Base from './base';
import AppAuthClient from './app-auth-client';
class AppConfig extends Base {
static tableName = 'app_configs';
static jsonSchema = {
type: 'object',
required: ['key'],
properties: {
id: { type: 'string', format: 'uuid' },
key: { type: 'string' },
allowCustomConnection: { type: 'boolean', default: false },
shared: { type: 'boolean', default: false },
disabled: { type: 'boolean', default: false },
},
};
static get virtualAttributes() {
return ['canConnect', 'canCustomConnect'];
}
static relationMappings = () => ({
appAuthClients: {
relation: Base.HasManyRelation,
modelClass: AppAuthClient,
join: {
from: 'app_configs.id',
to: 'app_auth_clients.app_config_id',
},
},
});
get canCustomConnect() {
return !this.disabled && this.allowCustomConnection;
}
get canConnect() {
const hasSomeActiveAppAuthClients = !!this.appAuthClients?.some(
(appAuthClient) => appAuthClient.active
);
const shared = this.shared;
const active = this.disabled === false;
const conditions = [hasSomeActiveAppAuthClients, shared, active];
return conditions.every(Boolean);
}
async getApp() {
if (!this.key) return null;
return await App.findOneByKey(this.key);
}
}
export default AppConfig;