blixify-server 0.1.21 → 0.1.22

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;AAE5C;;;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,gCAkD5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAiCtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAoEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA0DpC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAsH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA4CtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBA+MlC;IAEF,IAAI,YA0DF;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;AAE5C;;;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,gCAkD5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAiCtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAoEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA0DpC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAsH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA4CtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBA+MlC;IAEF,IAAI,YAyEF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,r,d,n){return new(d=d||Promise)(function(i,t){function s(e){try{a(n.next(e))}catch(e){t(e)}}function o(e){try{a(n.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,o)}a((n=n.apply(e,r||[])).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");class FirebaseWrapper{constructor(e,t,i,s,o,a){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=(o,a,r)=>__awaiter(this,void 0,void 0,function*(){try{const s=this.fbAdmin.firestore().batch();if(Array.isArray(o.body.data)){let t=!0;if(o.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=o.body.data,i=(0,QueryModel_1.checkBaseConfig)(this.config,o);let t=!0;e.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",o,e)||(t=!1)}),i&&t?(r&&(yield r(e)),yield Promise.all(e.map(t=>__awaiter(this,void 0,void 0,function*(){t.baseUpdatedAt=(0,moment_1.default)().toDate();var e=this.fbAdmin.firestore().collection(this.collection).doc(t.id);s.set(e,Object.assign({},t))}))),yield s.commit(),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"})}else a.status(400).json({err:"Invalid Model Structure"})}else a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initCreate=(i,s,o)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(i.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),e&&t?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),o&&(yield o(i.body.data)),yield this.fbAdmin.firestore().collection(this.collection).doc(i.body.data.id).set(i.body.data),s.send({success:!0})):s.status(400).json({err:"Invalid Security Configuration"})):s.status(400).json({err:"Invalid Model Structure"})}catch(e){s.status(400).json({err:e})}}),this.initGet=(a,r)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=a.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,a),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",a,t),i)&&s?r.send({data:t}):r.status(400).json({err:"Invalid Security Configuration"}):r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}}),this.initBatchUpdate=(a,r)=>__awaiter(this,void 0,void 0,function*(){const o=this.fbAdmin.firestore().batch();try{if(this.modelChecker(a.body.data)&&a.body.id&&Array.isArray(a.body.id)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,a);let t=!0;if(a.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,e)||(t=!1)}),e&&t)if(a.body.sensitive){let s=!0;yield Promise.all(a.body.id.map(i=>__awaiter(this,void 0,void 0,function*(){var e,t=yield this.fbAdmin.firestore().collection(this.collection).doc(i).get();t.exists?(t=t.data(),(0,moment_1.default)(a.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))?(t=this.parseModel(a.body.data),e=this.fbAdmin.firestore().collection(this.collection).doc(i),o.update(e,Object.assign({},t))):s=!1):r.status(400).json({err:"Invalid Security Configuration"})}))),s&&(yield o.commit()),r.send({success:!0})}else{const i=this.parseModel(a.body.data);a.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=this.fbAdmin.firestore().collection(this.collection).doc(t);o.update(e,Object.assign({},i)),yield o.commit()}))}else r.status(400).json({err:"Invalid Security Configuration"})}}catch(e){}}),this.initUpdate=(d,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o,a,r=this.modelChecker(d.body.data)&&d.body.id;r?(e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),e&&t?d.body.sensitive?(i=yield this.fbAdmin.firestore().collection(this.collection).doc(r).get()).exists?(s=i.data(),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*s.baseUpdatedAt.seconds))?(o=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(r).update(Object.assign({},o)),n.send({success:!0})):n.status(400).json({err:"Refresh Sensitive Model"})):n.status(400).json({err:"Invalid Security Configuration"}):(a=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(r).update(Object.assign({},a)),n.send({success:!0})):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Model Structure"})}catch(e){n.status(400).json({err:e})}}),this.initBatchDelete=(c,l,h)=>__awaiter(this,void 0,void 0,function*(){try{const d=this.fbAdmin.firestore().batch();if(Array.isArray(c.body.id)){var e=yield this.fbAdmin.firestore().collection(this.collection).where("id","in",c.body.id).get(),i=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const o=[];if(e&&e.forEach(e=>{e=e.data();o.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),!i||!t)return void l.status(400).json({err:"Invalid Security Configuration"});h&&(yield h(o)),yield Promise.all(c.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(),l.send({success:!0})}else{let o=this.fbAdmin.firestore().collection(this.collection);var s=c.body.query,a=(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)}}),yield o.get()),r=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const n=[];if(a&&a.forEach(e=>{e=e.data();n.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),h&&(yield h(n)),!r||!t)return void l.status(400).json({err:"Invalid Security Configuration"});a.forEach(e=>{d.delete(e.ref)}),yield d.commit()}l.send({success:!0})}catch(e){l.status(400).json({err:e})}}),this.initDelete=(a,r,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=a.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,a),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",a,t),i)&&s?(d&&(yield d(t)),yield this.fbAdmin.firestore().collection(this.collection).doc(o).delete(),r.send({success:!0})):r.status(400).json({err:"Invalid Security Configuration"}):r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}}),this.initList=(D,B)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s;try{var r=(0,QueryModel_1.checkBaseConfig)(this.config,D);if(r){let o=this.fbAdmin.firestore().collection(this.collection);var d=D.body.aggregate,n=null!=(e=D.body.query)?e:[];let a="";if(n&&0<n.length&&n.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(a=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)}}),d){const j=null!=(t=d.queryId)?t:"";var c=null!=(i=d.dateId)?i:"baseUpdatedAt",l=null!=(s=d.range)?s:[],h=[];for(const I of l){var u=I.split("-"),[f,y=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=u,m=2===u.length,b=(0,moment_1.default)(f,"DD/MM/YYYY").isValid(),g=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),v=(0,moment_1.default)(f,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),p=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!b||!g)return void B.status(400).json({err:"Invalid Aggregate Range Configuration"});var _=m?I:"Begining until "+(0,moment_1.default)(f).format("DD/MM/YYYY");o=m?o.where(c,">=",(0,moment_1.default)(v).toDate()).where(c,"<=",(0,moment_1.default)(p).toDate()):o.where(c,"<",(0,moment_1.default)(v).toDate());let t=0;switch(d.type){case"count":var M=yield o.count().get();t=M.data().count;break;case"value":var A=yield(o=(o=o.limit(1)).orderBy(c,"desc")).get();A&&A.forEach(e=>{e=e.data(),e=JSON.parse(JSON.stringify(e));t=e[j]})}h.push({_id:_,value:t})}B.send({data:h})}else if(D.body.limit){if(o=o.limit(D.body.limit),D.body.sort){var C=D.body.sort;if(a&&C.sortId!==a)return void B.status(400).json({err:"Invalid Search Sort Configuration"});a||(o=o.orderBy(C.sortId,"asc"===C.type?"asc":"desc"))}var w,k=yield(o=D.body.cursor?o.startAfter(D.body.cursor):o).get();let t=!0;const Y=[];if(k&&k.forEach(e=>{e=e.data();Y.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",D,e)||(t=!1)}),r&&t){let t="";if(Y.length===D.body.limit){let e="id";D.body.sort&&(w=D.body.sort,e=w.sortId),t=Y[D.body.limit-1][e]}B.send({data:Y,count:t})}else B.status(400).json({err:"Invalid Security Configuration"})}else B.status(400).json({err:"Invalid Limit Configuration"})}else B.status(400).json({err:"Invalid Security Configuration"})}catch(e){B.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",this.initCreate),e.post("/batchCreate",this.initBatchCreate),e.post("/get",this.initGet),e.post("/update",this.initUpdate),e.post("/batchUpdate",this.initBatchUpdate),e.post("/delete",this.initDelete),e.post("/batchDelete",this.initBatchDelete),e.post("/list",this.initList),e},this.fbAdmin=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=a}}exports.FirebaseWrapper=FirebaseWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,r,d,n){return new(d=d||Promise)(function(i,t){function s(e){try{a(n.next(e))}catch(e){t(e)}}function o(e){try{a(n.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,o)}a((n=n.apply(e,r||[])).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");class FirebaseWrapper{constructor(e,t,i,s,o,a){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=(o,a,r)=>__awaiter(this,void 0,void 0,function*(){try{const s=this.fbAdmin.firestore().batch();if(Array.isArray(o.body.data)){let t=!0;if(o.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=o.body.data,i=(0,QueryModel_1.checkBaseConfig)(this.config,o);let t=!0;e.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",o,e)||(t=!1)}),i&&t?(r&&(yield r(e)),yield Promise.all(e.map(t=>__awaiter(this,void 0,void 0,function*(){t.baseUpdatedAt=(0,moment_1.default)().toDate();var e=this.fbAdmin.firestore().collection(this.collection).doc(t.id);s.set(e,Object.assign({},t))}))),yield s.commit(),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"})}else a.status(400).json({err:"Invalid Model Structure"})}else a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initCreate=(i,s,o)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(i.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),e&&t?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),o&&(yield o(i.body.data)),yield this.fbAdmin.firestore().collection(this.collection).doc(i.body.data.id).set(i.body.data),s.send({success:!0})):s.status(400).json({err:"Invalid Security Configuration"})):s.status(400).json({err:"Invalid Model Structure"})}catch(e){s.status(400).json({err:e})}}),this.initGet=(a,r)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=a.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,a),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",a,t),i)&&s?r.send({data:t}):r.status(400).json({err:"Invalid Security Configuration"}):r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}}),this.initBatchUpdate=(a,r)=>__awaiter(this,void 0,void 0,function*(){const o=this.fbAdmin.firestore().batch();try{if(this.modelChecker(a.body.data)&&a.body.id&&Array.isArray(a.body.id)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,a);let t=!0;if(a.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,e)||(t=!1)}),e&&t)if(a.body.sensitive){let s=!0;yield Promise.all(a.body.id.map(i=>__awaiter(this,void 0,void 0,function*(){var e,t=yield this.fbAdmin.firestore().collection(this.collection).doc(i).get();t.exists?(t=t.data(),(0,moment_1.default)(a.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))?(t=this.parseModel(a.body.data),e=this.fbAdmin.firestore().collection(this.collection).doc(i),o.update(e,Object.assign({},t))):s=!1):r.status(400).json({err:"Invalid Security Configuration"})}))),s&&(yield o.commit()),r.send({success:!0})}else{const i=this.parseModel(a.body.data);a.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=this.fbAdmin.firestore().collection(this.collection).doc(t);o.update(e,Object.assign({},i)),yield o.commit()}))}else r.status(400).json({err:"Invalid Security Configuration"})}}catch(e){}}),this.initUpdate=(d,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o,a,r=this.modelChecker(d.body.data)&&d.body.id;r?(e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),e&&t?d.body.sensitive?(i=yield this.fbAdmin.firestore().collection(this.collection).doc(r).get()).exists?(s=i.data(),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*s.baseUpdatedAt.seconds))?(o=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(r).update(Object.assign({},o)),n.send({success:!0})):n.status(400).json({err:"Refresh Sensitive Model"})):n.status(400).json({err:"Invalid Security Configuration"}):(a=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(r).update(Object.assign({},a)),n.send({success:!0})):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Model Structure"})}catch(e){n.status(400).json({err:e})}}),this.initBatchDelete=(c,l,h)=>__awaiter(this,void 0,void 0,function*(){try{const d=this.fbAdmin.firestore().batch();if(Array.isArray(c.body.id)){var e=yield this.fbAdmin.firestore().collection(this.collection).where("id","in",c.body.id).get(),i=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const o=[];if(e&&e.forEach(e=>{e=e.data();o.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),!i||!t)return void l.status(400).json({err:"Invalid Security Configuration"});h&&(yield h(o)),yield Promise.all(c.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(),l.send({success:!0})}else{let o=this.fbAdmin.firestore().collection(this.collection);var s=c.body.query,a=(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)}}),yield o.get()),r=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const n=[];if(a&&a.forEach(e=>{e=e.data();n.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),h&&(yield h(n)),!r||!t)return void l.status(400).json({err:"Invalid Security Configuration"});a.forEach(e=>{d.delete(e.ref)}),yield d.commit()}l.send({success:!0})}catch(e){l.status(400).json({err:e})}}),this.initDelete=(a,r,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=a.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,a),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",a,t),i)&&s?(d&&(yield d(t)),yield this.fbAdmin.firestore().collection(this.collection).doc(o).delete(),r.send({success:!0})):r.status(400).json({err:"Invalid Security Configuration"}):r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}}),this.initList=(D,B)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s;try{var r=(0,QueryModel_1.checkBaseConfig)(this.config,D);if(r){let o=this.fbAdmin.firestore().collection(this.collection);var d=D.body.aggregate,n=null!=(e=D.body.query)?e:[];let a="";if(n&&0<n.length&&n.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(a=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)}}),d){const j=null!=(t=d.queryId)?t:"";var c=null!=(i=d.dateId)?i:"baseUpdatedAt",l=null!=(s=d.range)?s:[],h=[];for(const I of l){var u=I.split("-"),[f,y=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=u,m=2===u.length,b=(0,moment_1.default)(f,"DD/MM/YYYY").isValid(),g=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),v=(0,moment_1.default)(f,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),p=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!b||!g)return void B.status(400).json({err:"Invalid Aggregate Range Configuration"});var _=m?I:"Begining until "+(0,moment_1.default)(f).format("DD/MM/YYYY");o=m?o.where(c,">=",(0,moment_1.default)(v).toDate()).where(c,"<=",(0,moment_1.default)(p).toDate()):o.where(c,"<",(0,moment_1.default)(v).toDate());let t=0;switch(d.type){case"count":var M=yield o.count().get();t=M.data().count;break;case"value":var A=yield(o=(o=o.limit(1)).orderBy(c,"desc")).get();A&&A.forEach(e=>{e=e.data(),e=JSON.parse(JSON.stringify(e));t=e[j]})}h.push({_id:_,value:t})}B.send({data:h})}else if(D.body.limit){if(o=o.limit(D.body.limit),D.body.sort){var C=D.body.sort;if(a&&C.sortId!==a)return void B.status(400).json({err:"Invalid Search Sort Configuration"});a||(o=o.orderBy(C.sortId,"asc"===C.type?"asc":"desc"))}var w,k=yield(o=D.body.cursor?o.startAfter(D.body.cursor):o).get();let t=!0;const Y=[];if(k&&k.forEach(e=>{e=e.data();Y.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",D,e)||(t=!1)}),r&&t){let t="";if(Y.length===D.body.limit){let e="id";D.body.sort&&(w=D.body.sort,e=w.sortId),t=Y[D.body.limit-1][e]}B.send({data:Y,count:t})}else B.status(400).json({err:"Invalid Security Configuration"})}else B.status(400).json({err:"Invalid Limit Configuration"})}else B.status(400).json({err:"Invalid Security Configuration"})}catch(e){B.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=a}}exports.FirebaseWrapper=FirebaseWrapper;
@@ -1,5 +1,6 @@
1
1
  export { FirebaseWrapper } from "./fbWrapper";
2
2
  export { MongoWrapper } from "./mongoWrapper";
3
+ export { MondayWrapper } from "./mondayWrapper";
3
4
  export { SecurityMiddleware } from "./security";
4
5
  export { UploadWrapper } from "./uploadWrapper";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/apis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UploadWrapper=exports.SecurityMiddleware=exports.MongoWrapper=exports.FirebaseWrapper=void 0;var fbWrapper_1=require("./fbWrapper"),mongoWrapper_1=(Object.defineProperty(exports,"FirebaseWrapper",{enumerable:!0,get:function(){return fbWrapper_1.FirebaseWrapper}}),require("./mongoWrapper")),security_1=(Object.defineProperty(exports,"MongoWrapper",{enumerable:!0,get:function(){return mongoWrapper_1.MongoWrapper}}),require("./security")),uploadWrapper_1=(Object.defineProperty(exports,"SecurityMiddleware",{enumerable:!0,get:function(){return security_1.SecurityMiddleware}}),require("./uploadWrapper"));Object.defineProperty(exports,"UploadWrapper",{enumerable:!0,get:function(){return uploadWrapper_1.UploadWrapper}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UploadWrapper=exports.SecurityMiddleware=exports.MondayWrapper=exports.MongoWrapper=exports.FirebaseWrapper=void 0;var fbWrapper_1=require("./fbWrapper"),mongoWrapper_1=(Object.defineProperty(exports,"FirebaseWrapper",{enumerable:!0,get:function(){return fbWrapper_1.FirebaseWrapper}}),require("./mongoWrapper")),mondayWrapper_1=(Object.defineProperty(exports,"MongoWrapper",{enumerable:!0,get:function(){return mongoWrapper_1.MongoWrapper}}),require("./mondayWrapper")),security_1=(Object.defineProperty(exports,"MondayWrapper",{enumerable:!0,get:function(){return mondayWrapper_1.MondayWrapper}}),require("./security")),uploadWrapper_1=(Object.defineProperty(exports,"SecurityMiddleware",{enumerable:!0,get:function(){return security_1.SecurityMiddleware}}),require("./uploadWrapper"));Object.defineProperty(exports,"UploadWrapper",{enumerable:!0,get:function(){return uploadWrapper_1.UploadWrapper}});
@@ -0,0 +1,47 @@
1
+ import SecurityConfig from "../model/SecurityConfig";
2
+ export interface WrapperLib {
3
+ express?: any;
4
+ axios?: any;
5
+ }
6
+ export declare const queryMondayApi: (token: string, query: any, variables?: any) => Promise<import("axios").AxiosResponse<any, any>>;
7
+ /**
8
+ * @Wrapper
9
+ * collection - Monday Collection
10
+ *
11
+ */
12
+ export declare class MondayWrapper {
13
+ mondayToken: string;
14
+ boardId: string;
15
+ groupId: string;
16
+ config: SecurityConfig;
17
+ lib: WrapperLib;
18
+ modelChecker: (obj: any) => boolean;
19
+ modelType: () => {
20
+ read: string[];
21
+ write: {
22
+ [id: string]: string;
23
+ };
24
+ };
25
+ constructor(mondayToken: string, boardId: string, groupId: string, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, modelType: () => {
26
+ read: string[];
27
+ write: {
28
+ [id: string]: string;
29
+ };
30
+ }, lib: WrapperLib);
31
+ parseModel: (mondayData: {
32
+ id: string;
33
+ name: string;
34
+ column_values: {
35
+ id: string;
36
+ text: string;
37
+ value: string;
38
+ }[];
39
+ }) => any;
40
+ initCreate: (req: any, res: any) => Promise<void>;
41
+ initGet: (req: any, res: any) => Promise<void>;
42
+ initList: (req: any, res: any) => Promise<void>;
43
+ initUpdate: (req: any, res: any) => Promise<void>;
44
+ initDelete: (req: any, res: any) => Promise<void>;
45
+ init: () => any;
46
+ }
47
+ //# sourceMappingURL=mondayWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mondayWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mondayWrapper.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,eAAO,MAAM,cAAc,UAClB,MAAM,SACN,GAAG,cACE,GAAG,qDAahB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,aAAa;IACxB,WAAW,SAAM;IACjB,OAAO,SAAM;IACb,OAAO,SAAM;IACb,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAEhB,YAAY,QAAS,GAAG,aAEtB;IACF,SAAS;cAAe,MAAM,EAAE;;;;MAK9B;gBAGA,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,SAAS,EAAE,MAAM;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE;YAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,EACpE,GAAG,EAAE,UAAU;IAWjB,UAAU,eAAgB;QACxB,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,MAAM,CAAC;QACb,aAAa,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;KAC9D,SAaC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAkDpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBAyCjC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAyDlC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA0DpC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAsDpC;IAEF,IAAI,YA8CF;CACH"}
@@ -0,0 +1,64 @@
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,s,r,n){return new(r=r||Promise)(function(i,t){function o(e){try{d(n.next(e))}catch(e){t(e)}}function a(e){try{d(n.throw(e))}catch(e){t(e)}}function d(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(o,a)}d((n=n.apply(e,s||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MondayWrapper=exports.queryMondayApi=void 0;const axios_1=__importDefault(require("axios")),QueryModel_1=require("../model/QueryModel"),queryMondayApi=(e,t,i)=>__awaiter(void 0,void 0,void 0,function*(){return yield axios_1.default.post("https://api.monday.com/v2",{query:t,variables:i},{headers:{"Content-Type":"application/json",Authorization:null!=e?e:""}})});exports.queryMondayApi=queryMondayApi;class MondayWrapper{constructor(e,t,i,o,a,d,s){this.mondayToken="",this.boardId="",this.groupId="",this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.modelType=()=>({read:[],write:{}}),this.parseModel=e=>{const i={id:e.id,name:e.name};return e.column_values.map(t=>{if("subitems"!==t.id){let e=!0;this.modelType().read.includes(t.id)&&(e=!1),i[t.id]=e?t.text:t.value}}),i},this.initCreate=(s,r)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,o,a,d;try{this.modelChecker(s.body.data)?(t=(0,QueryModel_1.checkBaseConfig)(this.config,s),i=(0,QueryModel_1.checkOpsConfig)(this.config,"create",s,s.body.data),t&&i?(o=s.body.data,a={boardId:Number(this.boardId),groupId:this.groupId,itemName:null!=(e=s.body.data.name)?e:"Item",columnValues:JSON.stringify(o)},d=(yield(0,exports.queryMondayApi)(this.mondayToken,`
2
+ mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
3
+ create_item (
4
+ board_id: $boardId,
5
+ group_id: $groupId,
6
+ item_name: $itemName,
7
+ column_values: $columnValues
8
+ ) {
9
+ id
10
+ }
11
+ }
12
+ `,a)).data.data.create_item.id,r.send({success:d})):r.status(400).json({err:"Invalid Security Configuration"})):r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initGet=(d,s)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,o,a;d.body.id?(e=`{
13
+ boards(ids: ${Number(this.boardId)}) {
14
+ items(ids:${d.body.id}) {
15
+ id
16
+ name
17
+ column_values {
18
+ id
19
+ text
20
+ value
21
+ }
22
+ }
23
+ }
24
+ }`,0<(t=(yield(0,exports.queryMondayApi)(this.mondayToken,e)).data.data.boards[0].items).length?(i=this.parseModel(t[0]),o=(0,QueryModel_1.checkBaseConfig)(this.config,d),a=(0,QueryModel_1.checkOpsConfig)(this.config,"read",d,i),o&&a?s.send({data:i}):s.status(400).json({err:"Invalid Security Configuration"})):s.send({data:null})):s.status(400).json({err:"Invalid Fields"})}catch(e){s.status(400).json({err:e})}}),this.initList=(n,u)=>__awaiter(this,void 0,void 0,function*(){try{var a=(0,QueryModel_1.checkBaseConfig)(this.config,n);if(a){var d,s=n.body.query;let e=[],t="",i="",o=(n.body.limit&&(i="limit: "+n.body.limit),e=s&&0<s.length?(d=s[0],i=i&&" , "+i,t=`query {items_by_column_values (board_id: ${this.boardId}, column_id:"${d.queryId}" , column_value: "${d.value}"${i}) {id name column_values {id text value}}}`,(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.items_by_column_values):(t=`query{
25
+ boards(ids:${this.boardId}){
26
+ items(${i}){
27
+ id
28
+ name
29
+ column_values{
30
+ id
31
+ text
32
+ value
33
+ }
34
+ }
35
+ }
36
+ }`,(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items),!0);const r=[];e.map(e=>{e=this.parseModel(e);r.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",n,e)||(o=!1)}),a&&o?u.send({data:r}):u.status(400).json({err:"Invalid Security Configuration"})}else u.status(400).json({err:"Invalid Fields"})}catch(e){u.status(400).json({err:e})}}),this.initUpdate=(i,d)=>__awaiter(this,void 0,void 0,function*(){try{if(this.modelChecker(i.body.data)&&i.body.id){var e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",i,i.body.data);if(e&&t){const o=i.body.data,a={boardId:Number(this.boardId),itemId:Number(i.body.id),columnValues:{}};Object.keys(o).map(t=>{if("id"!==t){var i=this.modelType().write;let e="";(e=i[t]?i[t]:e)?a.columnValues[t]={[e]:o[t]}:a.columnValues[t]=o[t]}}),a.columnValues=JSON.stringify(a.columnValues),yield(0,exports.queryMondayApi)(this.mondayToken,`
37
+ mutation ($boardId: Int!, $itemId: Int!, $columnValues: JSON!) {
38
+ change_multiple_column_values(
39
+ item_id: $itemId,
40
+ board_id: $boardId,
41
+ column_values: $columnValues
42
+ ) {
43
+ id
44
+ }
45
+ }
46
+ `,a),d.send({success:!0})}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.initDelete=(s,r)=>__awaiter(this,void 0,void 0,function*(){try{if(s.body.id){var e=`{
47
+ boards(ids: ${Number(this.boardId)}) {
48
+ items(ids:${s.body.id}) {
49
+ id
50
+ name
51
+ column_values {
52
+ id
53
+ text
54
+ value
55
+ }
56
+ }
57
+ }
58
+ }`,t=(yield(0,exports.queryMondayApi)(this.mondayToken,e)).data.data.boards[0].items;if(t.length<=0)throw"Error";var i,o=this.parseModel(t[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,s),d=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",s,o);a&&d?(i={itemId:Number(s.body.id)},yield(0,exports.queryMondayApi)(this.mondayToken,`
59
+ mutation ($itemId: Int!){
60
+ delete_item (item_id: $itemId) {
61
+ id
62
+ }
63
+ }
64
+ `,i),r.send({success:!0})):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.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e},this.mondayToken=e,this.boardId=t,this.groupId=i,this.config=o,this.modelChecker=a,this.modelType=d,this.lib=s}}exports.MondayWrapper=MondayWrapper;
@@ -1 +1 @@
1
- {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,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;IAEhB,YAAY,QAAS,GAAG,aAEtB;IACF,OAAO,SAAM;gBAGX,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;IAYlB,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAiD5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA+BtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA8BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAuEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA4DpC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAuH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAmCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAsOlC;IAEF,IAAI,YA0DF;CACH"}
1
+ {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,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;IAEhB,YAAY,QAAS,GAAG,aAEtB;IACF,OAAO,SAAM;gBAGX,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;IAYlB,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAiD5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA+BtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA8BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAuEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA4DpC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAuH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAmCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAsOlC;IAEF,IAAI,YA0EF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,d,r){return new(d=d||Promise)(function(i,t){function s(e){try{o(r.next(e))}catch(e){t(e)}}function a(e){try{o(r.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,a)}o((r=r.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_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel");class MongoWrapper{constructor(e,t,i,s,a,o,n){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.tableId="",this.parseModel=e=>(delete e._id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(a,o,n)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(a.body.data)){let t=!0;a.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||o.status(400).json({err:"Invalid Model Structure"});var e,s=(0,QueryModel_1.checkBaseConfig)(this.config,a);let i=!0;yield Promise.all(a.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,e)||(i=!1)})),s&&i?(e=a.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),n&&(yield n(e)),yield this.mongoDB.db(this.tableId).collection(this.collection).insertMany(e),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})}else o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initCreate=(i,s,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(i.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),e&&t?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),a&&(yield a(i.body.data)),yield this.mongoDB.db(this.tableId).collection(this.collection).insertOne(i.body.data),s.send({success:!0})):s.status(400).json({err:"Invalid Security Configuration"})):s.status(400).json({err:"Invalid Model Structure"})}catch(e){s.status(400).json({err:e})}}),this.initGet=(a,o)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=a.body.id;s?(e=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:s}),t=(0,QueryModel_1.checkBaseConfig)(this.config,a),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",a,e),t&&i?o.send({data:e}):o.status(400).json({err:"Invalid Security Configuration"})):o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initBatchUpdate=(o,n)=>__awaiter(this,void 0,void 0,function*(){try{var e=this.modelChecker(o.body.data)&&o.body.id;if(Array.isArray(o.body.id)){var s=o.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),i=(0,QueryModel_1.checkBaseConfig)(this.config,o);let t=!0;if(yield Promise.all(o.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",o,e)||(t=!1)})),i&&t){const a=this.mongoDB.db(this.tableId).collection(this.collection);if(o.body.sensitive){let i=!0;yield Promise.all(o.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield a.findOne({_id:t});(0,moment_1.default)(o.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(e.baseUpdatedAt))?n.status(400).json({err:"Refresh Sensitive Model"}):i=!1}))),i&&(yield a.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0}))}else yield a.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0})}else n.status(400).json({err:"Invalid Security Configuration"})}}catch(e){}}),this.initUpdate=(d,r)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a,o,n=this.modelChecker(d.body.data)&&d.body.id;n?(e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),e&&t?(i=this.mongoDB.db(this.tableId).collection(this.collection),d.body.sensitive?(s=yield i.findOne({_id:n}),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(s.baseUpdatedAt))?(a=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},a)}),r.send({success:!0})):r.status(400).json({err:"Refresh Sensitive Model"})):(o=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},o)}),r.send({success:!0}))):r.status(400).json({err:"Invalid Security Configuration"})):r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initBatchDelete=(c,u,h)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(c.body.id)){var e=this.mongoDB.db(this.tableId).collection(this.collection),i=yield e.find({_id:{$in:c.body.id}}),s=(0,QueryModel_1.checkBaseConfig)(this.config,c),a=yield i.toArray();let t=!0;0<a.length&&(yield Promise.all(a.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}))),s&&t?(h&&(yield h(a)),yield e.deleteMany({_id:{$in:c.body.id}}),u.send({success:!0})):u.status(400).json({err:"Invalid Security Configuration"})}else{var o=c.body.query;const l={};o&&0<o.length&&o.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&&(l.$or=[],e.searchIds.map(e=>{l.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":l[i]=s;break;case"!=":l[i]={$ne:s};break;case">":l[i]={$gt:s};break;case"<":l[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(l[i]={$gte:s[0],$lte:s[1]});break;case"in":l[i]={$in:s}}});var n=this.mongoDB.db(this.tableId).collection(this.collection),d=yield n.find(l).toArray(),r=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;0<d.length&&d.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),h&&(yield h(d)),r&&t?(yield n.deleteMany(l),u.send({success:!0})):u.status(400).json({err:"Invalid Security Configuration"})}}catch(e){u.status(400).json({err:e})}}),this.initDelete=(o,n,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a=o.body.id;a?(t=yield(e=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:a}),i=(0,QueryModel_1.checkBaseConfig)(this.config,o),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,t),i&&s?(d&&(yield d(t)),yield e.findOneAndDelete({_id:a}),n.send({success:!0})):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initList=(A,B)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,a,o;try{var n=(0,QueryModel_1.checkBaseConfig)(this.config,A);if(n){var d=A.body.aggregate,r=null!=(e=A.body.query)?e:[];const Y={};if(r&&0<r.length&&r.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}}}),d){var l=[],c=null!=(t=d.queryId)?t:"",u=null!=(i=d.dateId)?i:"baseUpdatedAt";for(const O of null!=(s=d.range)?s:[]){Object.assign({},Y);var h=O.split("-"),[y,g=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=h,f=2===h.length,b=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),m=(0,moment_1.default)(g,"DD/MM/YYYY").isValid(),p=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),v=(0,moment_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!b||!m)return void B.status(400).json({err:"Invalid Aggregate Range Configuration"});var _=f?{$match:Object.assign(Object.assign({},Y),{[u]:{$gte:new Date(p),$lte:new Date(v)}})}:{$match:Object.assign(Object.assign({},Y),{[u]:{$lte:new Date(p)}})},M=[];let e=!1;var D=f?O:"Begining until "+(0,moment_1.default)(y).format("DD/MM/YYYY");switch(d.type){case"avg":M.push(_,{$group:{_id:D,value:{$avg:"$"+c}}});break;case"sum":M.push(_,{$group:{_id:D,value:{$sum:"$"+c}}});break;case"count":e=!0}if(0===M.length&&!e)return void B.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(Y).count({}):null!=(o=null==(a=(yield C.aggregate(M).toArray())[0])?void 0:a.value)?o:0,l.push({_id:D,value:t})}B.send({data:l})}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(Y);var j,I,k=yield e.count({}),$=(A.body.cursor&&(e=e.skip(A.body.cursor)),A.body.limit&&(e=e.limit(A.body.limit)),A.body.sort&&(I={[(j=A.body.sort).sortId]:"asc"===j.type?1:-1},e=e.sort(I)),yield e.toArray());let t=!0;0<$.length&&$.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",A,e)||(t=!1)}),n&&t?B.send({data:$,count:k}):B.status(400).json({err:"Invalid Security Configuration"})}}else B.status(400).json({err:"Invalid Security Configuration"})}catch(e){B.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",this.initCreate),e.post("/batchCreate",this.initBatchCreate),e.post("/get",this.initGet),e.post("/update",this.initUpdate),e.post("/batchUpdate",this.initBatchUpdate),e.post("/delete",this.initDelete),e.post("/batchDelete",this.initBatchDelete),e.post("/list",this.initList),e},this.mongoDB=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=a,this.lib=o;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e}}exports.MongoWrapper=MongoWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,d,r){return new(d=d||Promise)(function(i,t){function s(e){try{o(r.next(e))}catch(e){t(e)}}function a(e){try{o(r.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,a)}o((r=r.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_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel");class MongoWrapper{constructor(e,t,i,s,a,o,n){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.tableId="",this.parseModel=e=>(delete e._id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(a,o,n)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(a.body.data)){let t=!0;a.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||o.status(400).json({err:"Invalid Model Structure"});var e,s=(0,QueryModel_1.checkBaseConfig)(this.config,a);let i=!0;yield Promise.all(a.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,e)||(i=!1)})),s&&i?(e=a.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),n&&(yield n(e)),yield this.mongoDB.db(this.tableId).collection(this.collection).insertMany(e),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})}else o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initCreate=(i,s,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t;this.modelChecker(i.body.data)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,i),t=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),e&&t?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),a&&(yield a(i.body.data)),yield this.mongoDB.db(this.tableId).collection(this.collection).insertOne(i.body.data),s.send({success:!0})):s.status(400).json({err:"Invalid Security Configuration"})):s.status(400).json({err:"Invalid Model Structure"})}catch(e){s.status(400).json({err:e})}}),this.initGet=(a,o)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=a.body.id;s?(e=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:s}),t=(0,QueryModel_1.checkBaseConfig)(this.config,a),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",a,e),t&&i?o.send({data:e}):o.status(400).json({err:"Invalid Security Configuration"})):o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initBatchUpdate=(o,n)=>__awaiter(this,void 0,void 0,function*(){try{var e=this.modelChecker(o.body.data)&&o.body.id;if(Array.isArray(o.body.id)){var s=o.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),i=(0,QueryModel_1.checkBaseConfig)(this.config,o);let t=!0;if(yield Promise.all(o.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",o,e)||(t=!1)})),i&&t){const a=this.mongoDB.db(this.tableId).collection(this.collection);if(o.body.sensitive){let i=!0;yield Promise.all(o.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield a.findOne({_id:t});(0,moment_1.default)(o.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(e.baseUpdatedAt))?n.status(400).json({err:"Refresh Sensitive Model"}):i=!1}))),i&&(yield a.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0}))}else yield a.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0})}else n.status(400).json({err:"Invalid Security Configuration"})}}catch(e){}}),this.initUpdate=(d,r)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a,o,n=this.modelChecker(d.body.data)&&d.body.id;n?(e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,d.body.data),e&&t?(i=this.mongoDB.db(this.tableId).collection(this.collection),d.body.sensitive?(s=yield i.findOne({_id:n}),(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(s.baseUpdatedAt))?(a=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},a)}),r.send({success:!0})):r.status(400).json({err:"Refresh Sensitive Model"})):(o=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},o)}),r.send({success:!0}))):r.status(400).json({err:"Invalid Security Configuration"})):r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initBatchDelete=(c,u,h)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(c.body.id)){var e=this.mongoDB.db(this.tableId).collection(this.collection),i=yield e.find({_id:{$in:c.body.id}}),s=(0,QueryModel_1.checkBaseConfig)(this.config,c),a=yield i.toArray();let t=!0;0<a.length&&(yield Promise.all(a.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}))),s&&t?(h&&(yield h(a)),yield e.deleteMany({_id:{$in:c.body.id}}),u.send({success:!0})):u.status(400).json({err:"Invalid Security Configuration"})}else{var o=c.body.query;const l={};o&&0<o.length&&o.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&&(l.$or=[],e.searchIds.map(e=>{l.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":l[i]=s;break;case"!=":l[i]={$ne:s};break;case">":l[i]={$gt:s};break;case"<":l[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(l[i]={$gte:s[0],$lte:s[1]});break;case"in":l[i]={$in:s}}});var n=this.mongoDB.db(this.tableId).collection(this.collection),d=yield n.find(l).toArray(),r=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;0<d.length&&d.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),h&&(yield h(d)),r&&t?(yield n.deleteMany(l),u.send({success:!0})):u.status(400).json({err:"Invalid Security Configuration"})}}catch(e){u.status(400).json({err:e})}}),this.initDelete=(o,n,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,a=o.body.id;a?(t=yield(e=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:a}),i=(0,QueryModel_1.checkBaseConfig)(this.config,o),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,t),i&&s?(d&&(yield d(t)),yield e.findOneAndDelete({_id:a}),n.send({success:!0})):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initList=(A,B)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,a,o;try{var n=(0,QueryModel_1.checkBaseConfig)(this.config,A);if(n){var d=A.body.aggregate,r=null!=(e=A.body.query)?e:[];const Y={};if(r&&0<r.length&&r.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}}}),d){var l=[],c=null!=(t=d.queryId)?t:"",u=null!=(i=d.dateId)?i:"baseUpdatedAt";for(const O of null!=(s=d.range)?s:[]){Object.assign({},Y);var h=O.split("-"),[y,g=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=h,f=2===h.length,b=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),m=(0,moment_1.default)(g,"DD/MM/YYYY").isValid(),p=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),v=(0,moment_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!b||!m)return void B.status(400).json({err:"Invalid Aggregate Range Configuration"});var _=f?{$match:Object.assign(Object.assign({},Y),{[u]:{$gte:new Date(p),$lte:new Date(v)}})}:{$match:Object.assign(Object.assign({},Y),{[u]:{$lte:new Date(p)}})},M=[];let e=!1;var D=f?O:"Begining until "+(0,moment_1.default)(y).format("DD/MM/YYYY");switch(d.type){case"avg":M.push(_,{$group:{_id:D,value:{$avg:"$"+c}}});break;case"sum":M.push(_,{$group:{_id:D,value:{$sum:"$"+c}}});break;case"count":e=!0}if(0===M.length&&!e)return void B.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(Y).count({}):null!=(o=null==(a=(yield C.aggregate(M).toArray())[0])?void 0:a.value)?o:0,l.push({_id:D,value:t})}B.send({data:l})}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(Y);var j,I,k=yield e.count({}),$=(A.body.cursor&&(e=e.skip(A.body.cursor)),A.body.limit&&(e=e.limit(A.body.limit)),A.body.sort&&(I={[(j=A.body.sort).sortId]:"asc"===j.type?1:-1},e=e.sort(I)),yield e.toArray());let t=!0;0<$.length&&$.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",A,e)||(t=!1)}),n&&t?B.send({data:$,count:k}):B.status(400).json({err:"Invalid Security Configuration"})}}else B.status(400).json({err:"Invalid Security Configuration"})}catch(e){B.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=a,this.lib=o;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e}}exports.MongoWrapper=MongoWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,
@@ -23,6 +23,7 @@
23
23
  "start:mongo": "cd dist && node mongoServer.js",
24
24
  "start:fb": "cd dist && node firebaseServer.js",
25
25
  "start:aws": "cd dist && node awsServer.js",
26
+ "start:monday": "cd dist && node mondayServer.js",
26
27
  "install:husky": "yarn husky install"
27
28
  },
28
29
  "config": {