config = require('../DB'); let GetSaerchResult = (lat, lng, miles, callback)=>{ config.getDB().query(`SELECT * FROM (SELECT *, ((( acos(sin((${lat} * pi() / 180))*sin(( lat * pi() / 180)) + cos(( ${lat} * pi() /180 ))*cos(( lat * pi() / 180)) * cos(((${lng} - lng) * pi()/180)))) * 180/pi()) * 60 * 1.1515) as distance FROM community_provider ) myTable WHERE distance <= ${miles} LIMIT 15`, callback); } let GetType = (community_provider_id, callback)=>{ config.getDB().query(`SELECT community_provider.community_provider_id, community_provider.type , community_provider.address, community_provider.comm_name, community_provider.city, community_provider.state, community_provider.zip_code, community_provider.county, community_provider.type, user.f_name, user.l_name, user.email, user.user_img, user.user_id, user.user_type FROM community_provider,user_role, user WHERE community_provider.community_provider_id = user_role.community_provider_id and user_role.user_id = user.user_id and community_provider.community_provider_id='${community_provider_id}'`, callback); //config.getDB().query(`SELECT community_provider.community_provider_id, community_provider.type , community_provider.address, community_provider.comm_name, community_provider.city, community_provider.state, community_provider.zip_code, community_provider.county, community_provider.type, user.f_name, user.l_name, user.email, user.user_img, user.user_id, user.user_type, company.dba, company.license, company.status, company.year_founded, company.primarily_phone, company.cell_phone, company.fax, company.website, company.external_website, company.company_logo, company.company_overview, company.created_by FROM community_provider,user_role, user, company WHERE company.community_id= community_provider.community_provider_id and community_provider.community_provider_id = user_role.community_provider_id and user_role.user_id = user.user_id and community_provider.community_provider_id='${community_provider_id}'`, callback); } let GetCompany = (community_id, callback)=>{ config.getDB().query(`SELECT * FROM company WHERE community_id='${community_id}'`, callback); } let getInsentives = (user_id, callback)=>{ config.getDB().query(`SELECT * FROM incentives WHERE published=1 AND user_id ='${user_id}'`, callback); } let SaveSearch = (dataToset, callback)=>{ config.getDB().query(`insert into save_search set ? `, dataToset, callback); } let getName = (criteria, callback) => { config.getDB().query(`SELECT save_id, name FROM save_search where name= ?`, criteria.name, callback); } let GetSaveSearch = (user_id, callback)=>{ config.getDB().query(`SELECT * FROM save_search where type='provider' && user_id=${user_id}`, callback); } let ChechincetiveSearch= (criteria, callback)=>{ var setData = ''; Object.keys(criteria).forEach(function (k) { { setData += 'incentive_id' + ' = "' + criteria[k] + '" OR '; } }); setData = setData.substring(0, setData.length - 3); config.getDB().query(`SELECT * FROM incentives WHERE ${setData}`, callback); } module.exports = { GetType: GetType, GetCompany : GetCompany, GetSaerchResult: GetSaerchResult, getInsentives : getInsentives, SaveSearch : SaveSearch, getName : getName, GetSaveSearch : GetSaveSearch, ChechincetiveSearch : ChechincetiveSearch }