Skip to content

Instantly share code, notes, and snippets.

@gusgard
Created August 22, 2017 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gusgard/4903800c5b35526a7c97259bf0e5f3d4 to your computer and use it in GitHub Desktop.
Save gusgard/4903800c5b35526a7c97259bf0e5f3d4 to your computer and use it in GitHub Desktop.
Event facade
import { HttpService } from 'App/src/common';
import Event from './Event';
class EventFacade {
static async create(payload) {
const event = Event.encode(payload);
const { data: { data } } = await HttpService.post('/events', event);
return Event.create(data);
}
static async fetchHosted() {
const { data: { data } } = await HttpService.get('/events');
return data.map(e => Event.create(e));
}
static async fetchInvited() {
const { data: { data } } = await HttpService.get('/events/invites');
return data.map(e => Event.create(e));
}
static async fetchOne(id) {
const { data: { data } } = await HttpService.get(`/events/${id}`);
return Event.create(data);
}
static async update(event) {
await HttpService.post(`/events/${event.id}`, event);
}
static async delete(id) {
await HttpService.delete(`/events/${id}`);
}
}
export default EventFacade;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment