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

@@ -0,0 +1,10 @@
const createError = require('http-errors');
const CartModel = require('../models/CartModel');
const CartInstance = new CartModel();
module.exports = class CartService {
async create(userid) {
const result = await CartInstance.create(userid);
if (!result) throw createError();
}
}

View File

@@ -0,0 +1,25 @@
const createError = require('http-errors');
const ProductModel = require('../models/ProductModel');
const ProductInstance = new ProductModel();
module.exports = class ProductService {
async getAll() {
try {
const result = await ProductInstance.selectAll();
if (!result) throw createError(404, 'No products found.');
return result;
} catch(e) {
throw new Error(e);
}
}
async getOne(id) {
try {
const result = await ProductInstance.findOne(id);
if (!result) throw createError(404, 'No products found.');
return result;
} catch(e) {
throw new Error(e);
}
}
}