blixify-server 0.1.33 → 0.1.35
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.
- package/dist/apis/fbWrapper.d.ts +1 -1
- package/dist/apis/fbWrapper.d.ts.map +1 -1
- package/dist/apis/fbWrapper.js +1 -1
- package/dist/apis/mondayWrapper.d.ts +16 -5
- package/dist/apis/mondayWrapper.d.ts.map +1 -1
- package/dist/apis/mondayWrapper.js +11 -11
- package/dist/apis/mongoWrapper.d.ts +27 -8
- package/dist/apis/mongoWrapper.d.ts.map +1 -1
- package/dist/apis/mongoWrapper.js +1 -1
- package/package.json +1 -1
package/dist/apis/fbWrapper.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class FirebaseWrapper {
|
|
|
17
17
|
initCreate: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<void>;
|
|
18
18
|
initGet: (req: any, res: any) => Promise<void>;
|
|
19
19
|
initBatchUpdate: (req: any, res: any) => Promise<void>;
|
|
20
|
-
initUpdate: (req: any, res: any) => Promise<void>;
|
|
20
|
+
initUpdate: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<void>;
|
|
21
21
|
initBatchDelete: (req: any, res: any, workflow?: ((dataList: any[]) => Promise<any>) | undefined) => Promise<void>;
|
|
22
22
|
initDelete: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<void>;
|
|
23
23
|
initList: (req: any, res: any) => Promise<void>;
|
|
@@ -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,mBA2HzC;IAEF,UAAU,
|
|
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,mBA2HzC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCA8DtC;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,YA2EF;CACH"}
|
package/dist/apis/fbWrapper.js
CHANGED
|
@@ -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{o(n.next(e))}catch(e){t(e)}}function r(e){try{o(n.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,r)}o((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");class FirebaseWrapper{constructor(e,t,i,s,r,o){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=(r,o,a)=>__awaiter(this,void 0,void 0,function*(){try{const s=this.fbAdmin.firestore().batch();if(Array.isArray(r.body.data)){let t=!0;if(r.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=r.body.data,i=(0,QueryModel_1.checkBaseConfig)(this.config,r);let t=!0;e.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",r,e)||(t=!1)}),i&&t?(a&&(yield a(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(),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})}else o.status(400).json({err:"Invalid Model Structure"})}else o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initCreate=(i,s,r)=>__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(),r&&(yield r(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=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,r=o.body.id;r?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(r).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,o),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",o,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=(y,b)=>__awaiter(this,void 0,void 0,function*(){var e,t;const i=this.fbAdmin.firestore().batch();try{var s=this.modelChecker(y.body.data)&&y.body.query,r=this.parseModel(null!=(e=y.body.data)?e:[]),o=null!=(t=y.body.query)?t:[],a=y.body.isOr||!1,d=y.body.unsetData;if(s){var n=this.fbAdmin.firestore().collection(this.collection);const u=[];o.forEach(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"=":u.push(this.fbAdmin.firestore.Filter.where(i,"==",s));break;case"!=":u.push(this.fbAdmin.firestore.Filter.where(i,"!=",s));break;case">":u.push(this.fbAdmin.firestore.Filter.where(i,">",s));break;case"<":u.push(this.fbAdmin.firestore.Filter.where(i,"<",s));break;case"><":Array.isArray(s)&&2<=s.length&&u.push(this.fbAdmin.firestore.Filter.where(i,">=",s[0]),this.fbAdmin.firestore.Filter.where(i,"<=",s[1]));break;case"in":u.push(this.fbAdmin.firestore.Filter.where(i,"in",s))}});var c=a?this.fbAdmin.firestore.Filter.or(...u):this.fbAdmin.firestore.Filter.and(...u),l=yield n.where(c).get(),h=(0,QueryModel_1.checkBaseConfig)(this.config,y);let t=!0;const f=[];if(l&&l.forEach(e=>{e=e.data();f.push(e.id),y.body.sensitive&&!(0,moment_1.default)(y.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*e.baseUpdatedAt.seconds))&&b.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",y,e)||(t=!1)}),h&&t){let t={};d&&d.forEach(e=>{t[e]=this.fbAdmin.firestore.FieldValue.delete()}),r&&(t=Object.assign(Object.assign({},r),t)),yield Promise.all(f.map(e=>{e=this.fbAdmin.firestore().collection(this.collection).doc(e);i.update(e,Object.assign({},t))})),yield i.commit(),b.send({success:!0})}else b.status(400).json({err:"Invalid Security Configuration"})}}catch(e){b.status(400).json({err:e})}}),this.initUpdate=(d,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,r,o,a=this.modelChecker(d.body.data)&&d.body.id;a?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(a).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,d),s=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,t),i)&&s?d.body.sensitive?(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))?(r=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(a).update(Object.assign({},r)),n.send({success:!0})):n.status(400).json({err:"Refresh Sensitive Model"}):(o=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(a).update(Object.assign({},o)),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 r=[];if(e&&e.forEach(e=>{e=e.data();r.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(r)),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 r=this.fbAdmin.firestore().collection(this.collection);var s=c.body.query,o=(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&&(r=r.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":r=r.where(i,"==",s);break;case"!=":r=r.where(i,"!=",s);break;case">":r=r.where(i,">",s);break;case"<":r=r.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(r=r.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":r=r.where(i,"in",s)}}),yield r.get()),a=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const n=[];if(o&&o.forEach(e=>{e=e.data();n.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),h&&(yield h(n)),!a||!t)return void l.status(400).json({err:"Invalid Security Configuration"});o.forEach(e=>{d.delete(e.ref)}),yield d.commit()}l.send({success:!0})}catch(e){l.status(400).json({err:e})}}),this.initDelete=(o,a,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,r=o.body.id;r?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(r).get()).exists&&(t=e.data(),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 this.fbAdmin.firestore().collection(this.collection).doc(r).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=(D,B)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s;try{var a=(0,QueryModel_1.checkBaseConfig)(this.config,D);if(a){let r=this.fbAdmin.firestore().collection(this.collection);var d=D.body.aggregate,n=null!=(e=D.body.query)?e:[];let o="";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&&(o=e.searchIds[0],r=r.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":r=r.where(i,"==",s);break;case"!=":r=r.where(i,"!=",s);break;case">":r=r.where(i,">",s);break;case"<":r=r.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(r=r.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":r=r.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,b=2===u.length,m=(0,moment_1.default)(f,"DD/MM/YYYY").isValid(),g=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),p=(0,moment_1.default)(f,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),v=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!m||!g)return void B.status(400).json({err:"Invalid Aggregate Range Configuration"});var _=b?I:"Begining until "+(0,moment_1.default)(f).format("DD/MM/YYYY");r=b?r.where(c,">=",(0,moment_1.default)(p).toDate()).where(c,"<=",(0,moment_1.default)(v).toDate()):r.where(c,"<",(0,moment_1.default)(p).toDate());let t=0;switch(d.type){case"count":var A=yield r.count().get();t=A.data().count;break;case"value":var M=yield(r=(r=r.limit(1)).orderBy(c,"desc")).get();M&&M.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(r=r.limit(D.body.limit),D.body.sort){var w=D.body.sort;if(o&&w.sortId!==o)return void B.status(400).json({err:"Invalid Search Sort Configuration"});o||(r=r.orderBy(w.sortId,"asc"===w.type?"asc":"desc"))}var C,k=yield(r=D.body.cursor?r.startAfter(D.body.cursor):r).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)}),a&&t){let t="";if(Y.length===D.body.limit){let e="id";D.body.sort&&(C=D.body.sort,e=C.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=r,this.lib=o}}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{o(n.next(e))}catch(e){t(e)}}function r(e){try{o(n.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,r)}o((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");class FirebaseWrapper{constructor(e,t,i,s,r,o){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=(r,o,a)=>__awaiter(this,void 0,void 0,function*(){try{const s=this.fbAdmin.firestore().batch();if(Array.isArray(r.body.data)){let t=!0;if(r.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=r.body.data,i=(0,QueryModel_1.checkBaseConfig)(this.config,r);let t=!0;e.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",r,e)||(t=!1)}),i&&t?(a&&(yield a(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(),o.send({success:!0})):o.status(400).json({err:"Invalid Security Configuration"})}else o.status(400).json({err:"Invalid Model Structure"})}else o.status(400).json({err:"Invalid Fields"})}catch(e){o.status(400).json({err:e})}}),this.initCreate=(i,s,r)=>__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(),r&&(yield r(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=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,r=o.body.id;r?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(r).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,o),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",o,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=(y,b)=>__awaiter(this,void 0,void 0,function*(){var e,t;const i=this.fbAdmin.firestore().batch();try{var s=this.modelChecker(y.body.data)&&y.body.query,r=this.parseModel(null!=(e=y.body.data)?e:[]),o=null!=(t=y.body.query)?t:[],a=y.body.isOr||!1,d=y.body.unsetData;if(s){var n=this.fbAdmin.firestore().collection(this.collection);const u=[];o.forEach(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"=":u.push(this.fbAdmin.firestore.Filter.where(i,"==",s));break;case"!=":u.push(this.fbAdmin.firestore.Filter.where(i,"!=",s));break;case">":u.push(this.fbAdmin.firestore.Filter.where(i,">",s));break;case"<":u.push(this.fbAdmin.firestore.Filter.where(i,"<",s));break;case"><":Array.isArray(s)&&2<=s.length&&u.push(this.fbAdmin.firestore.Filter.where(i,">=",s[0]),this.fbAdmin.firestore.Filter.where(i,"<=",s[1]));break;case"in":u.push(this.fbAdmin.firestore.Filter.where(i,"in",s))}});var c=a?this.fbAdmin.firestore.Filter.or(...u):this.fbAdmin.firestore.Filter.and(...u),l=yield n.where(c).get(),h=(0,QueryModel_1.checkBaseConfig)(this.config,y);let t=!0;const f=[];if(l&&l.forEach(e=>{e=e.data();f.push(e.id),y.body.sensitive&&!(0,moment_1.default)(y.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*e.baseUpdatedAt.seconds))&&b.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",y,e)||(t=!1)}),h&&t){let t={};d&&d.forEach(e=>{t[e]=this.fbAdmin.firestore.FieldValue.delete()}),r&&(t=Object.assign(Object.assign({},r),t)),yield Promise.all(f.map(e=>{e=this.fbAdmin.firestore().collection(this.collection).doc(e);i.update(e,Object.assign({},t))})),yield i.commit(),b.send({success:!0})}else b.status(400).json({err:"Invalid Security Configuration"})}}catch(e){b.status(400).json({err:e})}}),this.initUpdate=(d,n,c)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,r,o,a=this.modelChecker(d.body.data)&&d.body.id;a?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(a).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,d),s=(0,QueryModel_1.checkOpsConfig)(this.config,"update",d,t),i)&&s?d.body.sensitive?(0,moment_1.default)(d.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))?(c&&(yield c(d.body.data)),r=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(a).update(Object.assign({},r)),n.send({success:!0})):n.status(400).json({err:"Refresh Sensitive Model"}):(c&&(yield c(d.body.data)),o=this.parseModel(d.body.data),yield this.fbAdmin.firestore().collection(this.collection).doc(a).update(Object.assign({},o)),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 r=[];if(e&&e.forEach(e=>{e=e.data();r.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(r)),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 r=this.fbAdmin.firestore().collection(this.collection);var s=c.body.query,o=(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&&(r=r.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":r=r.where(i,"==",s);break;case"!=":r=r.where(i,"!=",s);break;case">":r=r.where(i,">",s);break;case"<":r=r.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(r=r.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":r=r.where(i,"in",s)}}),yield r.get()),a=(0,QueryModel_1.checkBaseConfig)(this.config,c);let t=!0;const n=[];if(o&&o.forEach(e=>{e=e.data();n.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",c,e)||(t=!1)}),h&&(yield h(n)),!a||!t)return void l.status(400).json({err:"Invalid Security Configuration"});o.forEach(e=>{d.delete(e.ref)}),yield d.commit()}l.send({success:!0})}catch(e){l.status(400).json({err:e})}}),this.initDelete=(o,a,d)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,r=o.body.id;r?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(r).get()).exists&&(t=e.data(),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 this.fbAdmin.firestore().collection(this.collection).doc(r).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=(D,B)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s;try{var a=(0,QueryModel_1.checkBaseConfig)(this.config,D);if(a){let r=this.fbAdmin.firestore().collection(this.collection);var d=D.body.aggregate,n=null!=(e=D.body.query)?e:[];let o="";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&&(o=e.searchIds[0],r=r.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":r=r.where(i,"==",s);break;case"!=":r=r.where(i,"!=",s);break;case">":r=r.where(i,">",s);break;case"<":r=r.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(r=r.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":r=r.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,b=2===u.length,m=(0,moment_1.default)(f,"DD/MM/YYYY").isValid(),g=(0,moment_1.default)(y,"DD/MM/YYYY").isValid(),p=(0,moment_1.default)(f,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),v=(0,moment_1.default)(y,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!m||!g)return void B.status(400).json({err:"Invalid Aggregate Range Configuration"});var _=b?I:"Begining until "+(0,moment_1.default)(f).format("DD/MM/YYYY");r=b?r.where(c,">=",(0,moment_1.default)(p).toDate()).where(c,"<=",(0,moment_1.default)(v).toDate()):r.where(c,"<",(0,moment_1.default)(p).toDate());let t=0;switch(d.type){case"count":var A=yield r.count().get();t=A.data().count;break;case"value":var M=yield(r=(r=r.limit(1)).orderBy(c,"desc")).get();M&&M.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(r=r.limit(D.body.limit),D.body.sort){var w=D.body.sort;if(o&&w.sortId!==o)return void B.status(400).json({err:"Invalid Search Sort Configuration"});o||(r=r.orderBy(w.sortId,"asc"===w.type?"asc":"desc"))}var C,k=yield(r=D.body.cursor?r.startAfter(D.body.cursor):r).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)}),a&&t){let t="";if(Y.length===D.body.limit){let e="id";D.body.sort&&(C=D.body.sort,e=C.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=r,this.lib=o}}exports.FirebaseWrapper=FirebaseWrapper;
|
|
@@ -34,11 +34,22 @@ export declare class MondayWrapper {
|
|
|
34
34
|
value: string;
|
|
35
35
|
}[];
|
|
36
36
|
}) => any;
|
|
37
|
-
initCreate: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
initCreate: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<{
|
|
38
|
+
success: any;
|
|
39
|
+
} | undefined>;
|
|
40
|
+
initGet: (req: any, res: any) => Promise<{
|
|
41
|
+
data: any;
|
|
42
|
+
} | undefined>;
|
|
43
|
+
initList: (req: any, res: any) => Promise<{
|
|
44
|
+
data: any[];
|
|
45
|
+
count: boolean | null;
|
|
46
|
+
} | undefined>;
|
|
47
|
+
initUpdate: (req: any, res: any) => Promise<{
|
|
48
|
+
success: boolean;
|
|
49
|
+
} | undefined>;
|
|
50
|
+
initDelete: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<{
|
|
51
|
+
success: boolean;
|
|
52
|
+
} | undefined>;
|
|
42
53
|
init: () => any;
|
|
43
54
|
}
|
|
44
55
|
//# sourceMappingURL=mondayWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mondayWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mondayWrapper.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,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,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC
|
|
1
|
+
{"version":3,"file":"mondayWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mondayWrapper.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,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,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAuDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBA4CjC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;mBAyElC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG;;mBAkFpC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBA0DtC;IAEF,IAAI,YA8CF;CACH"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,d,r,n){return new(r=r||Promise)(function(i,t){function o(e){try{s(n.next(e))}catch(e){t(e)}}function a(e){try{s(n.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(o,a)}s((n=n.apply(e,d||[])).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,s,d){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=(r,n,u)=>__awaiter(this,void 0,void 0,function*(){var e,t
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,d,r,n){return new(r=r||Promise)(function(i,t){function o(e){try{s(n.next(e))}catch(e){t(e)}}function a(e){try{s(n.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(o,a)}s((n=n.apply(e,d||[])).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,s,d){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=(r,n,u)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(r.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,r),o=(0,QueryModel_1.checkOpsConfig)(this.config,"create",r,r.body.data);if(i&&o){var a=r.body.data,s=(u&&(yield u(a)),{boardId:Number(this.boardId),groupId:this.groupId,itemName:null!=(e=r.body.data.name)?e:"Item",columnValues:JSON.stringify(a)}),d={success:(yield(0,exports.queryMondayApi)(this.mondayToken,`
|
|
2
2
|
mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
|
|
3
3
|
create_item (
|
|
4
4
|
board_id: $boardId,
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
id
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
`,s)).data.data.create_item.id
|
|
12
|
+
`,s)).data.data.create_item.id};if(null!=(t=r.body)&&t.stopRes)return d;n.send(d)}else n.status(400).json({err:"Invalid Security Configuration"})}else n.status(400).json({err:"Invalid Model Structure"})}catch(e){n.status(400).json({err:e})}}),this.initGet=(r,n)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(r.body.id){var t=`{
|
|
13
13
|
boards(ids: ${Number(this.boardId)}) {
|
|
14
|
-
items(ids:${
|
|
14
|
+
items(ids:${r.body.id}) {
|
|
15
15
|
id
|
|
16
16
|
name
|
|
17
17
|
column_values {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
}`,
|
|
24
|
+
}`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items;if(0<i.length){var o,a=this.parseModel(i[0]),s=(0,QueryModel_1.checkBaseConfig)(this.config,r),d=(0,QueryModel_1.checkOpsConfig)(this.config,"read",r,a);if(s&&d)return o={data:a},null!=(e=r.body)&&e.stopRes?o:void n.send(o);n.status(400).json({err:"Invalid Security Configuration"})}else n.send({data:null})}else n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initList=(m,h)=>__awaiter(this,void 0,void 0,function*(){var d;try{var e=(0,QueryModel_1.checkBaseConfig)(this.config,m);if(e){var r=m.body.query;let t=[],i="",o="",a="";if(m.body.limit&&(o="limit: "+m.body.limit),m.body.cursor&&(a="page : "+Number(m.body.cursor)),r&&0<r.length){var n=r[0],u=(o=o&&" , "+o,a=a&&" , "+a,i=`query {items_by_column_values (board_id: ${this.boardId}, column_id:"${n.queryId}" , column_value: "${n.value}"${o}${a}) {id name column_values {id text value}}}`,yield(0,exports.queryMondayApi)(this.mondayToken,i));t=u.data.data.items_by_column_values}else{let e="";e=o&&a?o+" , "+a:o||a,i=`query{
|
|
25
25
|
boards(ids:${this.boardId}){
|
|
26
26
|
items(${e}){
|
|
27
27
|
id
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
}`;var l=yield(0,exports.queryMondayApi)(this.mondayToken,i);t=l.data.data.boards[0].items}let s=!0;const
|
|
36
|
+
}`;var l=yield(0,exports.queryMondayApi)(this.mondayToken,i);t=l.data.data.boards[0].items}let s=!0;const y=[];if(t.map(e=>{e=this.parseModel(e);y.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",m,e)||(s=!1)}),e&&s){let e=null;y.length===m.body.limit&&(e=!0);var c={data:y,count:e};if(null!=(d=m.body)&&d.stopRes)return c;h.send(c)}else h.status(400).json({err:"Invalid Security Configuration"})}else h.status(400).json({err:"Invalid Fields"})}catch(e){h.status(400).json({err:e})}}),this.initUpdate=(u,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(this.modelChecker(u.body.data)&&u.body.id){var t=`{
|
|
37
37
|
boards(ids: ${Number(this.boardId)}) {
|
|
38
|
-
items(ids:${
|
|
38
|
+
items(ids:${u.body.id}) {
|
|
39
39
|
id
|
|
40
40
|
name
|
|
41
41
|
column_values {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
}`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items;if(i.length<=0)throw"Error";var o=this.parseModel(i[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,
|
|
48
|
+
}`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items;if(i.length<=0)throw"Error";var o=this.parseModel(i[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,u),s=(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,o);if(a&&s){const r=u.body.data,n={boardId:Number(this.boardId),itemId:Number(u.body.id),columnValues:{}};Object.keys(r).map(t=>{if("id"!==t){var i=this.modelType().write;let e="";(e=i[t]?i[t]:e)?n.columnValues[t]={[e]:r[t]}:n.columnValues[t]=r[t]}}),n.columnValues=JSON.stringify(n.columnValues),yield(0,exports.queryMondayApi)(this.mondayToken,`
|
|
49
49
|
mutation ($boardId: Int!, $itemId: Int!, $columnValues: JSON!) {
|
|
50
50
|
change_multiple_column_values(
|
|
51
51
|
item_id: $itemId,
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
id
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
`,
|
|
58
|
+
`,n);var d={success:!0};if(null!=(e=u.body)&&e.stopRes)return d;l.send(d)}else l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Fields"})}catch(e){l.status(400).json({err:e})}}),this.initDelete=(n,u,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(n.body.id){var t=`{
|
|
59
59
|
boards(ids: ${Number(this.boardId)}) {
|
|
60
|
-
items(ids:${
|
|
60
|
+
items(ids:${n.body.id}) {
|
|
61
61
|
id
|
|
62
62
|
name
|
|
63
63
|
column_values {
|
|
@@ -67,10 +67,10 @@
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
}`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items;if(i.length<=0)throw"Error";var o
|
|
70
|
+
}`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items;if(i.length<=0)throw"Error";var o=this.parseModel(i[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,n),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,o);if(a&&s){l&&(yield l(o));var d={itemId:Number(n.body.id)},r=(yield(0,exports.queryMondayApi)(this.mondayToken,`
|
|
71
71
|
mutation ($itemId: Int!){
|
|
72
72
|
delete_item (item_id: $itemId) {
|
|
73
73
|
id
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
`,
|
|
76
|
+
`,d),{success:!0});if(null!=(e=n.body)&&e.stopRes)return r;u.send(r)}else u.status(400).json({err:"Invalid Security Configuration"})}else u.status(400).json({err:"Invalid Model Structure"})}catch(e){u.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=s,this.lib=d}}exports.MondayWrapper=MondayWrapper;
|
|
@@ -18,14 +18,33 @@ export declare class MongoWrapper {
|
|
|
18
18
|
modelChecker: (obj: any) => boolean;
|
|
19
19
|
constructor(mongoDB: any, collection: string, isProd: boolean, config: SecurityConfig, modelChecker: (obj: any, ignore?: boolean) => boolean, lib: WrapperLib, tableId?: string, debug?: (reqBody: any, curBody: any, errMsg: any) => void);
|
|
20
20
|
parseModel: (data: any) => any;
|
|
21
|
-
initBatchCreate: (req: any, res: any, workflow?: ((dataList: any[]) => Promise<any>) | undefined) => Promise<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
initBatchCreate: (req: any, res: any, workflow?: ((dataList: any[]) => Promise<any>) | undefined) => Promise<{
|
|
22
|
+
success: boolean;
|
|
23
|
+
} | undefined>;
|
|
24
|
+
initCreate: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<{
|
|
25
|
+
success: boolean;
|
|
26
|
+
} | undefined>;
|
|
27
|
+
initGet: (req: any, res: any) => Promise<{
|
|
28
|
+
data: any;
|
|
29
|
+
} | undefined>;
|
|
30
|
+
initBatchUpdate: (req: any, res: any) => Promise<{
|
|
31
|
+
success: boolean;
|
|
32
|
+
} | undefined>;
|
|
33
|
+
initUpdate: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<{
|
|
34
|
+
success: boolean;
|
|
35
|
+
} | undefined>;
|
|
36
|
+
initBatchDelete: (req: any, res: any, workflow?: ((dataList: any[]) => Promise<any>) | undefined) => Promise<{
|
|
37
|
+
success: boolean;
|
|
38
|
+
} | undefined>;
|
|
39
|
+
initDelete: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
} | undefined>;
|
|
42
|
+
initList: (req: any, res: any) => Promise<{
|
|
43
|
+
data: any[];
|
|
44
|
+
} | {
|
|
45
|
+
data: any;
|
|
46
|
+
count: any;
|
|
47
|
+
} | undefined>;
|
|
29
48
|
init: () => any;
|
|
30
49
|
}
|
|
31
50
|
//# sourceMappingURL=mongoWrapper.d.ts.map
|
|
@@ -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;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
|
|
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;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;;mBAmD5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAkCtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBAgCjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG;;mBAsIzC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAsEtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBA2H5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAqCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBA6OlC;IAEF,IAAI,YA4EF;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,d){return new(r=r||Promise)(function(s,t){function i(e){try{o(d.next(e))}catch(e){t(e)}}function a(e){try{o(d.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?s(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(i,a)}o((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_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel");class MongoWrapper{constructor(e,t,s,i,a,o,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_1.default)().toDate(),e),this.initBatchCreate=(o,n,r)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(Array.isArray(o.body.data)){let t=!0;o.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||n.status(400).json({err:"Invalid Model Structure"});var i,a=(0,QueryModel_1.checkBaseConfig)(this.config,o);let s=!0;yield Promise.all(o.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",o,e)||(s=!1)})),a&&s?(i=o.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),r&&(yield r(i)),yield this.mongoDB.db(this.tableId).collection(this.collection).insertMany(i),null!=(e=o.body)&&e.stopRes||n.send({success:!0})):n.status(400).json({err:"Invalid Security Configuration"})}else n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initCreate=(i,a,o)=>__awaiter(this,void 0,void 0,function*(){var e,t,s;try{this.modelChecker(i.body.data)?(t=(0,QueryModel_1.checkBaseConfig)(this.config,i),s=(0,QueryModel_1.checkOpsConfig)(this.config,"create",i,i.body.data),t&&s?(i.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),o&&(yield o(i.body.data)),yield this.mongoDB.db(this.tableId).collection(this.collection).insertOne(i.body.data),null!=(e=i.body)&&e.stopRes||a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"})):a.status(400).json({err:"Invalid Model Structure"})}catch(e){a.status(400).json({err:e})}}),this.initGet=(o,n)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t,s,i,a=o.body.id;a?(t=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:a}),s=(0,QueryModel_1.checkBaseConfig)(this.config,o),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",o,t),s&&i?null!=(e=o.body)&&e.stopRes||n.send({data:t}):n.status(400).json({err:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initBatchUpdate=(g,b)=>__awaiter(this,void 0,void 0,function*(){var e,s,i;try{if(this.modelChecker(g.body.data)&&g.body.query){var a=g.body.unsetData,o=null!=(e=g.body.query)?e:[];const u=g.body.isOr?"$or":"$and",h={};var n=this.parseModel(null!=(s=g.body.data)?s:[]),r=(o&&0<o.length&&(h[u]=[],o.some(e=>"search"===e.type)&&(h.$or=[]),o.map(e=>{var t,s=null!=(t=e.queryId)?t:"";const i=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&e.searchIds.map(e=>{h.$or.push({[e]:{$regex:i,$options:"i"}})});break;case"=":h[u].push({[s]:i});break;case"!=":h[u].push({[s]:{$ne:i}});break;case">":h[u].push({[s]:{$gt:i}});break;case"<":h[u].push({[s]:{$lt:i}});break;case"><":Array.isArray(i)&&2<=i.length&&(h[u].push({[s]:{$lt:i}}),h[u]={[s]:{$gte:i[0],$lte:i[1]}});break;case"in":h[u].push({[s]:{$in:i}})}})),(0,QueryModel_1.checkBaseConfig)(this.config,g));let t=!0;var d=this.mongoDB.db(this.tableId).collection(this.collection),l=yield(yield d.find(Object.assign({},h))).toArray();if(yield Promise.all(l.map(e=>{g.body.sensitive&&!(0,moment_1.default)(g.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(e.baseUpdatedAt))&&b.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",g,e)||(t=!1)})),r&&t){const y={};var c={};a&&(a.forEach(e=>{y[e]=""}),c.$unset=Object.assign({},y)),n&&(c.$set=Object.assign({},n)),yield d.updateMany(h,c),null!=(i=g.body)&&i.stopRes||b.send({success:!0})}else b.status(400).json({err:"Invalid Security Configuration"})}}catch(e){b.status(400).json({err:e})}}),this.initUpdate=(l,c)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{var s,i,a,o,n,r,d=this.modelChecker(l.body.data)&&l.body.id;d?(i=yield(s=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:d}),this.debug&&this.debug(l.body,i),a=(0,QueryModel_1.checkBaseConfig)(this.config,l),o=(0,QueryModel_1.checkOpsConfig)(this.config,"update",l,i),a&&o?l.body.sensitive?(0,moment_1.default)(l.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(i.baseUpdatedAt))?(n=this.parseModel(l.body.data),yield s.updateOne({_id:d},{$set:Object.assign({},n)}),null!=(e=l.body)&&e.stopRes||c.send({success:!0})):c.status(400).json({err:"Refresh Sensitive Model"}):(r=this.parseModel(l.body.data),yield s.updateOne({_id:d},{$set:Object.assign({},r)}),null!=(t=l.body)&&t.stopRes||c.send({success:!0})):c.status(400).json({err:"Invalid Security Configuration"})):c.status(400).json({err:"Invalid Model Structure"})}catch(e){this.debug&&this.debug(null,null,e),c.status(400).json({err:e})}}),this.initBatchDelete=(h,y,g)=>__awaiter(this,void 0,void 0,function*(){var e,s;try{if(Array.isArray(h.body.id)){var i=this.mongoDB.db(this.tableId).collection(this.collection),a=yield i.find({_id:{$in:h.body.id}}),o=(0,QueryModel_1.checkBaseConfig)(this.config,h),n=yield a.toArray();let t=!0;0<n.length&&(yield Promise.all(n.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",h,e)||(t=!1)}))),o&&t?(g&&(yield g(n)),yield i.deleteMany({_id:{$in:h.body.id}}),null!=(e=h.body)&&e.stopRes||y.send({success:!0})):y.status(400).json({err:"Invalid Security Configuration"})}else{var r=h.body.query;const u={};r&&0<r.length&&r.map(e=>{var t,s=null!=(t=e.queryId)?t:"";const i=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(u.$or=[],e.searchIds.map(e=>{u.$or.push({[e]:{$regex:i,$options:"i"}})}));break;case"=":u[s]=i;break;case"!=":u[s]={$ne:i};break;case">":u[s]={$gt:i};break;case"<":u[s]={$lt:i};break;case"><":Array.isArray(i)&&2<=i.length&&(u[s]={$gte:i[0],$lte:i[1]});break;case"in":u[s]={$in:i}}});var d=this.mongoDB.db(this.tableId).collection(this.collection),l=yield d.find(u).toArray(),c=(0,QueryModel_1.checkBaseConfig)(this.config,h);let t=!0;0<l.length&&l.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",h,e)||(t=!1)}),g&&(yield g(l)),c&&t?(yield d.deleteMany(u),null!=(s=h.body)&&s.stopRes||y.send({success:!0})):y.status(400).json({err:"Invalid Security Configuration"})}}catch(e){y.status(400).json({err:e})}}),this.initDelete=(n,r,d)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t,s,i,a,o=n.body.id;o?(s=yield(t=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:o}),i=(0,QueryModel_1.checkBaseConfig)(this.config,n),a=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,s),i&&a?(d&&(yield d(s)),yield t.findOneAndDelete({_id:o}),null!=(e=n.body)&&e.stopRes||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=(w,Q)=>__awaiter(this,void 0,void 0,function*(){var e,t,s,i,a,o,n,r;try{var d=(0,QueryModel_1.checkBaseConfig)(this.config,w);if(d){var l=w.body.aggregate,c=null!=(e=w.body.query)?e:[];const A={};if(c&&0<c.length&&c.map(e=>{var t,s=null!=(t=e.queryId)?t:"";const i=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(A.$or=[],e.searchIds.map(e=>{A.$or.push({[e]:{$regex:i,$options:"i"}})}));break;case"=":A[s]=i;break;case"!=":A[s]={$ne:i};break;case">":A[s]={$gt:i};break;case"<":A[s]={$lt:i};break;case"><":Array.isArray(i)&&2<=i.length&&(A[s]={$gte:i[0],$lte:i[1]});break;case"in":A[s]={$in:i}}}),l){var u=[],h=null!=(t=l.queryId)?t:"",y=null!=(s=l.dateId)?s:"baseUpdatedAt";for(const B of null!=(i=l.range)?i:[]){Object.assign({},A);var g=B.split("-"),[b,f=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=g,p=2===g.length,m=(0,moment_1.default)(b,"DD/MM/YYYY").isValid(),v=(0,moment_1.default)(f,"DD/MM/YYYY").isValid(),_=(0,moment_1.default)(b,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),M=(0,moment_1.default)(f,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!m||!v)return void Q.status(400).json({err:"Invalid Aggregate Range Configuration"});var $=p?{$match:Object.assign(Object.assign({},A),{[y]:{$gte:new Date(_),$lte:new Date(M)}})}:{$match:Object.assign(Object.assign({},A),{[y]:{$lte:new Date(_)}})},D=[];let e=!1;var k=p?B:"Begining until "+(0,moment_1.default)(b,"DD/MM/YYYY HH:mm:ss").format("DD/MM/YYYY");switch(l.type){case"avg":D.push($,{$group:{_id:k,value:{$avg:"$"+h}}});break;case"sum":D.push($,{$group:{_id:k,value:{$sum:"$"+h}}});break;case"count":e=!0}if(0===D.length&&!e)return void Q.status(400).json({err:"Invalid Aggregate Configuration"});var I=this.mongoDB.db(this.tableId).collection(this.collection);let t=0;t=e?yield I.find($.$match).count({}):null!=(o=null==(a=(yield I.aggregate(D).toArray())[0])?void 0:a.value)?o:0,u.push({_id:k,value:t})}null!=(n=w.body)&&n.stopRes||Q.send({data:u})}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(A);var C,j,Y=yield e.count({}),O=(w.body.cursor&&(e=e.skip(w.body.cursor)),w.body.limit&&(e=e.limit(w.body.limit)),w.body.sort&&(j={[(C=w.body.sort).sortId]:"asc"===C.type?1:-1},e=e.sort(j)),yield e.toArray());let t=!0;0<O.length&&O.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",w,e)||(t=!1)}),d&&t?null!=(r=w.body)&&r.stopRes||Q.send({data:O,count:Y}):Q.status(400).json({err:"Invalid Security Configuration"})}}else Q.status(400).json({err:"Invalid Security Configuration"})}catch(e){Q.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=s,this.config=i,this.modelChecker=a,this.lib=o;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,r,n,d){return new(n=n||Promise)(function(i,t){function s(e){try{o(d.next(e))}catch(e){t(e)}}function a(e){try{o(d.throw(e))}catch(e){t(e)}}function o(e){var t;e.done?i(e.value):((t=e.value)instanceof n?t:new n(function(e){e(t)})).then(s,a)}o((d=d.apply(e,r||[])).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,r,n){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_1.default)().toDate(),e),this.initBatchCreate=(r,n,d)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(Array.isArray(r.body.data)){let t=!0;r.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||n.status(400).json({err:"Invalid Model Structure"});var s=(0,QueryModel_1.checkBaseConfig)(this.config,r);let i=!0;if(yield Promise.all(r.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",r,e)||(i=!1)})),s&&i){var a=r.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()}));d&&(yield d(a));yield this.mongoDB.db(this.tableId).collection(this.collection).insertMany(a);var o={success:!0};if(null!=(e=r.body)&&e.stopRes)return o;n.send(o)}else n.status(400).json({err:"Invalid Security Configuration"})}else n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initCreate=(a,o,r)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(this.modelChecker(a.body.data)){var t=(0,QueryModel_1.checkBaseConfig)(this.config,a),i=(0,QueryModel_1.checkOpsConfig)(this.config,"create",a,a.body.data);if(t&&i){a.body.data.baseUpdatedAt=(0,moment_1.default)().toDate(),r&&(yield r(a.body.data));yield this.mongoDB.db(this.tableId).collection(this.collection).insertOne(a.body.data);var s={success:!0};if(null!=(e=a.body)&&e.stopRes)return s;o.send(s)}else o.status(400).json({err:"Invalid Security Configuration"})}else o.status(400).json({err:"Invalid Model Structure"})}catch(e){o.status(400).json({err:e})}}),this.initGet=(r,n)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=r.body.id;if(t){var i,s=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:t}),a=(0,QueryModel_1.checkBaseConfig)(this.config,r),o=(0,QueryModel_1.checkOpsConfig)(this.config,"read",r,s);if(a&&o)return i={data:s},null!=(e=r.body)&&e.stopRes?i:void n.send(i);n.status(400).json({err:"Invalid Security Configuration"})}else n.status(400).json({err:"Invalid Fields"})}catch(e){n.status(400).json({err:e})}}),this.initBatchUpdate=(g,b)=>__awaiter(this,void 0,void 0,function*(){var e,i,s;try{if(this.modelChecker(g.body.data)&&g.body.query){var a=g.body.unsetData,o=null!=(e=g.body.query)?e:[];const h=g.body.isOr?"$or":"$and",y={};var r=this.parseModel(null!=(i=g.body.data)?i:[]),n=(o&&0<o.length&&(y[h]=[],o.some(e=>"search"===e.type)&&(y.$or=[]),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&&e.searchIds.map(e=>{y.$or.push({[e]:{$regex:s,$options:"i"}})});break;case"=":y[h].push({[i]:s});break;case"!=":y[h].push({[i]:{$ne:s}});break;case">":y[h].push({[i]:{$gt:s}});break;case"<":y[h].push({[i]:{$lt:s}});break;case"><":Array.isArray(s)&&2<=s.length&&(y[h].push({[i]:{$lt:s}}),y[h]={[i]:{$gte:s[0],$lte:s[1]}});break;case"in":y[h].push({[i]:{$in:s}})}})),(0,QueryModel_1.checkBaseConfig)(this.config,g));let t=!0;var d=this.mongoDB.db(this.tableId).collection(this.collection),l=yield(yield d.find(Object.assign({},y))).toArray();if(yield Promise.all(l.map(e=>{g.body.sensitive&&!(0,moment_1.default)(g.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(e.baseUpdatedAt))&&b.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",g,e)||(t=!1)})),n&&t){const f={};var c={},u=(a&&(a.forEach(e=>{f[e]=""}),c.$unset=Object.assign({},f)),r&&(c.$set=Object.assign({},r)),yield d.updateMany(y,c),{success:!0});if(null!=(s=g.body)&&s.stopRes)return u;b.send(u)}else b.status(400).json({err:"Invalid Security Configuration"})}}catch(e){b.status(400).json({err:e})}}),this.initUpdate=(c,u,h)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{var i=this.modelChecker(c.body.data)&&c.body.id;if(i){var s=this.mongoDB.db(this.tableId).collection(this.collection),a=yield s.findOne({_id:i}),o=(this.debug&&this.debug(c.body,a),(0,QueryModel_1.checkBaseConfig)(this.config,c)),r=(0,QueryModel_1.checkOpsConfig)(this.config,"update",c,a);if(o&&r){var n={success:!0};if(c.body.sensitive)if((0,moment_1.default)(c.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(a.baseUpdatedAt))){h&&(yield h(c.body.data));var d=this.parseModel(c.body.data);if(yield s.updateOne({_id:i},{$set:Object.assign({},d)}),null!=(e=c.body)&&e.stopRes)return n;u.send(n)}else u.status(400).json({err:"Refresh Sensitive Model"});else{h&&(yield h(c.body.data));var l=this.parseModel(c.body.data);if(yield s.updateOne({_id:i},{$set:Object.assign({},l)}),null!=(t=c.body)&&t.stopRes)return n;u.send(n)}}else u.status(400).json({err:"Invalid Security Configuration"})}else u.status(400).json({err:"Invalid Model Structure"})}catch(e){this.debug&&this.debug(null,null,e),u.status(400).json({err:e})}}),this.initBatchDelete=(f,g,b)=>__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),a=yield s.find({_id:{$in:f.body.id}}),o=(0,QueryModel_1.checkBaseConfig)(this.config,f),r=yield a.toArray();let t=!0;if(0<r.length&&(yield Promise.all(r.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",f,e)||(t=!1)}))),o&&t){b&&(yield b(r)),yield s.deleteMany({_id:{$in:f.body.id}});var n={success:!0};if(null!=(e=f.body)&&e.stopRes)return n;g.send(n)}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),c=yield l.find(y).toArray(),u=(0,QueryModel_1.checkBaseConfig)(this.config,f);let t=!0;if(0<c.length&&c.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",f,e)||(t=!1)}),b&&(yield b(c)),u&&t){yield l.deleteMany(y);var h={success:!0};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=(n,d,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=n.body.id;if(t){var i=this.mongoDB.db(this.tableId).collection(this.collection),s=yield i.findOne({_id:t}),a=(0,QueryModel_1.checkBaseConfig)(this.config,n),o=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,s);if(a&&o){l&&(yield l(s)),yield i.findOneAndDelete({_id:t});var r={success:!0};if(null!=(e=n.body)&&e.stopRes)return r;d.send(r)}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=(R,S)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,a,o,r,n;try{var d=(0,QueryModel_1.checkBaseConfig)(this.config,R);if(d){var l=R.body.aggregate,c=null!=(e=R.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}}}),l){var u=[],h=null!=(t=l.queryId)?t:"",y=null!=(i=l.dateId)?i:"baseUpdatedAt";for(const Q of null!=(s=l.range)?s:[]){Object.assign({},w);var f=Q.split("-"),[g,b=(0,moment_1.default)().format("DD/MM/YYYY HH:mm:ss")]=f,p=2===f.length,v=(0,moment_1.default)(g,"DD/MM/YYYY").isValid(),m=(0,moment_1.default)(b,"DD/MM/YYYY").isValid(),_=(0,moment_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss"),M=(0,moment_1.default)(b,"DD/MM/YYYY HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");if(!v||!m)return void S.status(400).json({err:"Invalid Aggregate Range Configuration"});var $=p?{$match:Object.assign(Object.assign({},w),{[y]:{$gte:new Date(_),$lte:new Date(M)}})}:{$match:Object.assign(Object.assign({},w),{[y]:{$lte:new Date(_)}})},D=[];let e=!1;var k=p?Q:"Begining until "+(0,moment_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("DD/MM/YYYY");switch(l.type){case"avg":D.push($,{$group:{_id:k,value:{$avg:"$"+h}}});break;case"sum":D.push($,{$group:{_id:k,value:{$sum:"$"+h}}});break;case"count":e=!0}if(0===D.length&&!e)return void S.status(400).json({err:"Invalid Aggregate Configuration"});var I=this.mongoDB.db(this.tableId).collection(this.collection);let t=0;t=e?yield I.find($.$match).count({}):null!=(o=null==(a=(yield I.aggregate(D).toArray())[0])?void 0:a.value)?o:0,u.push({_id:k,value:t})}var C={data:u};if(null!=(r=R.body)&&r.stopRes)return C;S.send(C)}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(w);var j,Y,O,A=yield e.count({}),B=(R.body.cursor&&(e=e.skip(R.body.cursor)),R.body.limit&&(e=e.limit(R.body.limit)),R.body.sort&&(Y={[(j=R.body.sort).sortId]:"asc"===j.type?1:-1},e=e.sort(Y)),yield e.toArray());let t=!0;if(0<B.length&&B.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",R,e)||(t=!1)}),d&&t)return O={data:B,count:A},null!=(n=R.body)&&n.stopRes?O:void S.send(O);S.status(400).json({err:"Invalid Security Configuration"})}}else S.status(400).json({err:"Invalid Security Configuration"})}catch(e){S.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=r?r+"-"+e:e,this.debug=n}}exports.MongoWrapper=MongoWrapper;
|