Skip to content

Instantly share code, notes, and snippets.

@qetr1ck-op
Created February 7, 2017 20:48
Show Gist options
  • Save qetr1ck-op/c8a48683201ecd21525d635aaf53e013 to your computer and use it in GitHub Desktop.
Save qetr1ck-op/c8a48683201ecd21525d635aaf53e013 to your computer and use it in GitHub Desktop.
export default class PromoCodeService {
constructor(Resource) {
this._resource = Resource;
}
create(eventId, promo) {
return this._resource.events(eventId).promoCodes().post(promo);
}
get(eventId, id) {
return this._resource.events(eventId).promoCodes(id).get().then(response => response.data);
}
getAll(eventId) {
return this._resource.events(eventId).promoCodes().get().then(response => response.data);
}
getAllActive(eventId) {
return this.getAll(eventId).then(data => {
if (Array.isArray(data.campaigns)) {
data.campaigns = data.campaigns.filter(x => x.isActive);
}
return data;
});
}
delete(eventId, id) {
return this._resource.events(eventId).promoCodes(id).delete();
}
update(eventId, promo) {
return this._resource.events(eventId).promoCodes(promo.id).put(promo);
}
patch(eventId, promo) {
return this._resource.events(eventId).promoCodes(promo.id).patch(promo);
}
static get $inject() {
return ['Resource'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment