more detail into models and services

This commit is contained in:
Mikayla Dobson
2022-09-23 12:51:51 -05:00
parent c9c1de3521
commit 0b09152de4
8 changed files with 112 additions and 6 deletions

View File

@@ -1,9 +1,26 @@
module.exports = class ProductModel {
async find() {
const db = require('../db/Pool');
module.exports = class ProductModel {
async selectAll() {
try {
const q = "SELECT * FROM product;";
const result = await db.query(q);
if (result.rows.length) return result.rows;
return [];
} catch(e) {
throw new Error(e);
}
}
async findOne(productid) {
try {
const q = `SELECT * FROM product WHERE id = $1;`;
const filter = [productid];
const result = await db.query(q, filter);
if (result.rows.length) return result.rows[0];
return null;
} catch(e) {
throw new Error(e);
}
}
}