@flumens/models 0.18.0 → 0.19.0
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.
|
@@ -77,7 +77,7 @@ export declare enum LocationType {
|
|
|
77
77
|
MothTrap = "18879",
|
|
78
78
|
Transect = "777",
|
|
79
79
|
TransectSection = "778",
|
|
80
|
-
|
|
80
|
+
Site = "14"
|
|
81
81
|
}
|
|
82
82
|
export type DTO = z.infer<typeof dtoSchema>;
|
|
83
83
|
export type Data = Omit<DTO, 'createdOn' | 'updatedOn'> & ModelData;
|
package/dist/Indicia/Location.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("mobx"),i=require("axios"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("mobx"),i=require("axios"),n=require("lodash"),o=require("zod"),s=require("@flumens/utils/dist/uuid"),r=require("../Model.js");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=a(i);const l=o.object({lat:o.z.string().min(1),lon:o.z.string().min(1),name:o.z.string().min(1),locationTypeId:o.z.string().min(1),centroidSref:o.z.string().min(1),centroidSrefSystem:o.z.string().min(1),id:o.z.string().optional(),createdOn:o.z.string().optional(),updatedOn:o.z.string().optional(),parentId:o.z.string().nullable().optional(),boundaryGeom:o.z.string().nullable().optional(),code:o.z.string().nullable().optional(),createdById:o.z.string().nullable().optional(),updatedById:o.z.string().nullable().optional(),externalKey:o.z.string().nullable().optional(),centroidGeom:o.z.string().nullable().optional(),public:o.z.string().nullable().optional(),comment:o.z.string().nullable().optional()});var u;exports.LocationType=void 0,(u=exports.LocationType||(exports.LocationType={})).MothTrap="18879",u.Transect="777",u.TransectSection="778",u.Site="14";class c extends r.default{static fromDTO(t,i={}){l.parse(t);const{id:n,createdOn:o,updatedOn:r,externalKey:a}=t,d=e.__rest(t,["id","createdOn","updatedOn","externalKey"]);return new this(Object.assign({cid:a||s.UUIDv7(),id:n,createdAt:new Date(o).getTime(),updatedAt:new Date(r).getTime(),data:d},i))}constructor(i){var{skipStore:n,store:o,media:s=[],metadata:r={},url:a,getAccessToken:d}=i,l=e.__rest(i,["skipStore","store","media","metadata","url","getAccessToken"]);super(Object.assign(Object.assign({},l),{store:n?void 0:o})),this.metadata=t.observable(r),this.media=t.observable(s),this.remote=t.observable({synchronising:!1,url:a,getAccessToken:d})}saveRemote(){return e.__awaiter(this,void 0,void 0,(function*(){var e,t,i,n,o;try{this.remote.synchronising=!0;const e=yield this.uploadMedia(),t=this.toDTO(e),i=`${this.remote.url}/index.php/services/rest/locations`,n={url:i,method:"post",headers:{Authorization:`Bearer ${yield this.remote.getAccessToken()}`},timeout:8e4,data:t},{data:o}=yield d.default(n),s=new Date(o.values.updated_on).getTime();return this.updatedAt=s,this.syncedAt=s,this.id=o.values.id,this.remote.synchronising=!1,this.store&&this.save(),console.log("Location uploading done"),this}catch(s){this.remote.synchronising=!1;const r=s;if(409===(null===(e=r.response)||void 0===e?void 0:e.status)&&(null===(t=r.response)||void 0===t?void 0:t.data.duplicate_of)){console.log("Location uploading duplicate was found");const e=(new Date).getTime();return this.updatedAt=e,this.syncedAt=e,this.id=null===(i=r.response)||void 0===i?void 0:i.data.duplicate_of.id,this}const a=null===(o=null===(n=r.response)||void 0===n?void 0:n.data)||void 0===o?void 0:o.message;if(!a)throw s;if("object"==typeof a){throw new Error((e=>Object.entries(e).reduce(((e,t)=>`${e}${t[0]} ${t[1]}\n`),""))(a))}throw new Error(a)}}))}toDTO(e={}){const t=(i=this.data,Object.entries(i).reduce(((e,[t,i])=>(e[t.includes("locAttr:")?t:n.snakeCase(t)]=i,e)),{}));var i;const o={values:Object.assign({external_key:this.cid},t),media:[]};return this.media.forEach((t=>{const i=t.toDTO(e);i&&o.media.push(i)})),o}uploadMedia(){return e.__awaiter(this,void 0,void 0,(function*(){yield Promise.all(this.media.map((e=>e.uploadFile())));const e={};return this.media.forEach((t=>{e[t.cid]={name:t.data.queued}})),e}))}get isUploaded(){return!!this.id||!!this.syncedAt}get isSynchronising(){return this.remote.synchronising}get isDraft(){return!this.id}}exports.default=c,exports.dtoSchema=l;
|