more detail into models and services
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user