Files
e-commerce/services/RegionsService.js
2022-09-27 14:04:56 -05:00

35 lines
992 B
JavaScript

const createError = require('http-errors');
const RegionsModel = require('../models/RegionsModel');
const RegionInstance = new RegionsModel();
module.exports = class RegionsService {
async getAll() {
try {
const result = await RegionInstance.selectAll();
if (!result) throw createError(404, "No region entries found.");
return result;
} catch(e) {
throw new Error(e);
}
}
async getOne(id) {
try {
const result = await RegionInstance.getOne(id);
if (!result) throw createError(404, "No region entries found.");
return result;
} catch(e) {
throw new Error(e);
}
}
async create(data) {
try {
const result = await RegionInstance(data);
if (!result) throw createError(401, "Unauthorized action");
return result;
} catch(e) {
throw new Error(e);
}
}
}