Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static async find(_query: WorldCountryStateQueryInterface): Promise {
const query: WorldCountryStateQuery = plainToClass(WorldCountryStateQuery, _query);
// clear undefined/empty values
for (const key of Object.keys(query)) {
if (!query[key]) {
delete query[key];
}
}
try {
await validateOrReject(query, {
whitelist: true,
forbidNonWhitelisted: true,
validationError: { target: false, value: false },
});
} catch (err) {
return;
}
const stateData: WorldCountryStateInterface | undefined = (countryStates as WorldCountryStateInterface[]).find(
(plainState: WorldCountryStateInterface) => {
const state: WorldCountryState = plainToClass(WorldCountryState, plainState);
return WorldCountryStateUtil.match(state, query);
},
);
private validateInput = async (): Promise => {
try {
const validation = new InputValidation()
validation.name = this.newProps.name
validation.phone = this.newProps.phone
validation.address = this.newProps.address
validation.avatar = this.newProps.avatar
validation.birthdate = this.newProps.birthdate
await validateOrReject(validation)
} catch (error) {
throw new this.HttpException(400, 'invalid inputs', error)
}
}
protected validateValue(value: any, paramMetadata: ParamMetadata): Promise|any {
const isValidationEnabled = (paramMetadata.validate instanceof Object || paramMetadata.validate === true)
|| (this.driver.enableValidation === true && paramMetadata.validate !== false);
const shouldValidate = paramMetadata.targetType
&& (paramMetadata.targetType !== Object)
&& (value instanceof paramMetadata.targetType);
if (isValidationEnabled && shouldValidate) {
const options = paramMetadata.validate instanceof Object ? paramMetadata.validate : this.driver.validationOptions;
return validate(value, options)
.then(() => value)
.catch((validationErrors: ValidationError[]) => {
const error: any = new BadRequestError(`Invalid ${paramMetadata.type}, check 'errors' property for more info.`);
error.errors = validationErrors;
error.paramName = paramMetadata.name;
throw error;
});
}
return value;
}
update(todo: Partial): Promise {
return validateOrReject('todo', todo, { skipMissingProperties: true })
.then(() => todosDao.update(todo));
},
private validateInput = async (): Promise => {
try {
const validation = new InputValidation()
validation.email = this.credentials.email
validation.password = this.credentials.password
await validateOrReject(validation)
} catch (error) {
throw new this.HttpException(400, 'invalid inputs')
}
}
private validateInput = async (): Promise => {
this.validation.name = this.user.name
this.validation.email = this.user.email
this.validation.password = this.user.password
await validateOrReject(this.validation)
.catch((errors): void => {
throw new this
.HttpException(this.status, 'input validation error', errors)
})
}
create(todo: CreateTodoEntity): Promise {
return validateOrReject('todo', todo)
.then(() => todosDao.create(todo));
},
async execute(_query: GeocoderQueryType): Promise {
const query: GeocoderQueryType = plainToClass(this.constructor.queryClass(), _query);
try {
await validateOrReject(query, {
whitelist: true,
forbidNonWhitelisted: true,
validationError: { target: false, value: false },
});
} catch (err) {
this.getLogger().error(err, query);
throw new ValidationException(err);
}
if (query.accuracy && !this.constructor.isProvidesAccuracy(query.accuracy)) {
throw new UnsupportedAccuracyException(
`Command ${this.constructor.name} doesn't support "${query.accuracy}" accuracy (max accuracy is "${this.constructor.getMaxAccuracy()}")`,
);
}