{"size": 2794, "ext": "js", "max_stars_repo_path": "webapp/src/services/offer/offer.service.js", "max_stars_repo_name": "cclauss/Baobab", "max_stars_repo_stars_event_min_datetime": "2019-01-10T16:04:26.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-10T00:55:59.000Z", "max_issues_repo_path": "webapp/src/services/offer/offer.service.js", "max_issues_repo_name": "cclauss/Baobab", "max_issues_repo_issues_event_min_datetime": "2019-01-08T21:24:01.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T15:24:06.000Z", "max_forks_repo_path": "webapp/src/services/offer/offer.service.js", "max_forks_repo_name": "cclauss/Baobab", "max_forks_repo_forks_event_min_datetime": "2019-01-10T16:09:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-28T21:02:47.000Z"}
{"max_stars_count": 52, "max_issues_count": 535, "max_forks_count": 36, "avg_line_length": 29.4105263158, "max_line_length": 163, "alphanum_fraction": 0.5794559771}
import axios from "axios";
import {authHeader} from '../base.service';

const baseUrl = process.env.REACT_APP_API_URL;

export const offerServices = {
    getOffer,
    addOffer,
    updateOffer
}

function getOffer(event_id){
    return axios.get(baseUrl + "/api/v1/offer?event_id=" +event_id,{
        headers: authHeader()
      })
      .then(function(response){
        return{
            offer: response.data,
            error:"",
            statusCode: response.status
        };
      })
      .catch(function(error){
          return{
            offer:null,
            error:
              error.response && error.response.data
              ? error.response.data.message
              : error.message,
            statusCode: error.response && error.response.status
          };
      });

}

function addOffer(user_id, event_id,offer_date,expiry_date,payment_required,travel_award,accommodation_award, accepted_accommodation_award, accepted_travel_award){
    let data = {
        user_id:user_id, 
        event_id:event_id,
        offer_date:offer_date,
        expiry_date:expiry_date,
        payment_required:payment_required,
        travel_award:travel_award,
        accommodation_award:accommodation_award,
        accepted_accommodation_award:accepted_accommodation_award,
        accepted_travel_award: accepted_travel_award
    }

    return axios
        .post(baseUrl + 'api/v1/offer',data,{headers:authHeader()})
        .then(function (response){
            return{
                message:"succeeded",
                response: response
            }
        })
        .catch(function(error) {
            return {
              message: null,
              error:
                error.response && error.response.data
                  ? error.response.data.message
                  : error.message
            };
          });
}

function updateOffer(offer_id, event_id, candidate_response, rejected_reason, accepted_accommodation_award, accepted_travel_award){
    let data = {
        offer_id:offer_id, 
        event_id:event_id,
        candidate_response:candidate_response,
        rejected_reason:rejected_reason,
        accepted_travel_award:accepted_travel_award,
        accepted_accommodation_award:accepted_accommodation_award
    };

    return axios
        .put(baseUrl + "/api/v1/offer", data,{ headers: authHeader() })
        .then(function(response){
            return{
                message:"succeeded",
                response:response
            }
        }).catch(function(error) {
            return {
              message: null,
              error:
                error.response && error.response.data
                  ? error.response.data.message
                  : error.message
            };
          });     
}
