fix: added missing types validation

This commit is contained in:
abdou6666 2024-12-16 11:33:07 +01:00
parent c91a07067d
commit e55b801cb0

View File

@ -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');
}
} }