62 lines
2.0 KiB
JavaScript
62 lines
2.0 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';
|
|
function checkVersion(data) {
|
|
const { dangerousVersions, warningVersions, soaVersion } = data;
|
|
if (dangerousVersions && dangerousVersions.find(ele => !isVersion(ele))) {
|
|
throw new OakInputIllegalException('application', ['dangerousVersions'], 'error::illegalVersionData');
|
|
}
|
|
if (warningVersions && warningVersions.find(ele => !isVersion(ele))) {
|
|
throw new OakInputIllegalException('application', ['warningVersions'], 'error::illegalVersionData');
|
|
}
|
|
if (soaVersion && !isVersion(soaVersion)) {
|
|
throw new OakInputIllegalException('application', ['soaVersion'], 'error::illegalVersionData');
|
|
}
|
|
}
|
|
const checkers = [
|
|
{
|
|
type: 'data',
|
|
action: 'create',
|
|
entity: 'application',
|
|
checker: (data, context) => {
|
|
const setData = (data) => {
|
|
if (!data.config) {
|
|
Object.assign(data, {
|
|
config: {},
|
|
});
|
|
}
|
|
};
|
|
if (data instanceof Array) {
|
|
data.forEach((ele) => {
|
|
checkVersion(ele);
|
|
checkAttributesNotNull('application', ele, [
|
|
'name',
|
|
'type',
|
|
'systemId',
|
|
]);
|
|
setData(ele);
|
|
});
|
|
}
|
|
else {
|
|
checkVersion(data);
|
|
checkAttributesNotNull('application', data, [
|
|
'name',
|
|
'type',
|
|
'systemId',
|
|
]);
|
|
setData(data);
|
|
}
|
|
return;
|
|
},
|
|
},
|
|
{
|
|
type: 'data',
|
|
action: 'update',
|
|
entity: 'application',
|
|
checker(data) {
|
|
checkVersion(data);
|
|
}
|
|
}
|
|
];
|
|
export default checkers;
|