//const dao = require('./product-restaurants-db'); import * as dao from '../repository/product-restaurant-repository'; import { ProductRestaurants } from '../model/product-restaurant'; export async function byId (id:number){ try { if(!id) { throw 'Param Execution Error Function ( product-restaurant-service.byId ) ==> Stack Error : Param id is null'; } var result = await dao.byId(id); console.log(result); if(result.rowCount > 0){ return result.rows[0]; } return null; } catch (error) { throw error; } } export async function byRestaurantIdAndProduct (idRestaurant:number, productId:number){ try { if(!idRestaurant) { throw 'Param Execution Error Function ( product-restaurant-service.byRestaurantIdAndProduct ) ==> Stack Error : Param idRestaurant is null'; } if(!productId) { throw 'Param Execution Error Function ( product-restaurant-service.byRestaurantIdAndProduct ) ==> Stack Error : Param productId is null'; } var result = await dao.byRestaurantIdAndProduct(idRestaurant, productId); if(result.rowCount > 0){ return result.rows[0]; } return null; } catch (error) { throw error; } } export async function save(productRestaurants:ProductRestaurants){ try { validateParameters(productRestaurants); var result = await dao.save(productRestaurants); if(result.rowCount > 0){ return result.rows[0]; } return null; } catch (error) { throw error; } } export async function update(productRestaurants:ProductRestaurants){ try { //validateParameters(productRestaurants); await dao.update(productRestaurants); } catch (error) { throw error; } } export async function remove(productRestaurants:ProductRestaurants){ try { await dao.remove(productRestaurants); } catch (error) { throw error; } } function validateParameters(productRestaurants :ProductRestaurants) { if(!productRestaurants.idRestaurants) { throw 'Param Execution Error Function ( product-restaurant-service.save ) ==> Stack Error : Param idRestaurant is null'; } if(!productRestaurants.idProduct) { throw 'Param Execution Error Function ( product-restaurant-service.save ) ==> Stack Error : Param idProduct is null'; } if(!productRestaurants.currentPriceUnit1) { throw 'Param Execution Error Function ( product-restaurant-service.save ) ==> Stack Error : Param currentPrice is null'; } if(!productRestaurants.originalPrice) { throw 'Param Execution Error Function ( product-restaurant-service.save ) ==> Stack Error : Param originalPrice is null'; } if(productRestaurants.stock == null) { throw 'Param Execution Error Function ( product-restaurant-service.save ) ==> Stack Error : Param originalPrice is null'; } if(!productRestaurants.insertUser || !productRestaurants.updateUser) { throw 'Param Execution Error Function ( product-restaurant-service.validateParameters ) ==> Stack Error : Param insertUser is null or updateUser is null'; } if(!productRestaurants.createdAt || !productRestaurants.updatedAt) { throw 'Param Execution Error Function ( product-restaurant-service.validateParameters ) ==> Stack Error : Param createdAt is null or updatedAt is null'; } if(!(typeof productRestaurants.isDeleted == "boolean")) { throw 'Param Execution Error Function ( product-restaurant-service.validateParameters ) ==> Stack Error : Param touchedByHuman input wrong or field is null ! This attribute is a BOOLEAN'; } }