mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 18:45:57 +00:00
fix: added missing types validation
This commit is contained in:
parent
c91a07067d
commit
e55b801cb0
@ -118,13 +118,10 @@ export class SettingRepository extends BaseRepository<Setting> {
|
|||||||
) {
|
) {
|
||||||
throw new Error('Setting Model : Value must be a string!');
|
throw new Error('Setting Model : Value must be a string!');
|
||||||
} else if (type === SettingType.multiple_text) {
|
} else if (type === SettingType.multiple_text) {
|
||||||
const isStringArray =
|
if (!this.isArrayOfString(value)) {
|
||||||
Array.isArray(value) &&
|
throw new Error(
|
||||||
value.every((v) => {
|
'Setting Model (Multiple Text) : Value must be a string array!',
|
||||||
return typeof v === 'string';
|
);
|
||||||
});
|
|
||||||
if (!isStringArray) {
|
|
||||||
throw new Error('Setting Model : Value must be a string array!');
|
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
type === SettingType.checkbox &&
|
type === SettingType.checkbox &&
|
||||||
@ -138,6 +135,26 @@ export class SettingRepository extends BaseRepository<Setting> {
|
|||||||
value !== null
|
value !== null
|
||||||
) {
|
) {
|
||||||
throw new Error('Setting Model : Value must be a number!');
|
throw new Error('Setting Model : Value must be a number!');
|
||||||
|
} else if (type === SettingType.multiple_attachment) {
|
||||||
|
if (!this.isArrayOfString(value)) {
|
||||||
|
throw new Error(
|
||||||
|
'Setting Model (Multiple Attachement): Value must be a string array!',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (type === SettingType.attachment) {
|
||||||
|
if (typeof value !== 'string' && typeof value !== null) {
|
||||||
|
throw new Error(
|
||||||
|
'Setting Model (attachement): Value must be a string or null !',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (type === SettingType.secret && typeof value !== 'string') {
|
||||||
|
throw new Error('Setting Model (secret) : Value must be a string');
|
||||||
|
} else if (type === SettingType.select && typeof value !== 'string') {
|
||||||
|
throw new Error('Setting Model (select): Value must be a string array!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isArrayOfString(value: any): boolean {
|
||||||
|
return Array.isArray(value) && value.every((v) => typeof v === 'string');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user