# Backend issue in react native course

**URL:** <https://forum.codewithmosh.com/t/backend-issue-in-react-native-course/11291>\
**Category:** Uncategorized\
**Created:** [March 15, 2022, 3:45pm UTC](https://forum.codewithmosh.com/t/backend-issue-in-react-native-course/11291 "2022-03-15T15:45:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benbella](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@Benbella](https://forum.codewithmosh.com/u/Benbella)\
**Post date:** [March 15, 2022, 3:45pm UTC](https://forum.codewithmosh.com/t/backend-issue-in-react-native-course/11291/1 "2022-03-15T15:45:00Z")

</div>

TypeError: Joi.validate is not a function

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [March 17, 2022, 12:15am UTC](https://forum.codewithmosh.com/t/backend-issue-in-react-native-course/11291/2 "2022-03-17T00:15:16Z")

</div>

The Joi API has changed since Mosh recorded the course and you may need to use `schema.validate`[as shown here](https://forum.codewithmosh.com/t/node-js-validatereturn-function-joi-objectid-not-a-function/4562).

---

<div class="post-metadata">

**Author:** ![Yemola](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@Yemola](https://forum.codewithmosh.com/u/Yemola)\
**Post date:** [August 30, 2022, 5:29am UTC](https://forum.codewithmosh.com/t/backend-issue-in-react-native-course/11291/3 "2022-08-30T05:29:51Z")

</div>

Hi Eelsholz,

I have tried to follow the reference you gave regarding the ‘Joi.validate not a function’ error in React Native backend project. Unfortunately, the error still persist after using schema.validate and changing the schema.

Please, can you share your validation.js and listings.js files. I’ll like to see what I’m doing wrong. I’ll appreciate your assistance.

Thanks  
Yemi

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [August 31, 2022, 12:28am UTC](https://forum.codewithmosh.com/t/backend-issue-in-react-native-course/11291/4 "2022-08-31T00:28:20Z")

</div>

You’re still getting `Joi.validate is not a function` even after removing `Joi.validate`? Weird!

I don’t have a validation.js and listings.js. Could you share yours?

---

<div class="post-metadata">

**Author:** ![Yemola](https://avatars.discourse-cdn.com/v4/letter/y/b77776/32.png) [@Yemola](https://forum.codewithmosh.com/u/Yemola)\
**Post date:** [August 31, 2022, 7:27am UTC](https://forum.codewithmosh.com/t/backend-issue-in-react-native-course/11291/5 "2022-08-31T07:27:39Z")

</div>

Thanks for your response.  
**Here is the listings.js router:**

const express = require(“express”);  
const router = express.Router();  
const Joi = require(“joi”);  
const multer = require(“multer”);

const store = require(“…/store/listings”);  
const categoriesStore = require(“…/store/categories”);  
const validateWith = require(“…/middleware/validation”);  
const auth = require(“…/middleware/auth”);  
const imageResize = require(“…/middleware/imageResize”);  
const delay = require(“…/middleware/delay”);  
const listingMapper = require(“…/mappers/listings”);  
const config = require(“config”);

const upload = multer({  
dest: “uploads/”,  
limits: { fieldSize: 25 \* 1024 \* 1024 },  
});

const schema = Joi.object({  
title: Joi.string().required(),  
description: Joi.string().allow(“”),  
price: Joi.number().required().min(1),  
categoryId: Joi.number().required().min(1),  
location: Joi.object({  
latitude: Joi.number().required(),  
longitude: Joi.number().required(),  
}).optional(),  
});

const validateCategoryId = (req, res, next) =\> {  
if (!categoriesStore.getCategory(parseInt(req.body.categoryId)))  
return res.status(400).send({ error: “Invalid categoryId.” });

next();  
};

router.get(“/”, (req, res) =\> {  
const listings = store.getListings();  
const resources = listings.map(listingMapper);  
res.send(resources);  
});

router.post(  
“/”,  
[  
// Order of these middleware matters.  
// “upload” should come before other “validate” because we have to handle  
// multi-part form data. Once the upload middleware from multer applied,  
// request.body will be populated and we can validate it. This means  
// if the request is invalid, we’ll end up with one or more image files  
// stored in the uploads folder. We’ll need to clean up this folder  
// using a separate process.  
// auth,  
upload.array(“images”, config.get(“maxImageCount”)),  
validateWith(schema),  
validateCategoryId,  
imageResize,  
],

async (req, res) =\> {  
const listing = {  
title: req.body.title,  
price: parseFloat(req.body.price),  
categoryId: parseInt(req.body.categoryId),  
description: req.body.description,  
};  
listing.images = req.images.map((fileName) =\> ({ fileName: fileName }));  
if (req.body.location) listing.location = JSON.parse(req.body.location);  
if (req.user) listing.userId = req.user.userId;

```
store.addListing(listing);

res.status(201).send(listing);

```

}  
);

module.exports = router;

**And this is the validation.js module:** I commented the initial code from Mosh

module.exports = schema =\> (req, res, next) =\> {  
const result = schema.validate(req.body);

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

next();  
};

// module.exports = schema =\> (req, res, next) =\> {  
// const result = schema.validate(req.body);

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

// next();  
// };

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [September 3, 2022, 12:15am UTC](https://forum.codewithmosh.com/t/backend-issue-in-react-native-course/11291/6 "2022-09-03T00:15:41Z")

</div>

I’m trying some of your code and I’m not running into any errors yet. Do you have the exact error message, and the stack trace?
