Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import { Connect, mix } from 'fronto-connect';
  2. import scopes from './scopes';
  3. import { action, computed } from 'mobx';
  4.  
  5. class Experience extends Connect {
  6. namespace = 'v1';
  7. resource = 'experiences';
  8.  
  9. @computed get selecte(){
  10. return this.selected;
  11. }
  12.  
  13. @action load(query = {}, callback = {}) {
  14. const path = `${this.api.endpoint}${this.namespace}/${this.resource}`;
  15. this.get(path, query, callback);
  16. }
  17.  
  18. @action loadPhotos(id, callback = {}) {
  19. const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${id}/photos`;
  20. this.get(path, {}, callback);
  21. }
  22.  
  23. /*
  24. * @param {callback} callback
  25. * Defines callback based on response status
  26. * Pass objects with status id as object name arrow functions to be executed after the fetch
  27. * You can use 'default' to execute some code if the response has a unhandled status
  28. */
  29. // @action new(callback = {}, body = {}, id = null){
  30. // const path = `${this.api.endpoint}${this.namespace}/${this.resource}/`;
  31. // path += id || '';
  32. // console.log(path);
  33. // }
  34.  
  35. @action uploadPhotos(id, body = [], callback = {}){
  36. const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${id}/photos`;
  37. var data = new FormData();
  38. for(let i = 0;i < body.length;i++){
  39. console.log(body[i]);
  40. data.append('images[]', body[i]);
  41. }
  42. this.post(path, data, callback, true);
  43. }
  44.  
  45. @action setCoverPhoto(experienceId, photoId, callback = {}){
  46. const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${experienceId}/photos/${photoId}/set_cover`;
  47. this.post(path, {}, callback);
  48. }
  49.  
  50. @action deletePhoto(experienceId, photoId, callback = {}){
  51. const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${experienceId}/photos/${photoId}`;
  52. this.delete(path,callback);
  53. }
  54.  
  55. @action edit(id, body = {}, callback = {}) {
  56. const path = `${this.api.endpoint}${this.namespace}/${this.resource}/${id}`;
  57. this.put(path, body, callback);
  58. }
  59. }
  60.  
  61. mix(Experience, scopes.readable);
  62. mix(Experience, scopes.writable);
  63. mix(Experience, scopes.api);
  64.  
  65. export default Experience;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement