Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Connect, mix } from 'fronto-connect';
- import scopes from './scopes';
- import { action, computed } from 'mobx';
- class Experience extends Connect {
- namespace = 'v1';
- resource = 'experiences';
- @computed get selecte(){
- return this.selected;
- }
- @action load(query = {}, callback = {}) {
- const path = `${this.api.endpoint}${this.namespace}/${this.resource}`;
- this.get(path, query, callback);
- }
- @action loadPhotos(id, callback = {}) {
- const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${id}/photos`;
- this.get(path, {}, callback);
- }
- /*
- * @param {callback} callback
- * Defines callback based on response status
- * Pass objects with status id as object name arrow functions to be executed after the fetch
- * You can use 'default' to execute some code if the response has a unhandled status
- */
- // @action new(callback = {}, body = {}, id = null){
- // const path = `${this.api.endpoint}${this.namespace}/${this.resource}/`;
- // path += id || '';
- // console.log(path);
- // }
- @action uploadPhotos(id, body = [], callback = {}){
- const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${id}/photos`;
- var data = new FormData();
- for(let i = 0;i < body.length;i++){
- console.log(body[i]);
- data.append('images[]', body[i]);
- }
- this.post(path, data, callback, true);
- }
- @action setCoverPhoto(experienceId, photoId, callback = {}){
- const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${experienceId}/photos/${photoId}/set_cover`;
- this.post(path, {}, callback);
- }
- @action deletePhoto(experienceId, photoId, callback = {}){
- const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${experienceId}/photos/${photoId}`;
- this.delete(path,callback);
- }
- @action edit(id, body = {}, callback = {}) {
- const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${id}`;
- this.put(path, body, callback);
- }
- }
- mix(Experience, scopes.readable);
- mix(Experience, scopes.writable);
- mix(Experience, scopes.api);
- export default Experience;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement