Files
e-commerce/services/ProductService.js
2022-09-23 12:51:51 -05:00

25 lines
717 B
JavaScript

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