mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
import { mixin } from 'objection';
|
|
import BaseModel from '@/models/Model';
|
|
import MetableCollection from '@/lib/Metable/MetableCollection';
|
|
import definedOptions from '@/data/options';
|
|
|
|
export default class Option extends mixin(BaseModel, [mixin]) {
|
|
/**
|
|
* Table name.
|
|
*/
|
|
static get tableName() {
|
|
return 'options';
|
|
}
|
|
|
|
/**
|
|
* Override the model query.
|
|
* @param {...any} args -
|
|
*/
|
|
static query(...args) {
|
|
return super.query(...args).runAfter((result) => {
|
|
if (result instanceof MetableCollection) {
|
|
result.setModel(Option);
|
|
result.setExtraColumns(['group']);
|
|
}
|
|
return result;
|
|
});
|
|
}
|
|
|
|
static get collection() {
|
|
return MetableCollection;
|
|
}
|
|
|
|
static validateDefined(options) {
|
|
const notDefined = [];
|
|
|
|
options.forEach((option) => {
|
|
if (!definedOptions[option.group]) {
|
|
notDefined.push(option);
|
|
} else if (!definedOptions[option.group].some((o) => o.key === option.key)) {
|
|
notDefined.push(option);
|
|
}
|
|
});
|
|
return notDefined;
|
|
}
|
|
}
|