Open BrandyMello opened 5 years ago
Possibly add population as a req param, since it is now there with the rollback and I cannot get rid of it?
new error: (node:81211) UnhandledPromiseRejectionWarning: Error: Undefined binding(s) detected when compiling FIRST. Undefined column(s): [name] query: select * from "countries" where "name" = ? limit ? with this code:
app.post('/api/v1/territories', async (request, response) => {
const territory = request.body;
const country = await database('countries').where('name', territory.territoryOf).first();
const countryTerritory = {...territory, countryId: country.id};
for (let requiredParameter of ['name', 'territory_population', 'territoryOf']) {
if (!territory[requiredParameter]) {
return response
.status(422)
.send({
error: `Expected format: {
name: <String>,
territoryPopulation: <Integer>,
territoryOf: <String>
}. You are missing a "{requiredParameter}" property.`})
}
}
database('dependencies_or_territories').insert(countryTerritory, 'id')
.then(territory => {
response.status(201).json({ id: territory[0] })
.catch(error => {
response.status(500).json({ error });
})
});
})
Not sure if this has to do with the migration issue. Difficult to test DELETE of territory when POST is not working. -Want to include removing territory of country when county is deleted