handleResponse with joi

PHOTO EMBED

Sat Mar 26 2022 12:51:00 GMT+0000 (Coordinated Universal Time)

Saved by @mmzaghlool52 #markdown

import express from 'express';
import {middleWares, formBadRequest} from 'nodejs-express-utils';
const app = express();

app.post(
    '/',
	middleWares.inputJoi(extendedJoi.object({
      id: joi.number().required(),
	  name: joi.string().optional(),
    })),
  	
    // data is the validated data returned from the inputJoi middleware
    middleWares.handleResponse((data) => {
		const {id, name} = data;
      	
      	if(!name) {
           return formBadRequest('missing-name');
        }
      	
      	
      	return {data: {}};
    }),
);
content_copyCOPY