updates to cart section of api

This commit is contained in:
Mikayla Dobson
2022-09-27 17:23:39 -05:00
parent d99cf5bb8a
commit 9c80989860
4 changed files with 22 additions and 14 deletions

View File

@@ -15,7 +15,7 @@ async function main() {
password VARCHAR NOT NULL,
firstname VARCHAR,
lastname VARCHAR,
isAdmin BOOLEAN DEFAULT FALSE
isadmin BOOLEAN DEFAULT FALSE
);
`;
@@ -23,7 +23,7 @@ async function main() {
const createCartTable = `
CREATE TABLE IF NOT EXISTS cart (
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY NOT NULL,
appUserId INT REFERENCES users(id)
userid INT REFERENCES users(id)
);
`;

View File

@@ -4,7 +4,7 @@ const pgp = require('pg-promise')({ capSQL: true });
module.exports = class CartModel {
async create(userid) {
try {
const statement = pgp.helpers.insert(userid, null, 'carts') + 'RETURNING *';
const statement = pgp.helpers.insert(userid, null, 'cart') + 'RETURNING *';
const result = await db.query(statement);
if (result.rows.length) return result.rows[0];
return null;
@@ -15,7 +15,7 @@ module.exports = class CartModel {
async findOneByUserId(userid) {
try {
const statement = `SELECT * FROM carts WHERE userid = $1`;
const statement = `SELECT * FROM cart WHERE userid = $1`;
const filter = [userid];
const result = await db.query(statement, filter);
if (result.rows.length) return result.rows[0];
@@ -27,7 +27,7 @@ module.exports = class CartModel {
async findOneByCartId(cartid) {
try {
const statement = `SELECT * FROM carts WHERE id = $1`;
const statement = `SELECT * FROM cart WHERE id = $1`;
const filter = [cartid];
const result = await db.query(statement, filter);
if (result.rows.length) return result.rows[0];
@@ -36,4 +36,20 @@ module.exports = class CartModel {
throw new Error(e);
}
}
async updateCart(data) {
try {
} catch(e) {
throw new Error(e);
}
}
async insertNewItem(data) {
try {
} catch(e) {
throw new Error(e);
}
}
}

View File

@@ -5,14 +5,6 @@ const router = require('express').Router();
module.exports = (app, passport) => {
app.use('/api/auth', router);
router.get('/', async (req, res, next) => {
try {
res.send('auth get response');
} catch(e) {
next(e);
}
})
router.post('/register', async (req, res, next) => {
try {
const data = req.body;

View File

@@ -16,7 +16,7 @@ module.exports = class AuthService {
bcrypt.hash(password, salt, (err, hash) => {
if (err) throw err;
const newData = {
email: email,
...data,
password: hash
}