Boss Machine Project -

I have started working on the Boss Machine Project (https://www.codecademy.com/paths/create-a-back-end-app-with-javascript/tracks/bapi-learn-express/modules/boss-machine-project/informationals/bapi-p4-boss-machine) .
I am working on the first part of the assignment:

Routes Required
/api/minions
GET /api/minions to get an array of all minions.

I started creating the routers directly into api.js without using an external router file (i.e. minions.js) looking to do it later to make my code better structured.
My api.js code now looks like this now:

const express = require('express');
const apiRouter = express.Router();

const { 
    createMeeting,
    getAllFromDatabase,
    getFromDatabaseById,
    addToDatabase,
    updateInstanceInDatabase,
    deleteFromDatabasebyId,
    deleteAllFromDatabase,
 } = require('./db');

apiRouter.get('/api/minions',(req,res,next)=>{
    res.send(getAllFromDatabase('minions'));
});

When running the test file, shows like this code is not throwing an array, below the output of issues from running npm run test:


/api/minions routes
GET /api/minions
1) returns an array
2) returns an array of all minions

Hope you can help me here.

Regards,
Dennis.

Hey Dennis,

Since apiRouter should already be mounted in server.js at ‘/api’, your get call should look like this

apiRouter.get('/minions', (req, res, next) => {
    const minions = getAllFromDatabase('minions')
    res.status(200).send(minions);
});

Hope this helps