blixify-server 0.1.38 → 0.1.40

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
- {"version":3,"file":"fbWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/fbWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAEhB,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU;IAUjB,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCA4E5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA6CtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAqItC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA8EtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAwH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA4CtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBA4MlC;IAEF,IAAI,YA+EF;CACH"}
1
+ {"version":3,"file":"fbWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/fbWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAEhB,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU;IAUjB,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCA4E5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA6CtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAoItC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA6EtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAwH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA4CtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBA4MlC;IAEF,IAAI,YA+EF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,a,d,n){return new(d=d||Promise)(function(i,t){function s(e){try{r(n.next(e))}catch(e){t(e)}}function o(e){try{r(n.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,o)}r((n=n.apply(e,a||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirebaseWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel"),utils_1=require("./utils");class FirebaseWrapper{constructor(e,t,i,s,o,r){this.fbAdmin="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.parseModel=e=>(delete e.id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(c,l,u)=>__awaiter(this,void 0,void 0,function*(){try{const o=this.fbAdmin.firestore().batch(),r=this.fbAdmin.firestore().collection(this.collection);if(Array.isArray(c.body.data)){let t=!0;if(c.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=c.body.data,i=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const a=[],d=[];if(e.map(e=>{a.push(e.id),(0,QueryModel_1.checkOpsConfig)(this.config,"update",c,e)||(t=!1),c.body.unique&&null!=e&&e[c.body.unique]&&d.push(e[c.body.unique])}),i&&t){if(0<d.length){var s=yield r.find(c.body.unique,"in",d).get();const n=[];if(s.empty||s.forEach(e=>{e=e.data();n.push(e)}),0<n.length)return void l.status(400).json({err:`Unique:${n.map(e=>e[c.body.unique])} exists`})}u&&(yield u(e)),yield Promise.all(e.map(t=>__awaiter(this,void 0,void 0,function*(){t.baseUpdatedAt=(0,moment_1.default)().toDate();var e=r.doc(t.id);o.set(e,Object.assign({},t))}))),yield o.commit(),l.send({success:a})}else l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Model Structure"})}else l.status(400).json({err:"Invalid Fields"})}catch(e){l.status(400).json({err:e})}}),this.initCreate=(o,r,a)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(this.modelChecker(o.body.data)){var t=(0,QueryModel_1.checkBaseConfig)(this.config,o),i=(0,QueryModel_1.checkOpsConfig)(this.config,"create",o,o.body.data);if(t&&i){var s=this.fbAdmin.firestore().collection(this.collection);if(o.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),o.body.unique&&null!=(e=o.body.data)&&e[o.body.unique])if(!(yield s.where(o.body.unique,"==",o.body.data[o.body.unique]).get()).empty)return void r.status(400).json({err:`Unique:${o.body.data[o.body.unique]} exists`});a&&(yield a(o.body.data)),yield s.doc(o.body.data.id).set(o.body.data),r.send({success:!0})}else r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initGet=(r,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=r.body.id;o?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(o).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",r,t),i)&&s?a.send({data:t}):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initBatchUpdate=(b,m,p)=>__awaiter(this,void 0,void 0,function*(){var e,t;const s=this.fbAdmin.firestore().batch();try{var i=this.modelChecker(b.body.data)&&b.body.query,o=this.parseModel(null!=(e=b.body.data)?e:[]),r=null!=(t=b.body.query)?t:[],a=b.body.isOr||!1,d=b.body.unsetData;if(i){var n=this.fbAdmin.firestore().collection(this.collection);const h=[];r.forEach(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"=":h.push(this.fbAdmin.firestore.Filter.where(i,"==",s));break;case"!=":h.push(this.fbAdmin.firestore.Filter.where(i,"!=",s));break;case">":h.push(this.fbAdmin.firestore.Filter.where(i,">",s));break;case"<":h.push(this.fbAdmin.firestore.Filter.where(i,"<",s));break;case"><":Array.isArray(s)&&2<=s.length&&h.push(this.fbAdmin.firestore.Filter.where(i,">=",s[0]),this.fbAdmin.firestore.Filter.where(i,"<=",s[1]));break;case"in":h.push(this.fbAdmin.firestore.Filter.where(i,"in",s))}});var c=a?this.fbAdmin.firestore.Filter.or(...h):this.fbAdmin.firestore.Filter.and(...h),l=yield n.where(c).get(),u=(0,QueryModel_1.checkBaseConfig)(this.config,b);let i=!0;const f=[],y=[];if(l&&l.forEach(e=>{var t=e.data(),t=(y.push(t.id),!b.body.sensitive||(0,moment_1.default)(b.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))||m.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",b,t)||(i=!1),(0,utils_1.compareUpdatedFields)(e,b.body.data,"id"))["workflowUpdateFields"];f.concat(t)}),u&&i){let t={};d&&d.forEach(e=>{t[e]=this.fbAdmin.firestore.FieldValue.delete()}),o&&(t=Object.assign(Object.assign({},o),t)),p&&(yield p(f)),yield Promise.all(y.map(e=>{e=this.fbAdmin.firestore().collection(this.collection).doc(e);s.update(e,Object.assign({},t))})),yield s.commit(),m.send({success:y})}else m.status(400).json({err:"Invalid Security Configuration"})}}catch(e){m.status(400).json({err:e})}}),this.initUpdate=(u,h,f)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o,r,a,d,n,c,l=this.modelChecker(u.body.data)&&u.body.id;l?(t=yield(e=this.fbAdmin.firestore().collection(this.collection)).doc(l).get()).exists&&(i=t.data(),s=(0,QueryModel_1.checkBaseConfig)(this.config,u),o=(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,i),s)&&o?({workflowUpdateFields:a,updatedFields:d}=(u.body.unique&&null!=i&&i[u.body.unique]&&((r=yield e.where(u.body.unique,"==",u.body.data[u.body.unique]).get()).empty||r.forEach(e=>{e=e.data();u.body.id!==e.id&&h.status(400).json({err:u.body.data[u.body.unique]+" exists"})})),(0,utils_1.compareUpdatedFields)(i,u.body.data,"id")),u.body.sensitive?(0,moment_1.default)(u.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*i.baseUpdatedAt.seconds))?(f&&(yield f(a)),n=this.parseModel(d),yield e.doc(l).update(Object.assign({},n)),h.send({success:!0})):h.status(400).json({err:"Refresh Sensitive Model"}):(f&&(yield f(a)),c=this.parseModel(d),yield e.doc(l).update(Object.assign({},c)),h.send({success:!0}))):h.status(400).json({err:"Invalid Security Configuration"}):h.status(400).json({err:"Invalid Model Structure"})}catch(e){h.status(400).json({err:e})}}),this.initBatchDelete=(l,u,h)=>__awaiter(this,void 0,void 0,function*(){try{const d=this.fbAdmin.firestore().batch();if(Array.isArray(l.body.id)){var e=yield this.fbAdmin.firestore().collection(this.collection).where("id","in",l.body.id).get(),i=(0,QueryModel_1.checkBaseConfig)(this.config,l);let t=!0;const o=[];e&&e.forEach(e=>{e=e.data();o.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",l,e)||(t=!1)}),i&&t?(h&&(yield h(o)),yield Promise.all(l.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield this.fbAdmin.firestore().collection(this.collection).doc(t);d.delete(e)}))),yield d.commit(),u.send({success:l.body.id})):u.status(400).json({err:"Invalid Security Configuration"})}else{let o=this.fbAdmin.firestore().collection(this.collection);var s=l.body.query;const n=[];s&&0<s.length&&s.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(o=o.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":o=o.where(i,"==",s);break;case"!=":o=o.where(i,"!=",s);break;case">":o=o.where(i,">",s);break;case"<":o=o.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(o=o.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":o=o.where(i,"in",s)}});var r=yield o.get(),a=(0,QueryModel_1.checkBaseConfig)(this.config,l);let t=!0;const c=[];r&&r.forEach(e=>{e=e.data();n.push(e.id),c.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",l,e)||(t=!1)}),h&&(yield h(c)),a&&t?(r.forEach(e=>{d.delete(e.ref)}),yield d.commit(),u.send({success:n})):u.status(400).json({err:"Invalid Security Configuration"})}}catch(e){u.status(400).json({err:e})}}),this.initDelete=(r,a,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=r.body.id;o?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(o).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,t),i)&&s?(d&&(yield d(t)),yield this.fbAdmin.firestore().collection(this.collection).doc(o).delete(),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initList=(q,F)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,a;try{var d=(0,QueryModel_1.checkBaseConfig)(this.config,q);if(d){let o=this.fbAdmin.firestore().collection(this.collection);var n=q.body.aggregate,c=null!=(e=q.body.query)?e:[];let r="";if(c&&0<c.length&&c.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(r=e.searchIds[0],o=o.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":o=o.where(i,"==",s);break;case"!=":o=o.where(i,"!=",s);break;case">":o=o.where(i,">",s);break;case"<":o=o.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(o=o.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":o=o.where(i,"in",s)}}),n){const I=null!=(t=n.queryId)?t:"";var l=null!=(i=n.dateId)?i:"baseUpdatedAt",u=null!=(s=n.range)?s:[],h=[];for(const Y of u){var f=Y.split("-"),[y,b=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=f,m=2===f.length,p=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),g=(0,moment_1.default)(b,"DD/MM/YYYY").isValid(),v=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),_=(0,moment_1.default)(b,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!p||!g)return void F.status(400).json({err:"Invalid Aggregate Range Configuration"});var A=m?Y:"Begining until "+(0,moment_1.default)(y).format("DD/MM/YYYY");o=m?o.where(l,">=",(0,moment_1.default)(v).toDate()).where(l,"<=",(0,moment_1.default)(_).toDate()):o.where(l,"<",(0,moment_1.default)(v).toDate());let t=0;switch(n.type){case"count":var w=yield o.count().get();t=w.data().count;break;case"value":var M=yield(o=(o=o.limit(1)).orderBy(l,"desc")).get();M&&M.forEach(e=>{e=e.data(),e=JSON.parse(JSON.stringify(e));t=e[I]})}h.push({_id:A,value:t})}F.send({data:h})}else{if(q.body.stopLimit||(o=o.limit(null!=(a=q.body.limit)?a:10)),q.body.sort){var k=q.body.sort;if(r&&k.sortId!==r)return void F.status(400).json({err:"Invalid Search Sort Configuration"});r||(o=o.orderBy(k.sortId,"asc"===k.type?"asc":"desc"))}var C,j=yield(o=q.body.cursor?o.startAfter(q.body.cursor):o).get();let t=!0;const D=[];if(j&&j.forEach(e=>{e=e.data();D.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",q,e)||(t=!1)}),d&&t){let t="";if(D.length===q.body.limit){let e="id";q.body.sort&&(C=q.body.sort,e=C.sortId),t=D[q.body.limit-1][e]}F.send({data:D,count:t})}else F.status(400).json({err:"Invalid Security Configuration"})}}else F.status(400).json({err:"Invalid Security Configuration"})}catch(e){F.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.fbAdmin=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=r}}exports.FirebaseWrapper=FirebaseWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,a,d,n){return new(d=d||Promise)(function(i,t){function s(e){try{r(n.next(e))}catch(e){t(e)}}function o(e){try{r(n.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,o)}r((n=n.apply(e,a||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirebaseWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel"),utils_1=require("./utils");class FirebaseWrapper{constructor(e,t,i,s,o,r){this.fbAdmin="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.parseModel=e=>(delete e.id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(c,l,u)=>__awaiter(this,void 0,void 0,function*(){try{const o=this.fbAdmin.firestore().batch(),r=this.fbAdmin.firestore().collection(this.collection);if(Array.isArray(c.body.data)){let t=!0;if(c.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=c.body.data,i=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const a=[],d=[];if(e.map(e=>{a.push(e.id),(0,QueryModel_1.checkOpsConfig)(this.config,"update",c,e)||(t=!1),c.body.unique&&null!=e&&e[c.body.unique]&&d.push(e[c.body.unique])}),i&&t){if(0<d.length){var s=yield r.find(c.body.unique,"in",d).get();const n=[];if(s.empty||s.forEach(e=>{e=e.data();n.push(e)}),0<n.length)return void l.status(400).json({err:`Unique:${n.map(e=>e[c.body.unique])} exists`})}u&&(yield u(e)),yield Promise.all(e.map(t=>__awaiter(this,void 0,void 0,function*(){t.baseUpdatedAt=(0,moment_1.default)().toDate();var e=r.doc(t.id);o.set(e,Object.assign({},t))}))),yield o.commit(),l.send({success:a})}else l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Model Structure"})}else l.status(400).json({err:"Invalid Fields"})}catch(e){l.status(400).json({err:e})}}),this.initCreate=(o,r,a)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(this.modelChecker(o.body.data)){var t=(0,QueryModel_1.checkBaseConfig)(this.config,o),i=(0,QueryModel_1.checkOpsConfig)(this.config,"create",o,o.body.data);if(t&&i){var s=this.fbAdmin.firestore().collection(this.collection);if(o.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),o.body.unique&&null!=(e=o.body.data)&&e[o.body.unique])if(!(yield s.where(o.body.unique,"==",o.body.data[o.body.unique]).get()).empty)return void r.status(400).json({err:`Unique:${o.body.data[o.body.unique]} exists`});a&&(yield a(o.body.data)),yield s.doc(o.body.data.id).set(o.body.data),r.send({success:!0})}else r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initGet=(r,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=r.body.id;o?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(o).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",r,t),i)&&s?a.send({data:t}):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initBatchUpdate=(b,m,p)=>__awaiter(this,void 0,void 0,function*(){var e,t;const s=this.fbAdmin.firestore().batch();try{var i=this.modelChecker(b.body.data)&&b.body.query,o=this.parseModel(null!=(e=b.body.data)?e:[]),r=null!=(t=b.body.query)?t:[],a=b.body.isOr||!1,d=b.body.unsetData;if(i){var n=this.fbAdmin.firestore().collection(this.collection);const h=[];r.forEach(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"=":h.push(this.fbAdmin.firestore.Filter.where(i,"==",s));break;case"!=":h.push(this.fbAdmin.firestore.Filter.where(i,"!=",s));break;case">":h.push(this.fbAdmin.firestore.Filter.where(i,">",s));break;case"<":h.push(this.fbAdmin.firestore.Filter.where(i,"<",s));break;case"><":Array.isArray(s)&&2<=s.length&&h.push(this.fbAdmin.firestore.Filter.where(i,">=",s[0]),this.fbAdmin.firestore.Filter.where(i,"<=",s[1]));break;case"in":h.push(this.fbAdmin.firestore.Filter.where(i,"in",s))}});var c=a?this.fbAdmin.firestore.Filter.or(...h):this.fbAdmin.firestore.Filter.and(...h),l=yield n.where(c).get(),u=(0,QueryModel_1.checkBaseConfig)(this.config,b);let i=!0;const f=[],y=[];if(l&&l.forEach(e=>{var t=e.data(),t=(y.push(t.id),!b.body.sensitive||(0,moment_1.default)(b.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))||m.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",b,t)||(i=!1),(0,utils_1.compareUpdatedFields)(e,b.body.data))["workflowUpdateFields"];f.concat(t)}),u&&i){let t={};d&&d.forEach(e=>{t[e]=this.fbAdmin.firestore.FieldValue.delete()}),o&&(t=Object.assign(Object.assign({},o),t)),p&&(yield p(f)),yield Promise.all(y.map(e=>{e=this.fbAdmin.firestore().collection(this.collection).doc(e);s.update(e,Object.assign({},t))})),yield s.commit(),m.send({success:y})}else m.status(400).json({err:"Invalid Security Configuration"})}}catch(e){m.status(400).json({err:e})}}),this.initUpdate=(u,h,f)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o,r,a,d,n,c,l=this.modelChecker(u.body.data)&&u.body.id;l?(t=yield(e=this.fbAdmin.firestore().collection(this.collection)).doc(l).get()).exists&&(i=t.data(),s=(0,QueryModel_1.checkBaseConfig)(this.config,u),o=(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,i),s)&&o?({workflowUpdateFields:a,updatedFields:d}=(u.body.unique&&null!=i&&i[u.body.unique]&&((r=yield e.where(u.body.unique,"==",u.body.data[u.body.unique]).get()).empty||r.forEach(e=>{e=e.data();u.body.id!==e.id&&h.status(400).json({err:u.body.data[u.body.unique]+" exists"})})),(0,utils_1.compareUpdatedFields)(i,u.body.data)),u.body.sensitive?(0,moment_1.default)(u.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*i.baseUpdatedAt.seconds))?(f&&(yield f(a)),n=this.parseModel(d),yield e.doc(l).update(Object.assign({},n)),h.send({success:!0})):h.status(400).json({err:"Refresh Sensitive Model"}):(f&&(yield f(a)),c=this.parseModel(d),yield e.doc(l).update(Object.assign({},c)),h.send({success:!0}))):h.status(400).json({err:"Invalid Security Configuration"}):h.status(400).json({err:"Invalid Model Structure"})}catch(e){h.status(400).json({err:e})}}),this.initBatchDelete=(l,u,h)=>__awaiter(this,void 0,void 0,function*(){try{const d=this.fbAdmin.firestore().batch();if(Array.isArray(l.body.id)){var e=yield this.fbAdmin.firestore().collection(this.collection).where("id","in",l.body.id).get(),i=(0,QueryModel_1.checkBaseConfig)(this.config,l);let t=!0;const o=[];e&&e.forEach(e=>{e=e.data();o.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",l,e)||(t=!1)}),i&&t?(h&&(yield h(o)),yield Promise.all(l.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield this.fbAdmin.firestore().collection(this.collection).doc(t);d.delete(e)}))),yield d.commit(),u.send({success:l.body.id})):u.status(400).json({err:"Invalid Security Configuration"})}else{let o=this.fbAdmin.firestore().collection(this.collection);var s=l.body.query;const n=[];s&&0<s.length&&s.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(o=o.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":o=o.where(i,"==",s);break;case"!=":o=o.where(i,"!=",s);break;case">":o=o.where(i,">",s);break;case"<":o=o.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(o=o.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":o=o.where(i,"in",s)}});var r=yield o.get(),a=(0,QueryModel_1.checkBaseConfig)(this.config,l);let t=!0;const c=[];r&&r.forEach(e=>{e=e.data();n.push(e.id),c.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",l,e)||(t=!1)}),h&&(yield h(c)),a&&t?(r.forEach(e=>{d.delete(e.ref)}),yield d.commit(),u.send({success:n})):u.status(400).json({err:"Invalid Security Configuration"})}}catch(e){u.status(400).json({err:e})}}),this.initDelete=(r,a,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=r.body.id;o?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(o).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,t),i)&&s?(d&&(yield d(t)),yield this.fbAdmin.firestore().collection(this.collection).doc(o).delete(),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initList=(q,F)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,a;try{var d=(0,QueryModel_1.checkBaseConfig)(this.config,q);if(d){let o=this.fbAdmin.firestore().collection(this.collection);var n=q.body.aggregate,c=null!=(e=q.body.query)?e:[];let r="";if(c&&0<c.length&&c.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(r=e.searchIds[0],o=o.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":o=o.where(i,"==",s);break;case"!=":o=o.where(i,"!=",s);break;case">":o=o.where(i,">",s);break;case"<":o=o.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(o=o.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":o=o.where(i,"in",s)}}),n){const I=null!=(t=n.queryId)?t:"";var l=null!=(i=n.dateId)?i:"baseUpdatedAt",u=null!=(s=n.range)?s:[],h=[];for(const Y of u){var f=Y.split("-"),[y,b=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=f,m=2===f.length,p=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),g=(0,moment_1.default)(b,"DD/MM/YYYY").isValid(),v=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),_=(0,moment_1.default)(b,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!p||!g)return void F.status(400).json({err:"Invalid Aggregate Range Configuration"});var A=m?Y:"Begining until "+(0,moment_1.default)(y).format("DD/MM/YYYY");o=m?o.where(l,">=",(0,moment_1.default)(v).toDate()).where(l,"<=",(0,moment_1.default)(_).toDate()):o.where(l,"<",(0,moment_1.default)(v).toDate());let t=0;switch(n.type){case"count":var w=yield o.count().get();t=w.data().count;break;case"value":var M=yield(o=(o=o.limit(1)).orderBy(l,"desc")).get();M&&M.forEach(e=>{e=e.data(),e=JSON.parse(JSON.stringify(e));t=e[I]})}h.push({_id:A,value:t})}F.send({data:h})}else{if(q.body.stopLimit||(o=o.limit(null!=(a=q.body.limit)?a:10)),q.body.sort){var k=q.body.sort;if(r&&k.sortId!==r)return void F.status(400).json({err:"Invalid Search Sort Configuration"});r||(o=o.orderBy(k.sortId,"asc"===k.type?"asc":"desc"))}var C,j=yield(o=q.body.cursor?o.startAfter(q.body.cursor):o).get();let t=!0;const D=[];if(j&&j.forEach(e=>{e=e.data();D.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",q,e)||(t=!1)}),d&&t){let t="";if(D.length===q.body.limit){let e="id";q.body.sort&&(C=q.body.sort,e=C.sortId),t=D[q.body.limit-1][e]}F.send({data:D,count:t})}else F.status(400).json({err:"Invalid Security Configuration"})}}else F.status(400).json({err:"Invalid Security Configuration"})}catch(e){F.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.fbAdmin=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=r}}exports.FirebaseWrapper=FirebaseWrapper;
@@ -1 +1 @@
1
- {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,SAAM;IACb,KAAK,EAAE,GAAG,CAAC;IAEX,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI;IAa3D,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBAyE5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAgDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBAgCjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAkJtC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAwFtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBA6H5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAqCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBA2OlC;IAEF,IAAI,YA+EF;CACH"}
1
+ {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,SAAM;IACb,KAAK,EAAE,GAAG,CAAC;IAEX,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI;IAa3D,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBAyE5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAgDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBAgCjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAiJtC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAuFtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBA6H5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAqCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBA2OlC;IAEF,IAAI,YA+EF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,d){return new(r=r||Promise)(function(i,t){function s(e){try{a(d.next(e))}catch(e){t(e)}}function o(e){try{a(d.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,o)}a((d=d.apply(e,n||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=void 0;const moment_timezone_1=__importDefault(require("moment-timezone")),QueryModel_1=require("../model/QueryModel"),utils_1=require("./utils");class MongoWrapper{constructor(e,t,i,s,o,a,n,r){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.tableId="",this.modelChecker=e=>!1,this.parseModel=e=>(delete e._id,e.baseUpdatedAt=(0,moment_timezone_1.default)().toDate(),e),this.initBatchCreate=(u,c,h)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(Array.isArray(u.body.data)){let t=!0;u.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||c.status(400).json({err:"Invalid Model Structure"});var s=(0,QueryModel_1.checkBaseConfig)(this.config,u);let i=!0;const d=[];if(yield Promise.all(u.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,e)||(i=!1),u.body.unique&&null!=e&&e[u.body.unique]&&d.push(e[u.body.unique])})),s&&i){var o=this.mongoDB.db(this.tableId).collection(this.collection);if(0<d.length){var a=(yield o.find({[u.body.unique]:{$in:d}})).toArray();if(0<a.length)return void c.status(400).json({err:`Unique:${a.map(e=>e[u.body.unique])} exists`})}const l=[];var n=u.body.data.map(e=>(l.push(e._id),Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_timezone_1.default)().toDate()}))),r=(h&&(yield h(n)),yield o.insertMany(n),{success:l});if(null!=(e=u.body)&&e.stopRes)return r;c.send(r)}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initCreate=(n,r,d)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(n.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,n),s=(0,QueryModel_1.checkOpsConfig)(this.config,"create",n,n.body.data);if(i&&s){var o=this.mongoDB.db(this.tableId).collection(this.collection);if(n.body.data.baseUpdatedAt=(0,moment_timezone_1.default)().toDate(),n.body.unique&&null!=(e=n.body.data)&&e[n.body.unique])if(yield o.findOne({[n.body.unique]:n.body.data[n.body.unique]}))return void r.status(400).json({err:`Unique:${n.body.data[n.body.unique]} exists`});d&&(yield d(n.body.data)),yield o.insertOne(n.body.data);var a={success:!0};if(null!=(t=n.body)&&t.stopRes)return a;r.send(a)}else r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initGet=(n,r)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=n.body.id;if(t){var i,s=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:t}),o=(0,QueryModel_1.checkBaseConfig)(this.config,n),a=(0,QueryModel_1.checkOpsConfig)(this.config,"read",n,s);if(o&&a)return i={data:s},null!=(e=n.body)&&e.stopRes?i:void r.send(i);r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}}),this.initBatchUpdate=(p,m,v)=>__awaiter(this,void 0,void 0,function*(){var e,i,s;try{if(this.modelChecker(p.body.data)&&p.body.query){var o=p.body.unsetData,a=null!=(e=p.body.query)?e:[];const y=p.body.isOr?"$or":"$and",f={};var n=this.parseModel(null!=(i=p.body.data)?i:[]),r=(a&&0<a.length&&(f[y]=[],a.some(e=>"search"===e.type)&&(f.$or=[]),a.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&e.searchIds.map(e=>{f.$or.push({[e]:{$regex:s,$options:"i"}})});break;case"=":f[y].push({[i]:s});break;case"!=":f[y].push({[i]:{$ne:s}});break;case">":f[y].push({[i]:{$gt:s}});break;case"<":f[y].push({[i]:{$lt:s}});break;case"><":Array.isArray(s)&&2<=s.length&&(f[y].push({[i]:{$lt:s}}),f[y]={[i]:{$gte:s[0],$lte:s[1]}});break;case"in":f[y].push({[i]:{$in:s}})}})),(0,QueryModel_1.checkBaseConfig)(this.config,p));let t=!0;var d=this.mongoDB.db(this.tableId).collection(this.collection),l=yield(yield d.find(Object.assign({},f))).toArray();const b=[];if(yield Promise.all(l.map(e=>{p.body.sensitive&&!(0,moment_timezone_1.default)(p.body.data.baseUpdatedAt).isAfter((0,moment_timezone_1.default)(e.baseUpdatedAt))&&m.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",p,e)||(t=!1);e=(0,utils_1.compareUpdatedFields)(e,p.body.data,"_id").workflowUpdateFields;b.concat(e)})),r&&t){const g={};var u={},c=(o&&(o.forEach(e=>{g[e]=""}),u.$unset=Object.assign({},g)),n&&(u.$set=Object.assign({},n)),v&&(yield v(b)),yield d.updateMany(f,u),b.map(e=>e._id)),h={success:c};if(null!=(s=p.body)&&s.stopRes)return h;m.send(h)}else m.status(400).json({err:"Invalid Security Configuration"})}}catch(e){m.status(400).json({err:e})}}),this.initUpdate=(y,f,b)=>__awaiter(this,void 0,void 0,function*(){var e,t,i;try{var s=this.modelChecker(y.body.data)&&y.body.id;if(s){var o=this.mongoDB.db(this.tableId).collection(this.collection),a=yield o.findOne({_id:s}),n=(this.debug&&this.debug(y.body,a),(0,QueryModel_1.checkBaseConfig)(this.config,y)),r=(0,QueryModel_1.checkOpsConfig)(this.config,"update",y,a);if(n&&r){if(y.body.unique&&null!=(e=y.body.data)&&e[y.body.unique]){var d=yield o.findOne({[y.body.unique]:y.body.data[y.body.unique]});if(d&&y.body.id!==d._id)return void f.status(400).json({err:y.body.data[y.body.unique]+" exists"})}var{workflowUpdateFields:l,updatedFields:u}=(0,utils_1.compareUpdatedFields)(a,y.body.data,"_id"),c={success:!0},h=(b&&(yield b(l)),this.parseModel(u));if(y.body.sensitive)if((0,moment_timezone_1.default)(y.body.data.baseUpdatedAt).isAfter((0,moment_timezone_1.default)(a.baseUpdatedAt))){if(yield o.updateOne({_id:s},{$set:Object.assign({},h)}),null!=(t=y.body)&&t.stopRes)return c;f.send(c)}else f.status(400).json({err:"Refresh Sensitive Model"});else{if(yield o.updateOne({_id:s},{$set:Object.assign({},h)}),null!=(i=y.body)&&i.stopRes)return c;f.send(c)}}else f.status(400).json({err:"Invalid Security Configuration"})}else f.status(400).json({err:"Invalid Model Structure"})}catch(e){this.debug&&this.debug(null,null,e),f.status(400).json({err:e})}}),this.initBatchDelete=(b,g,p)=>__awaiter(this,void 0,void 0,function*(){var e,i;try{if(Array.isArray(b.body.id)){var s=this.mongoDB.db(this.tableId).collection(this.collection),o=yield s.find({_id:{$in:b.body.id}}),a=(0,QueryModel_1.checkBaseConfig)(this.config,b),n=yield o.toArray();let t=!0;if(0<n.length&&(yield Promise.all(n.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",b,e)||(t=!1)}))),a&&t){p&&(yield p(n)),yield s.deleteMany({_id:{$in:b.body.id}});var r={success:b.body.id};if(null!=(e=b.body)&&e.stopRes)return r;g.send(r)}else g.status(400).json({err:"Invalid Security Configuration"})}else{var d=b.body.query;const y={};d&&0<d.length&&d.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(y.$or=[],e.searchIds.map(e=>{y.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":y[i]=s;break;case"!=":y[i]={$ne:s};break;case">":y[i]={$gt:s};break;case"<":y[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(y[i]={$gte:s[0],$lte:s[1]});break;case"in":y[i]={$in:s}}});var l=this.mongoDB.db(this.tableId).collection(this.collection),u=yield l.find(y).toArray(),c=(0,QueryModel_1.checkBaseConfig)(this.config,b);let t=!0;const f=[];if(0<u.length&&u.map(e=>{f.push(e._id),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",b,e)||(t=!1)}),p&&(yield p(u)),c&&t){yield l.deleteMany(y);var h={success:f};if(null!=(i=b.body)&&i.stopRes)return h;g.send(h)}else g.status(400).json({err:"Invalid Security Configuration"})}}catch(e){g.status(400).json({err:e})}}),this.initDelete=(r,d,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=r.body.id;if(t){var i=this.mongoDB.db(this.tableId).collection(this.collection),s=yield i.findOne({_id:t}),o=(0,QueryModel_1.checkBaseConfig)(this.config,r),a=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,s);if(o&&a){l&&(yield l(s)),yield i.findOneAndDelete({_id:t});var n={success:!0};if(null!=(e=r.body)&&e.stopRes)return n;d.send(n)}else d.status(400).json({err:"Invalid Security Configuration"})}else d.status(400).json({err:"Invalid Fields"})}catch(e){d.status(400).json({err:e})}}),this.initList=(U,z)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,o,a,n,r,d;try{var l=(0,QueryModel_1.checkBaseConfig)(this.config,U);if(l){var u=U.body.aggregate,c=null!=(e=U.body.query)?e:[];const w={};if(c&&0<c.length&&c.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(w.$or=[],e.searchIds.map(e=>{w.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":w[i]=s;break;case"!=":w[i]={$ne:s};break;case">":w[i]={$gt:s};break;case"<":w[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(w[i]={$gte:s[0],$lte:s[1]});break;case"in":w[i]={$in:s}}}),u){var h=[],y=null!=(t=u.queryId)?t:"",f=null!=(i=u.dateId)?i:"baseUpdatedAt";for(const Q of null!=(s=u.range)?s:[]){Object.assign({},w);var b=Q.split("-"),[g,p=(0,moment_timezone_1.default)().format("DD/MM/YYYY HH:mm:ss")]=b,m=2===b.length,v=(0,moment_timezone_1.default)(g,"DD/MM/YYYY").isValid(),_=(0,moment_timezone_1.default)(p,"DD/MM/YYYY").isValid(),M=(0,moment_timezone_1.default)(g,"DD/MM/YYYY HH:mm:ss").tz("Asia/Kuala_lumpur").format("YYYY-MM-DD HH:mm:ss"),$=(0,moment_timezone_1.default)(p,"DD/MM/YYYY HH:mm:ss").tz("Asia/Kuala_lumpur").format("YYYY-MM-DD HH:mm:ss");if(!v||!_)return void z.status(400).json({err:"Invalid Aggregate Range Configuration"});var k=m?{$match:Object.assign(Object.assign({},w),{[f]:{$gte:new Date(M),$lte:new Date($)}})}:{$match:Object.assign(Object.assign({},w),{[f]:{$lte:new Date(M)}})},D=[];let e=!1;var I=m?Q:"Begining until "+(0,moment_timezone_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("DD/MM/YYYY");switch(u.type){case"avg":D.push(k,{$group:{_id:I,value:{$avg:"$"+y}}});break;case"sum":D.push(k,{$group:{_id:I,value:{$sum:"$"+y}}});break;case"count":e=!0}if(0===D.length&&!e)return void z.status(400).json({err:"Invalid Aggregate Configuration"});var j=this.mongoDB.db(this.tableId).collection(this.collection);let t=0;t=e?yield j.find(k.$match).count({}):null!=(a=null==(o=(yield j.aggregate(D).toArray())[0])?void 0:o.value)?a:0,h.push({_id:I,value:t})}var C={data:h};if(null!=(n=U.body)&&n.stopRes)return C;z.send(C)}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(w);var Y,O,A,q=yield e.count({}),B=(U.body.cursor&&(e=e.skip(U.body.cursor)),U.body.stopLimit||(e=e.limit(null!=(r=U.body.limit)?r:10)),U.body.sort&&(O={[(Y=U.body.sort).sortId]:"asc"===Y.type?1:-1},e=e.sort(O)),yield e.toArray());let t=!0;if(0<B.length&&B.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",U,e)||(t=!1)}),l&&t)return A={data:B,count:q},null!=(d=U.body)&&d.stopRes?A:void z.send(A);z.status(400).json({err:"Invalid Security Configuration"})}}else z.status(400).json({err:"Invalid Security Configuration"})}catch(e){z.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.mongoDB=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=a;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e,this.debug=r}}exports.MongoWrapper=MongoWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,d){return new(r=r||Promise)(function(i,t){function s(e){try{a(d.next(e))}catch(e){t(e)}}function o(e){try{a(d.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,o)}a((d=d.apply(e,n||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=void 0;const moment_timezone_1=__importDefault(require("moment-timezone")),QueryModel_1=require("../model/QueryModel"),utils_1=require("./utils");class MongoWrapper{constructor(e,t,i,s,o,a,n,r){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.tableId="",this.modelChecker=e=>!1,this.parseModel=e=>(delete e._id,e.baseUpdatedAt=(0,moment_timezone_1.default)().toDate(),e),this.initBatchCreate=(u,c,h)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(Array.isArray(u.body.data)){let t=!0;u.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||c.status(400).json({err:"Invalid Model Structure"});var s=(0,QueryModel_1.checkBaseConfig)(this.config,u);let i=!0;const d=[];if(yield Promise.all(u.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,e)||(i=!1),u.body.unique&&null!=e&&e[u.body.unique]&&d.push(e[u.body.unique])})),s&&i){var o=this.mongoDB.db(this.tableId).collection(this.collection);if(0<d.length){var a=(yield o.find({[u.body.unique]:{$in:d}})).toArray();if(0<a.length)return void c.status(400).json({err:`Unique:${a.map(e=>e[u.body.unique])} exists`})}const l=[];var n=u.body.data.map(e=>(l.push(e._id),Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_timezone_1.default)().toDate()}))),r=(h&&(yield h(n)),yield o.insertMany(n),{success:l});if(null!=(e=u.body)&&e.stopRes)return r;c.send(r)}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initCreate=(n,r,d)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(n.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,n),s=(0,QueryModel_1.checkOpsConfig)(this.config,"create",n,n.body.data);if(i&&s){var o=this.mongoDB.db(this.tableId).collection(this.collection);if(n.body.data.baseUpdatedAt=(0,moment_timezone_1.default)().toDate(),n.body.unique&&null!=(e=n.body.data)&&e[n.body.unique])if(yield o.findOne({[n.body.unique]:n.body.data[n.body.unique]}))return void r.status(400).json({err:`Unique:${n.body.data[n.body.unique]} exists`});d&&(yield d(n.body.data)),yield o.insertOne(n.body.data);var a={success:!0};if(null!=(t=n.body)&&t.stopRes)return a;r.send(a)}else r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initGet=(n,r)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=n.body.id;if(t){var i,s=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:t}),o=(0,QueryModel_1.checkBaseConfig)(this.config,n),a=(0,QueryModel_1.checkOpsConfig)(this.config,"read",n,s);if(o&&a)return i={data:s},null!=(e=n.body)&&e.stopRes?i:void r.send(i);r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}}),this.initBatchUpdate=(p,m,v)=>__awaiter(this,void 0,void 0,function*(){var e,i,s;try{if(this.modelChecker(p.body.data)&&p.body.query){var o=p.body.unsetData,a=null!=(e=p.body.query)?e:[];const y=p.body.isOr?"$or":"$and",b={};var n=this.parseModel(null!=(i=p.body.data)?i:[]),r=(a&&0<a.length&&(b[y]=[],a.some(e=>"search"===e.type)&&(b.$or=[]),a.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&e.searchIds.map(e=>{b.$or.push({[e]:{$regex:s,$options:"i"}})});break;case"=":b[y].push({[i]:s});break;case"!=":b[y].push({[i]:{$ne:s}});break;case">":b[y].push({[i]:{$gt:s}});break;case"<":b[y].push({[i]:{$lt:s}});break;case"><":Array.isArray(s)&&2<=s.length&&(b[y].push({[i]:{$lt:s}}),b[y]={[i]:{$gte:s[0],$lte:s[1]}});break;case"in":b[y].push({[i]:{$in:s}})}})),(0,QueryModel_1.checkBaseConfig)(this.config,p));let t=!0;var d=this.mongoDB.db(this.tableId).collection(this.collection),l=yield(yield d.find(Object.assign({},b))).toArray();const f=[];if(yield Promise.all(l.map(e=>{p.body.sensitive&&!(0,moment_timezone_1.default)(p.body.data.baseUpdatedAt).isAfter((0,moment_timezone_1.default)(e.baseUpdatedAt))&&m.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",p,e)||(t=!1);e=(0,utils_1.compareUpdatedFields)(e,p.body.data).workflowUpdateFields;f.concat(e)})),r&&t){const g={};var u={},c=(o&&(o.forEach(e=>{g[e]=""}),u.$unset=Object.assign({},g)),n&&(u.$set=Object.assign({},n)),v&&(yield v(f)),yield d.updateMany(b,u),f.map(e=>e._id)),h={success:c};if(null!=(s=p.body)&&s.stopRes)return h;m.send(h)}else m.status(400).json({err:"Invalid Security Configuration"})}}catch(e){m.status(400).json({err:e})}}),this.initUpdate=(y,b,f)=>__awaiter(this,void 0,void 0,function*(){var e,t,i;try{var s=this.modelChecker(y.body.data)&&y.body.id;if(s){var o=this.mongoDB.db(this.tableId).collection(this.collection),a=yield o.findOne({_id:s}),n=(this.debug&&this.debug(y.body,a),(0,QueryModel_1.checkBaseConfig)(this.config,y)),r=(0,QueryModel_1.checkOpsConfig)(this.config,"update",y,a);if(n&&r){if(y.body.unique&&null!=(e=y.body.data)&&e[y.body.unique]){var d=yield o.findOne({[y.body.unique]:y.body.data[y.body.unique]});if(d&&y.body.id!==d._id)return void b.status(400).json({err:y.body.data[y.body.unique]+" exists"})}var{workflowUpdateFields:l,updatedFields:u}=(0,utils_1.compareUpdatedFields)(a,y.body.data),c={success:!0},h=(f&&(yield f(l)),this.parseModel(u));if(y.body.sensitive)if((0,moment_timezone_1.default)(y.body.data.baseUpdatedAt).isAfter((0,moment_timezone_1.default)(a.baseUpdatedAt))){if(yield o.updateOne({_id:s},{$set:Object.assign({},h)}),null!=(t=y.body)&&t.stopRes)return c;b.send(c)}else b.status(400).json({err:"Refresh Sensitive Model"});else{if(yield o.updateOne({_id:s},{$set:Object.assign({},h)}),null!=(i=y.body)&&i.stopRes)return c;b.send(c)}}else b.status(400).json({err:"Invalid Security Configuration"})}else b.status(400).json({err:"Invalid Model Structure"})}catch(e){this.debug&&this.debug(null,null,e),b.status(400).json({err:e})}}),this.initBatchDelete=(f,g,p)=>__awaiter(this,void 0,void 0,function*(){var e,i;try{if(Array.isArray(f.body.id)){var s=this.mongoDB.db(this.tableId).collection(this.collection),o=yield s.find({_id:{$in:f.body.id}}),a=(0,QueryModel_1.checkBaseConfig)(this.config,f),n=yield o.toArray();let t=!0;if(0<n.length&&(yield Promise.all(n.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",f,e)||(t=!1)}))),a&&t){p&&(yield p(n)),yield s.deleteMany({_id:{$in:f.body.id}});var r={success:f.body.id};if(null!=(e=f.body)&&e.stopRes)return r;g.send(r)}else g.status(400).json({err:"Invalid Security Configuration"})}else{var d=f.body.query;const y={};d&&0<d.length&&d.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(y.$or=[],e.searchIds.map(e=>{y.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":y[i]=s;break;case"!=":y[i]={$ne:s};break;case">":y[i]={$gt:s};break;case"<":y[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(y[i]={$gte:s[0],$lte:s[1]});break;case"in":y[i]={$in:s}}});var l=this.mongoDB.db(this.tableId).collection(this.collection),u=yield l.find(y).toArray(),c=(0,QueryModel_1.checkBaseConfig)(this.config,f);let t=!0;const b=[];if(0<u.length&&u.map(e=>{b.push(e._id),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",f,e)||(t=!1)}),p&&(yield p(u)),c&&t){yield l.deleteMany(y);var h={success:b};if(null!=(i=f.body)&&i.stopRes)return h;g.send(h)}else g.status(400).json({err:"Invalid Security Configuration"})}}catch(e){g.status(400).json({err:e})}}),this.initDelete=(r,d,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=r.body.id;if(t){var i=this.mongoDB.db(this.tableId).collection(this.collection),s=yield i.findOne({_id:t}),o=(0,QueryModel_1.checkBaseConfig)(this.config,r),a=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,s);if(o&&a){l&&(yield l(s)),yield i.findOneAndDelete({_id:t});var n={success:!0};if(null!=(e=r.body)&&e.stopRes)return n;d.send(n)}else d.status(400).json({err:"Invalid Security Configuration"})}else d.status(400).json({err:"Invalid Fields"})}catch(e){d.status(400).json({err:e})}}),this.initList=(U,z)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,o,a,n,r,d;try{var l=(0,QueryModel_1.checkBaseConfig)(this.config,U);if(l){var u=U.body.aggregate,c=null!=(e=U.body.query)?e:[];const w={};if(c&&0<c.length&&c.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(w.$or=[],e.searchIds.map(e=>{w.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":w[i]=s;break;case"!=":w[i]={$ne:s};break;case">":w[i]={$gt:s};break;case"<":w[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(w[i]={$gte:s[0],$lte:s[1]});break;case"in":w[i]={$in:s}}}),u){var h=[],y=null!=(t=u.queryId)?t:"",b=null!=(i=u.dateId)?i:"baseUpdatedAt";for(const Q of null!=(s=u.range)?s:[]){Object.assign({},w);var f=Q.split("-"),[g,p=(0,moment_timezone_1.default)().format("DD/MM/YYYY HH:mm:ss")]=f,m=2===f.length,v=(0,moment_timezone_1.default)(g,"DD/MM/YYYY").isValid(),_=(0,moment_timezone_1.default)(p,"DD/MM/YYYY").isValid(),$=(0,moment_timezone_1.default)(g,"DD/MM/YYYY HH:mm:ss").tz("Asia/Kuala_lumpur").toDate(),M=(0,moment_timezone_1.default)(p,"DD/MM/YYYY HH:mm:ss").tz("Asia/Kuala_lumpur").toDate();if(!v||!_)return void z.status(400).json({err:"Invalid Aggregate Range Configuration"});var k=m?{$match:Object.assign(Object.assign({},w),{[b]:{$gte:$,$lte:M}})}:{$match:Object.assign(Object.assign({},w),{[b]:{$lte:$}})},I=[];let e=!1;var j=m?Q:"Begining until "+(0,moment_timezone_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("DD/MM/YYYY");switch(u.type){case"avg":I.push(k,{$group:{_id:j,value:{$avg:"$"+y}}});break;case"sum":I.push(k,{$group:{_id:j,value:{$sum:"$"+y}}});break;case"count":e=!0}if(0===I.length&&!e)return void z.status(400).json({err:"Invalid Aggregate Configuration"});var C=this.mongoDB.db(this.tableId).collection(this.collection);let t=0;t=e?yield C.find(k.$match).count({}):null!=(a=null==(o=(yield C.aggregate(I).toArray())[0])?void 0:o.value)?a:0,h.push({_id:j,value:t})}var D={data:h};if(null!=(n=U.body)&&n.stopRes)return D;z.send(D)}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(w);var O,A,q,B=yield e.count({}),Y=(U.body.cursor&&(e=e.skip(U.body.cursor)),U.body.stopLimit||(e=e.limit(null!=(r=U.body.limit)?r:10)),U.body.sort&&(A={[(O=U.body.sort).sortId]:"asc"===O.type?1:-1},e=e.sort(A)),yield e.toArray());let t=!0;if(0<Y.length&&Y.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",U,e)||(t=!1)}),l&&t)return q={data:Y,count:B},null!=(d=U.body)&&d.stopRes?q:void z.send(q);z.status(400).json({err:"Invalid Security Configuration"})}}else z.status(400).json({err:"Invalid Security Configuration"})}catch(e){z.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.mongoDB=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=a;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e,this.debug=r}}exports.MongoWrapper=MongoWrapper;
@@ -1,4 +1,4 @@
1
- export declare const compareUpdatedFields: (prevData: any, currentData: any, idPrefix: string) => {
1
+ export declare const compareUpdatedFields: (prevData: any, currentData: any) => {
2
2
  workflowUpdateFields: {
3
3
  [x: string]: any;
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/apis/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,aACrB,GAAG,eACA,GAAG,YACN,MAAM;;;;;;;CAejB,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/apis/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,aAAc,GAAG,eAAe,GAAG;;;;;;;CAkBnE,CAAC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compareUpdatedFields=void 0;const compareUpdatedFields=(d,s,e)=>{const t={};return Object.keys(s).forEach(e=>{s[e]!==d[e]&&(t[e]=s[e])}),{workflowUpdateFields:Object.assign(Object.assign({},t),{[e]:d[e]}),updatedFields:t}};exports.compareUpdatedFields=compareUpdatedFields;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compareUpdatedFields=void 0;const uuid_1=require("uuid"),compareUpdatedFields=(d,t)=>{const s={};return Object.keys(t).forEach(e=>{t[e]!==d[e]&&(s[e]=t[e])}),Object.keys(d).forEach(e=>{d[e]&&(0,uuid_1.validate)(d[e])&&(s[e]=d[e])}),{workflowUpdateFields:Object.assign({},s),updatedFields:s}};exports.compareUpdatedFields=compareUpdatedFields;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,
@@ -35,10 +35,12 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
+ "@types/uuid": "^9.0.7",
38
39
  "axios": "^1.4.0",
39
40
  "mime": "^3.0.0",
40
41
  "moment": "^2.29.4",
41
- "moment-timezone": "^0.5.43"
42
+ "moment-timezone": "^0.5.43",
43
+ "uuid": "^9.0.1"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@types/express": "^4.17.14",