loopback4-example-shopping icon indicating copy to clipboard operation
loopback4-example-shopping copied to clipboard

Email validation for createAll method

Open smithasmi95 opened this issue 4 years ago • 1 comments

Hi All, the documentation of loopback 4 does not contain validations for createAll method at interceptors. Can anyone guide me on how do we validate for createAll method?

const validateOrder: Interceptor = async (invocationCtx, next) => {

 console.log('log: before-', invocationCtx.methodName);

 const order: Order = new Order();

 if (invocationCtx.methodName == 'create')
     Object.assign(order, invocationCtx.args[0]);

 else if (invocationCtx.methodName == 'updateById')
     Object.assign(order, invocationCtx.args[1]);

 if (order.orderNum.length !== 6) {
     throw new HttpErrors.InternalServerError('Invalid order number');
 }
   
 const result = await next();
 return result;

};

smithasmi95 avatar Jul 29 '21 09:07 smithasmi95

@smithasmi95 sorry I don't think I follow as your code snippet does not illustrate any createAll logic. Some tips if the question is not related to this repo I would suggest you ask it on Slack or via LoopBack monorepo

mrmodise avatar Sep 29 '21 05:09 mrmodise