54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
import { OakInputIllegalException } from 'oak-domain/lib/types';
|
|
import { checkAttributesNotNull } from 'oak-domain/lib/utils/validator';
|
|
import { isVersion } from 'oak-domain/lib/utils/version';
|
|
const checkers = [
|
|
{
|
|
type: 'data',
|
|
action: 'create',
|
|
entity: 'system',
|
|
checker: (data) => {
|
|
const setData = (data) => {
|
|
if (!data.config) {
|
|
Object.assign(data, {
|
|
config: {},
|
|
});
|
|
}
|
|
if (!data.super) {
|
|
Object.assign(data, {
|
|
super: false,
|
|
});
|
|
}
|
|
};
|
|
if (data instanceof Array) {
|
|
data.forEach((ele) => {
|
|
checkAttributesNotNull('system', ele, ['name', 'platformId']);
|
|
if (ele.oldestVersion && !isVersion(ele.oldestVersion)) {
|
|
throw new OakInputIllegalException('system', ['oldestVersion'], 'error::illegalVersionData', 'oak-general-business');
|
|
}
|
|
setData(ele);
|
|
});
|
|
}
|
|
else {
|
|
checkAttributesNotNull('system', data, ['name', 'platformId']);
|
|
if (data.oldestVersion && !isVersion(data.oldestVersion)) {
|
|
throw new OakInputIllegalException('system', ['oldestVersion'], 'error::illegalVersionData', 'oak-general-business');
|
|
}
|
|
setData(data);
|
|
}
|
|
return;
|
|
},
|
|
},
|
|
{
|
|
type: 'data',
|
|
action: 'update',
|
|
entity: 'system',
|
|
checker(data) {
|
|
const { oldestVersion } = data;
|
|
if (oldestVersion && !isVersion(oldestVersion)) {
|
|
throw new OakInputIllegalException('system', ['oldestVersion'], 'error::illegalVersionData');
|
|
}
|
|
}
|
|
}
|
|
];
|
|
export default checkers;
|