Skip to content

Email validation for createAll method #1267

@smithasmi95

Description

@smithasmi95

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;

};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions