{"size": 539, "ext": "js", "max_stars_repo_path": "server/services/notifications/createNotif.js", "max_stars_repo_name": "wassimbj/trasty", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/services/notifications/createNotif.js", "max_issues_repo_name": "wassimbj/trasty", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/services/notifications/createNotif.js", "max_forks_repo_name": "wassimbj/trasty", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.962962963, "max_line_length": 78, "alphanum_fraction": 0.6307977737}
import db from '../../database/init';

/*
  newOffer = {
    traveler_id,
    request_id
  }

  acceptedOffer = {
    requester_id,
    request_id
  }
*/
export default async function createNotif( notifTo, newOffer, acceptedOffer ){
  try{
    const notifType = !newOffer ? 'accepted_offer' : 'new_offer';
    await db.query(`
      INSERT INTO
        notifs(new_offer, accepted_offer, user_id, notif_type)
      VALUES($1,$2,$3,$4)
    `, [newOffer, acceptedOffer, notifTo, notifType]);
  
  }catch(err){
    throw new Error(err);
  }
}
