@flumens/models 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("mobx"),r=require("axios"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("mobx"),r=require("axios"),s=require("@flumens/utils/dist/errors"),i=require("../Collection.js"),n=require("./Group.js"),o=require("./helpers.js");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(r),c=function(r){function i(s){var i=r.call(this,e.__assign({id:"groups",Model:n.default},s))||this;return i.remote=t.observable({synchronising:!1,url:s.url,getAccessToken:s.getAccessToken}),i}return e.__extends(i,r),i.prototype.fetchRemote=function(){return e.__awaiter(this,arguments,void 0,(function(t){var r,i,n,a,c,l,d,h,f,m,p,g,b,y,w,v,_=this;return void 0===t&&(t={}),e.__generator(this,(function(e){switch(e.label){case 0:console.log("📚 Collection: ".concat(this.id," collection fetching")),this.remote.synchronising=!0,e.label=1;case 1:return e.trys.push([1,6,,7]),r=t.type,i=t.form,n=t.location,[4,this.remote.getAccessToken()];case 2:return a=e.sent(),c="".concat(this.remote.url,"/index.php/services/rest/groups"),l={},r&&(l.view=r),i&&(l.page=i.join(",")),Number.isFinite(n)&&(l.indexed_location_ids=n),d={params:l,headers:{Authorization:"Bearer ".concat(a)},timeout:8e4},[4,u.default.get(c,d)];case 3:if(h=e.sent(),f=function(e){return!e.toDate||new Date(e.toDate)>new Date},m=function(e){return!e.fromDate||new Date(e.fromDate)<new Date},p=h.data.map((function(e){return e.values})).map(o.getCamelCaseObj).filter(f).filter(m),g=p.map((function(e){return _.Model.fromDTO(e,{skipStore:"member"!==r})})),r){if("member"===r)for(b=0;b<this.data.length;b++)(y=this.data[b]).isStored&&y.data.userIsMember&&(y.destroy(),this.data.splice(b,1),b--);else if("pending"===r)for(b=0;b<this.data.length;b++)(y=this.data[b]).isStored&&y.data.userIsPending&&(y.destroy(),this.data.splice(b,1),b--);else if("joinable"===r)for(b=0;b<this.data.length;b++)(y=this.data[b]).isStored||(this.data.splice(b,1),b--)}else for(b=0;b<this.data.length;b++)(y=this.data[b]).isStored&&y.destroy(),this.data.splice(b,1),b--;return"member"!==r?[3,5]:[4,Promise.all(g.map((function(e){return e.save()})))];case 4:e.sent(),e.label=5;case 5:return(v=this.data).push.apply(v,g),console.log("📚 Collection: ".concat(this.id," collection fetching done ").concat(p.length," documents")),[3,7];case 6:if(w=e.sent(),u.default.isCancel(w))return[2];if(s.isAxiosNetworkError(w))throw new s.HandledError("Request aborted because of a network issue (timeout or similar).");if("issues"in w)throw new Error(w.issues.map((function(e){return"".concat(e.path.join(" ")," ").concat(e.message)})).join(" "));throw this.remote.synchronising=!1,w;case 7:return this.remote.synchronising=!1,[2]}}))}))},Object.defineProperty(i.prototype,"isSynchronising",{get:function(){return this.remote.synchronising},enumerable:!1,configurable:!0}),i}(i.default);exports.byGroupMembershipStatus=function(e){return function(t){var r=t.data.userIsMember||t.data.userIsPending;return"member"===e?r:!r}},exports.default=c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("mobx"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("mobx"),n=require("lodash"),a=require("../Model.js"),i=require("./Media.js"),r=require("./helpers.js"),o=function(a){function o(n){void 0===n&&(n={});var r=this,s=n.metadata,d=void 0===s?{}:s,u=n.media,c=void 0===u?[]:u,l=n.Media,p=void 0===l?i.default:l,v=t.__rest(n,["metadata","media","Media"]);v.createdAt=v.createdAt||(null==d?void 0:d.createdOn),v.updatedAt=v.updatedAt||(null==d?void 0:d.updatedOn),v.syncedAt=v.syncedAt||(null==d?void 0:d.syncedOn),(r=a.call(this,v)||this).debouncedValue=300,r.keys=function(){var e;return t.__assign(t.__assign({},o.keys),(e=r.getSurvey().attrs||{},Object.keys(e).reduce((function(n,a){var i;return t.__assign(t.__assign({},n),((i={})[a]=e[a].remote||e[a],i))}),{})))},r.Media=p,r.metadata=e.observable(d);var m,f,_=c.map((m=r.Media,void 0===f&&(f={}),function(e){return e instanceof m?e:new m(t.__assign(t.__assign({},e),f))}));r.media=e.observable(_);var h=function(t){return t.parent=r};r.media.forEach(h);return e.intercept(r.media,(function(t){var e;return(null===(e=t.added)||void 0===e?void 0:e.length)?(t.added.forEach(h),r.setUpdatedAtTimestamp(Date.now())):t.removedCount&&r.setUpdatedAtTimestamp(Date.now()),t})),r}return t.__extends(o,a),o.fromElasticDTO=function(e,n,a){var i,o,s,d,u,c,l,p=e.id,v=e.metadata,m=e.event,f=e.occurrence,_=e.taxon,h=e.identification,y=new Date(v.created_on).getTime(),g=new Date(v.updated_on).getTime(),b=Date.now(),A=m.parent_event_id?null===(o=null===(i=a.smp)||void 0===i?void 0:i.occ)||void 0===o?void 0:o.attrs:null===(s=a.occ)||void 0===s?void 0:s.attrs;A||(A=(null===(u=null===(d=a.smp)||void 0===d?void 0:d.occ)||void 0===u?void 0:u.attrs)||(null===(c=a.occ)||void 0===c?void 0:c.attrs)||{});var w=r.parseRemoteAttrs(A,(null==f?void 0:f.attributes)||[]),O=(null===(l=null==f?void 0:f.media)||void 0===l?void 0:l.map((function(t){var e=t.path;return{id:e,createdAt:y,updatedAt:g,syncedAt:b,data:{data:"".concat(n,"/upload/").concat(e)}}})))||[],x=_.species||_.taxon_name,N=x!==_.taxon_name?_.taxon_name:"";return new this({id:p,cid:p,createdAt:y,updatedAt:g,syncedAt:b,metadata:{verification:h},data:t.__assign(t.__assign({},w),{taxon:{warehouse_id:parseInt(_.taxa_taxon_list_id,10),scientific_name:x,scientificName:x,common_name:N,commonName:N,found_in_name:N?"common_name":"scientific_name",foundInName:N?"commonName":"scientificName"},comment:null==f?void 0:f.occurrence_remarks}),media:O})},o.prototype.setUpdatedAtTimestamp=function(t){var e;a.prototype.setUpdatedAtTimestamp.call(this,t),null===(e=this.parent)||void 0===e||e.setUpdatedAtTimestamp(t)},o.prototype.save=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(t){if(!this.parent)throw new Error("Trying to save locally without a parent");return this.parent.save(),[2]}))}))},o.prototype.destroy=function(e){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(t){switch(t.label){case 0:if(!this.parent)throw new Error("Trying to destroy locally without a parent");return this.parent.occurrences.remove(this),[4,Promise.all(this.media.map((function(t){return t.destroy(!0)})))];case 1:return t.sent(),e?[2]:[4,this.parent.save()];case 2:return t.sent(),[2]}}))}))},o.prototype.sync=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(t){return[2,this.parent?this.parent.sync():a.prototype.sync.call(this)]}))}))},o.prototype.toJSON=function(){var n,i=a.prototype.toJSON.call(this);return JSON.parse(JSON.stringify(t.__assign(t.__assign({},i),{media:(null===(n=this.media)||void 0===n?void 0:n.map((function(t){return t.toJSON()})))||[],metadata:e.toJS(this.metadata)||{}})))},o.prototype.getSurvey=function(){return this.parent&&this.parent.getSurvey().occ||{}},Object.defineProperty(o.prototype,"isUploaded",{get:function(){if(!this.parent)throw new Error("No occurrence parent to return disabled status.");return this.parent.isUploaded},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"isDisabled",{get:function(){return this.isUploaded},enumerable:!1,configurable:!0}),o.prototype.toDTO=function(e){var a=this;void 0===e&&(e={});var i="function"==typeof this.keys?this.keys():this.keys,r=t.__assign(t.__assign({},o.keys),i),s={values:{external_key:this.cid},media:[]};this.id&&(s.values.id=this.id);Object.keys(this.data).forEach((function(t){var e=a.data[t],i=function(t){return null==t};if(!i(e)){if(!r[t])return t=t.includes("occAttr:")?t:n.snakeCase(t),void(s.values[t]=e);var o=r[t].id||t;if(e=function(t,e){var n=r[t].values;if(!n)return e;if("function"==typeof n)return n(e,s,a);if(n instanceof Array){var i=n.find((function(t){return t.value===e}));if(!i||!i.id)throw new Error('A "'.concat(t,'" attribute "').concat(e,'" value could not be mapped to a remote database field.'));return i.id}return e instanceof Array?e.map((function(t){return n[t]})):n[e]}(t,e),!i(e)){var d=Number.isNaN(Number(o))?o:"occAttr:".concat(o);d=d.includes("occAttr:")?d:n.snakeCase(d),s.values[d]=e}}})),this.media.forEach((function(t){var n=t.toDTO(e);n&&s.media.push(n)}));var d=this.getSurvey();return d.modifySubmission?d.modifySubmission(s,this):s},o.keys={taxon:{id:"taxa_taxon_list_id"}},o}(a.default);exports.default=o;
|