Skip to content

User Story 10 - Incorporate middleware to verify params #84

@alexanderjhughes

Description

@alexanderjhughes

Use the Joi library to validate params:

import Joi from 'joi';

const validateCardParams = (req, res, next) => {
  const schema = Joi.object({
    card_id: Joi.number().required(),
    card_bin: Joi.number().required(),
  });

  const { error } = schema.validate(req.params);

  if (error) {
    res.status(400).json({ message: error.details[0].message });
    return;
  }

  next();
};

// Then use it in your route
app.get('/card', validateCardParams, CardController.getCard);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions