Saturday, 8 July 2017

Node n00b, question on a problem I have for school

Hi all,Here's the question (link).up to that point in the exercises, we've set up a postgres db and are making requests via postman to a local server, which is talking to the postgres db. in the database, there are 2 tables -- restaurants and grades. grades has a restaurants_id column that references the id column in restaurants.is the idea to update both the restaurants and grades table at the same time, per object insertion? i’ve managed to add the restaurant info to the restaurants table, and the grade/score info to the grades table.i haven't managed to figure out how to add this info to the two tables and link them up with the foreign key reference that exists between the tables.if none of this makes any sense, sorry for wasting your time and thanks for trying. tricky doing work on the weekend when i can't reach anyone from school.thanks, and below is my code:const express = require('express'); const bodyParser = require('body-parser');const { DATABASE, PORT } = require('./config'); const knex = require('knex')(DATABASE); const app = express(); app.use(bodyParser.json()); app.post('/restaurants', (req, res) => { const restaurantsInsert = { name: req.body.name, cuisine: req.body.cuisine, borough: req.body.borough }; knex .insert(restaurantsInsert) .into('restaurants') .then(result => res.status(201)); knex .insert(req.body.grades) .into('grades') .then(result => res.status(201).end()); }); app.listen(PORT);

Submitted July 09, 2017 at 04:30AM by askholeprojector

No comments:

Post a Comment