1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| import { normalize } from 'normalizr';
import { request, address } from '../service/'; import * as state from './store';
const get = (config, schema, name) => request(config) .then(resp => { const schemaData = normalize(resp, schema) const { count, previous, next } = schemaData.result Object.assign(schemaData.entities[name], { count, previous, next }) return schemaData });
const base = config => request(config).then(resp => resp);
export const list = config => base(config);
export const create = config => base( Object.assign({}, { method: 'POST', }, config) );
export const update = config => base( Object.assign({}, { method: 'PATCH', }, config) );
export const del = config => base( Object.assign({}, { method: 'DELETE', isJson: false, }, config) )
export const getAds = () => get({ url: address.ads, hasCert: false, }, { results: [state.adSchema] }, 'ads');
export const updateAds = payload => update({ url: `${address.ads}${payload.id}/`, body: JSON.stringify(payload), hasCert: false, })
export const createAds = payload => create({ url: address.ads, body: JSON.stringify(payload), hasCert: false, })
export const delAds = payload => del({ url: `${address.ads}${payload.id}/`, hasCert: false, })
|