Build the Movies API

Hello guys, i need your help, currently working with movies API, without Joi validation, my code was throwing error

const {Movie} = require(‘…/models/movie’);
const Genre = require(‘…/models/genre’);
const express = require(‘express’);

const router = express.Router();

router.get(‘/’, async (req, res) => {
const movies = await Movie.find().sort(‘title’);
res.send(movies);
});

router.post(‘/’, async (req, res) => {
const genreId = req.body.genreId;

const genre = await Genre.findById({ "_id": genreId});
if (!genre) { 
    return res.status(404).json.send({ message: 'Genre not found' });
} 

let movie = new Movie({
    title: req.body.title,
    genre: {
        _id: genre._id,
        name: genre.name,
    },
    numberInStock: req.body.numberInStock,
    dailyRentalRate: req.body.dailyRentalRate
});
movie = await movie.save();

});

module.exports = router;

output error:
const genre = await Genre.findById(req.body.genreId);
^
TypeError: Genre.findById is not a function

I think you need to change your require line (notice the curly braces around Genre) from this:

const Genre = require(‘…/models/genre’);

To this:

const {Genre} = require(‘…/models/genre’);

Thanks for your contribution, :bouquet:
My code is working perfectly, I have completed the exercise, but I need more of the back-end materials to level up my skill, I would be glad if you could share with me updated materials

Blockquote

You’re welcome.

I don’t think I understand what you mean by “updated materials”. The node course hasn’t been updated since it was first recorded, or this is what I know.

I mean the latest advanced NodeJs material pure back-end

If you’re looking to learn more advanced things in Node.js then perhaps you can extend the Movie Rental project to have an admin panel and other features like that. You will come across different roadblocks for which you will need to do your research and watch some tutorials.

This will be a more holistic way, I think. Another good way would be to pick a project, that interests you, from some YouTube channel. Once you’ve completed the playlist/video, you can extend the project and make it better. The advantage of this second way is that you’ll learn a different way to do things than how Mosh has done in the course. But try not to fall into the tutorial hell because then you won’t be gaining much.