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

@@ -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);
}
}
}