Expresso project - Building REST APIs using SQLite

Hi,
I’m trying to complete the Expresso cumulative project in the Web Development path, the final project for section 13, building APIs using persistent data. All of the CRUD methods are working from the Front End, except for Timesheets. For the Timesheets I’m not able to create (add) a timesheet for an employee I get the following error from the server console: Error: SQLITE_CONSTRAINT: NOT NULL constraint failed: Timesheet.employee_id
Has anybody who’s done this project encountered this? Anybody?? I’ve triple checked my code against the solution sheet. I don’t see anything wrong with my code. I know what the error means and the id field is definitely not NULL. I will paste my code from timesheet.js and the link to the project below:

https://www.codecademy.com/paths/web-development/tracks/building-a-persistent-api/modules/persistent-api-cumulative-projects/informationals/cumulative-project-expresso

const express = require('express');
const exployeesRouter = require('./employees.js');
const timesheetsRouter = express.Router({mergeparams: true});

const sqlite3 = require('sqlite3');
const db = new sqlite3.Database(process.env.TEST_DATABASE || './database.sqlite');

timesheetsRouter.param('timesheetId', (req, res, next, timesheetId)=> {
	const sql = 'SELECT * FROM Timesheet WHERE Timesheet.id = $timesheetId';
	const values = {$timesheetId: timesheetId};
	db.get(sql, values, (error, timesheet)=> {
		if(error){
			next(error);
		} else if(timesheet){
			next();
		} else {
			res.sendStatus(404);
		}
		

	});
});

timesheetsRouter.get('/',(req, res, next)=>{
	    const sql = 'SELECT * FROM Timesheet WHERE Timesheet.employee_id = $employeeId';
		const values = {$employeeId: req.params.employeeId}
db.all(sql, values, (error, timesheets)=>{
	if(error){
			next(error);
		} else {
			res.status(200).json({timesheets: timesheets})
		}
  });	
		
});

timesheetsRouter.post('/',(req, res, next)=>{
	const hours = req.body.timesheet.hours;
	const rate = req.body.timesheet.rate;
	const date = req.body.timesheet.date;
	const employeeId = req.params.employeeId;

	if (!hours || !rate || !date) {
		return res.sendStatus(400) //Bad request
	} 
	const sql = 'INSERT INTO Timesheet (hours, rate, date, employee_id)' +
	'VALUES ($hours, $rate, $date, $employeeId)';
	const values = {
		$hours: hours,
		$rate: rate,
		$date: date,
		$employeeId: employeeId
	};

	db.run(sql, values, (error)=> {
		if(error){
			next(error);
		} else {
			db.get(`SELECT * FROM Timesheet WHERE Timesheet.id = ${this.lastID}`, (error, timesheet)=> {
				res.status(201).json({timesheet: timesheet});
		
		   }); //End db get
		}
	}); //End Db run
}); //End db Post

timesheetsRouter.put('/:timesheetId', (req, res, next)=> {
	const hours = req.body.timesheet.hours;
	const rate = req.body.timesheet.rate;
	const date = req.body.timesheet.date;
	const employeeId = req.params.employeeId;

	if(!hours || !rate || !date) {
		res.sendStatus(400); //Bad request
	}

	const sql = 'UPDATE Timesheet SET hours = $hours, rate = $rate, date = $date, employeeId = $employeeId ' +
	' WHERE Timesheet.id = $timesheetId';
	  const values = {
		$hours: hours,
		$rate: rate,
		$date: date,
		$employeeId: employeeId,
		$timesheetId: req.params.timesheetId
	};

	db.run(sql, values, (error)=> {
		if(error){
			next(error);
		} else {
			db.get(`SELECT * FROM Timesheet WHERE Timesheet.id = ${req.params.timesheetId}`, (error, timesheet)=>{
				res.sendStatus(200).json({timesheet: timesheet});
			});

		}
	});
});

timesheetsRouter.delete('/:timesheetId', (req, res, next)=>{
	const sql = 'DELETE FROM Timesheet WHERE Timesheet.id = $timesheetId';
	const values = {
		timesheetId: req.params.timesheetId,
		employeeId: req.params.employeeId
	};
	db.run(sql, values, (error)=> {
		if(error){
			next(error);
		} else if(!timesheetId || !employeeId) {
			res.sendStatus(404); //Not found
		} else {
			res.status(204);
		}

		
	}); //db run
}); //router.delete

module.exports = timesheetsRouter;

It looks like this line:

if (!hours || !rate || !date) {

should be this instead:

if (!hours || !rate || !date || !employeeId) {

That should get rid of the constraint error, but then you would still need to determine why employeeId is missing. Since I can’t see the code that is making the POST request, I can only assume that your payload is missing the employeeId for some unknown reason.

Yes, adding employeeId to the If statement got rid of the constraint error, but now when I try to add a Timesheet I get the 400 response which is Bad Request. There WAS actually a syntax error in my migration.js file that I caught. In the Timesheet table Timesheet.employee_id had some missing quotation marks, and I really thought that was the whole problem so then I corrected the error and dropped and re-created the table but I still cannot POST data to a timesheet for an employee. Funny enough I can manually populate this table using Db browse successfully. When I go back to the front end though, I see no timesheets. Something is off, but what ?? There’s nothing that pops off the page and hits me over the head, and my code for the post is exactly the same as the solution.