blixify-server 0.1.14 → 0.1.15
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":"AAOA,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,QAAe,GAAG,OAAO,GAAG,mBA8CzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA8BpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAoEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA0DpC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"fbWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/fbWrapper.ts"],"names":[],"mappings":"AAOA,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,QAAe,GAAG,OAAO,GAAG,mBA8CzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA8BpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA6BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAoEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA0DpC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBA6GzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAyCpC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAsHlC;IAEF,IAAI,YA0DF;CACH"}
|
package/dist/apis/fbWrapper.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,a,d,n){return new(d=d||Promise)(function(i,t){function s(e){try{r(n.next(e))}catch(e){t(e)}}function o(e){try{r(n.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?i(e.value):((t=e.value)instanceof d?t:new d(function(e){e(t)})).then(s,o)}r((n=n.apply(e,a||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirebaseWrapper=void 0;const moment_1=__importDefault(require("moment")),QueryModel_1=require("../model/QueryModel");class FirebaseWrapper{constructor(e,t,i,s,o,r){this.fbAdmin="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.modelChecker=e=>!1,this.parseModel=e=>(delete e.id,e.baseUpdatedAt=(0,moment_1.default)().toDate(),e),this.initBatchCreate=(s,o)=>__awaiter(this,void 0,void 0,function*(){try{const i=this.fbAdmin.firestore().batch();if(Array.isArray(s.body.data)){let t=!0;if(s.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t){var e=(0,QueryModel_1.checkBaseConfig)(this.config,s);let t=!0;s.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",s,e)||(t=!1)}),e&&t?(yield Promise.all(s.body.data.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);i.set(e,Object.assign({},t))}))),yield i.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)=>__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(),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=(r,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=r.body.id;o?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(o).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",r,t),i)&&s?a.send({data:t}):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initBatchUpdate=(r,a)=>__awaiter(this,void 0,void 0,function*(){const o=this.fbAdmin.firestore().batch();try{if(this.modelChecker(r.body.data)&&r.body.id&&Array.isArray(r.body.id)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,r);let t=!0;if(r.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",r,e)||(t=!1)}),e&&t)if(r.body.sensitive){let s=!0;yield Promise.all(r.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)(r.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(1e3*t.baseUpdatedAt.seconds))?(t=this.parseModel(r.body.data),e=this.fbAdmin.firestore().collection(this.collection).doc(i),o.update(e,Object.assign({},t))):s=!1):a.status(400).json({err:"Invalid Security Configuration"})}))),s&&(yield o.commit()),a.send({success:!0})}else{const i=this.parseModel(r.body.data);r.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 a.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,r,a=this.modelChecker(d.body.data)&&d.body.id;a?(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(a).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(a).update(Object.assign({},o)),n.send({success:!0})):n.status(400).json({err:"Refresh Sensitive Model"})):n.status(400).json({err:"Invalid Security Configuration"}):(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:"Invalid Security Configuration"})):n.status(400).json({err:"Invalid Model Structure"})}catch(e){n.status(400).json({err:e})}}),this.initBatchDelete=(n,c)=>__awaiter(this,void 0,void 0,function*(){try{const d=this.fbAdmin.firestore().batch();if(Array.isArray(n.body.id)){var e=yield this.fbAdmin.firestore().collection(this.collection).where("id","in",n.body.id).get(),i=(0,QueryModel_1.checkBaseConfig)(this.config,n);let t=!0;if(e&&e.forEach(e=>{e=e.data();(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,e)||(t=!1)}),!i||!t)return void c.status(400).json({err:"Invalid Security Configuration"});yield Promise.all(n.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(),c.send({success:!0})}else{let o=this.fbAdmin.firestore().collection(this.collection);var s=n.body.query,r=(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()),a=(0,QueryModel_1.checkBaseConfig)(this.config,n);let t=!0;if(r&&r.forEach(e=>{e=e.data();(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,e)||(t=!1)}),!a||!t)return void c.status(400).json({err:"Invalid Security Configuration"});r.forEach(e=>{d.delete(e.ref)}),yield d.commit()}c.send({success:!0})}catch(e){c.status(400).json({err:e})}}),this.initDelete=(r,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=r.body.id;o?(e=yield this.fbAdmin.firestore().collection(this.collection).doc(o).get()).exists&&(t=e.data(),i=(0,QueryModel_1.checkBaseConfig)(this.config,r),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,t),i)&&s?(yield this.fbAdmin.firestore().collection(this.collection).doc(o).delete(),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"}):a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initList=(n,c)=>__awaiter(this,void 0,void 0,function*(){try{var e=(0,QueryModel_1.checkBaseConfig)(this.config,n);if(e){let o=this.fbAdmin.firestore().collection(this.collection),r="";var t=n.body.query;if(t&&0<t.length&&t.map(e=>{var t,i=null!=(t=e.queryId)?t:"",s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(r=e.searchIds[0],o=o.orderBy(e.searchIds[0]).startAt(s).endAt(s+""));break;case"=":o=o.where(i,"==",s);break;case"!=":o=o.where(i,"!=",s);break;case">":o=o.where(i,">",s);break;case"<":o=o.where(i,"<",s);break;case"><":Array.isArray(s)&&2<=s.length&&(o=o.where(i,">=",s[0]).where(i,"<=",s[1]));break;case"in":o=o.where(i,"in",s)}}),n.body.limit){if(o=o.limit(n.body.limit),n.body.sort){var i=n.body.sort;if(r&&i.sortId!==r)return void c.status(400).json({err:"Invalid Search Sort Configuration"});r||(o=o.orderBy(i.sortId,"asc"===i.type?"asc":"desc"))}var s,a=yield(o=n.body.cursor?o.startAfter(n.body.cursor):o).get();let t=!0;const d=[];if(a&&a.forEach(e=>{e=e.data();d.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",n,e)||(t=!1)}),e&&t){let t="";if(d.length===n.body.limit){let e="id";n.body.sort&&(s=n.body.sort,e=s.sortId),t=d[n.body.limit-1][e]}c.send({data:d,count:t})}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Limit Configuration"})}else c.status(400).json({err:"Invalid Security Configuration"})}catch(e){c.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=r}}exports.FirebaseWrapper=FirebaseWrapper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,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,QAAe,GAAG,OAAO,GAAG,mBA+CzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA6BpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA8BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAuEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA4DpC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAOA,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,QAAe,GAAG,OAAO,GAAG,mBA+CzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA6BpC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA8BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAuEzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBA4DpC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAoHzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAkCpC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBA8GlC;IAEF,IAAI,YA0DF;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(
|
|
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{a(r.next(e))}catch(e){t(e)}}function o(e){try{a(r.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((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,o,a,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=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(o.body.data)){let t=!0;o.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||a.status(400).json({err:"Invalid Model Structure"});var e,s=(0,QueryModel_1.checkBaseConfig)(this.config,o);let i=!0;yield Promise.all(o.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",o,e)||(i=!1)})),s&&i?(e=o.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),yield this.mongoDB.db(this.tableId).collection(this.collection).insertMany(e),a.send({success:!0})):a.status(400).json({err:"Invalid Security Configuration"})}else a.status(400).json({err:"Invalid Fields"})}catch(e){a.status(400).json({err:e})}}),this.initCreate=(i,s)=>__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(),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=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=o.body.id;s?(e=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:s}),t=(0,QueryModel_1.checkBaseConfig)(this.config,o),i=(0,QueryModel_1.checkOpsConfig)(this.config,"read",o,e),t&&i?a.send({data:e}):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=(a,n)=>__awaiter(this,void 0,void 0,function*(){try{var e=this.modelChecker(a.body.data)&&a.body.id;if(Array.isArray(a.body.id)){var s=a.body.data.map(e=>Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_1.default)().toDate()})),i=(0,QueryModel_1.checkBaseConfig)(this.config,a);let t=!0;if(yield Promise.all(a.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",a,e)||(t=!1)})),i&&t){const o=this.mongoDB.db(this.tableId).collection(this.collection);if(a.body.sensitive){let i=!0;yield Promise.all(a.body.id.map(t=>__awaiter(this,void 0,void 0,function*(){var e=yield o.findOne({_id:t});(0,moment_1.default)(a.body.data.baseUpdatedAt).isAfter((0,moment_1.default)(e.baseUpdatedAt))?n.status(400).json({err:"Refresh Sensitive Model"}):i=!1}))),i&&(yield o.updateMany({_id:{$in:e}},{$set:Object.assign({},s)}),n.send({success:!0}))}else yield o.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,o,a,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))?(o=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},o)}),r.send({success:!0})):r.status(400).json({err:"Refresh Sensitive Model"})):(a=this.parseModel(d.body.data),yield i.updateOne({_id:n},{$set:Object.assign({},a)}),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=(l,h)=>__awaiter(this,void 0,void 0,function*(){try{if(Array.isArray(l.body.id)){var e=this.mongoDB.db(this.tableId).collection(this.collection),i=yield e.find({_id:{$in:l.body.id}}),s=(0,QueryModel_1.checkBaseConfig)(this.config,l),o=yield i.toArray();let t=!0;0<o.length&&(yield Promise.all(o.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",l,e)||(t=!1)}))),s&&t?(yield e.deleteMany({_id:{$in:l.body.id}}),h.send({success:!0})):h.status(400).json({err:"Invalid Security Configuration"})}else{var a=l.body.query;const c={};a&&0<a.length&&a.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(c.$or=[],e.searchIds.map(e=>{c.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":c[i]=s;break;case"!=":c[i]={$ne:s};break;case">":c[i]={$gt:s};break;case"<":c[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(c[i]={$gte:s[0],$lte:s[1]});break;case"in":c[i]={$in:s}}});var n=this.mongoDB.db(this.tableId).collection(this.collection),d=yield n.find(c).toArray(),r=(0,QueryModel_1.checkBaseConfig)(this.config,l);let t=!0;0<d.length&&d.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",l,e)||(t=!1)}),r&&t?(yield n.deleteMany(c),h.send({success:!0})):h.status(400).json({err:"Invalid Security Configuration"})}}catch(e){h.status(400).json({err:e})}}),this.initDelete=(a,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=a.body.id;o?(t=yield(e=this.mongoDB.db(this.tableId).collection(this.collection)).findOne({_id:o}),i=(0,QueryModel_1.checkBaseConfig)(this.config,a),s=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",a,t),i&&s?(yield e.findOneAndDelete({_id:o}),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=(c,l)=>__awaiter(this,void 0,void 0,function*(){try{var i=(0,QueryModel_1.checkBaseConfig)(this.config,c);if(i){var s=c.body.query;const r={};s&&0<s.length&&s.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&&(r.$or=[],e.searchIds.map(e=>{r.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":r[i]=s;break;case"!=":r[i]={$ne:s};break;case">":r[i]={$gt:s};break;case"<":r[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(r[i]={$gte:s[0],$lte:s[1]});break;case"in":r[i]={$in:s}}});let e=this.mongoDB.db(this.tableId).collection(this.collection).find(r);var o,a,n=yield e.count({}),d=(c.body.cursor&&(e=e.skip(c.body.cursor)),c.body.limit&&(e=e.limit(c.body.limit)),c.body.sort&&(a={[(o=c.body.sort).sortId]:"asc"===o.type?1:-1},e=e.sort(a)),yield e.toArray());let t=!0;0<d.length&&d.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",c,e)||(t=!1)}),i&&t?l.send({data:d,count:n}):l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Security Configuration"})}catch(e){l.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=o,this.lib=a;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e}}exports.MongoWrapper=MongoWrapper;
|