import { API_FOOD, API_FOOD_SCALE, API_FOOD_TAGS } from './http/api';
import { request } from './http/request';

export const getFoodTags = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_FOOD_TAGS, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const getFoodScales = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_FOOD_SCALE, method: 'GET', data: {...params}
        }).then(res => {
            resolve(res);
        }).catch(e => {
            reject(e)
        })
    })
}
export const getFoodJournals = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_FOOD, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
        }).catch(e => {
            reject(e)
        })
    })
}

export const createFoodJournal = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_FOOD, method: 'POST', data: { ...params }
        }).then(res => {
            resolve(res);
        }).catch(e => {
            reject(e)
        })
    })
}

export const editFoodJournal = (params, id) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_FOOD + `/${id}`, method: 'POST', data: { ...params }
        }).then(res => {
            resolve(res);
        }).catch(e => {
            reject(e)
        })
    })
}

export const delFoodJournal = (id) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_FOOD + `/${id}`, method: 'DELETE', data: {}
        }).then(res => {
            resolve(res);
        }).catch(e => {
            reject(e)
        })
    })
}