blixify-server 0.1.33 → 0.1.34

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.
@@ -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<void>;
38
- initGet: (req: any, res: any) => Promise<void>;
39
- initList: (req: any, res: any) => Promise<void>;
40
- initUpdate: (req: any, res: any) => Promise<void>;
41
- initDelete: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<void>;
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,gCAsDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA2CjC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBAwElC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAiFpC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAyDtC;IAEF,IAAI,YA8CF;CACH"}
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,i,o,a,s,d;try{this.modelChecker(r.body.data)?(i=(0,QueryModel_1.checkBaseConfig)(this.config,r),o=(0,QueryModel_1.checkOpsConfig)(this.config,"create",r,r.body.data),i&&o?(a=r.body.data,u&&(yield u(a)),s={boardId:Number(this.boardId),groupId:this.groupId,itemName:null!=(e=r.body.data.name)?e:"Item",columnValues:JSON.stringify(a)},d=(yield(0,exports.queryMondayApi)(this.mondayToken,`
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,null!=(t=r.body)&&t.stopRes||n.send({success:d})):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.initGet=(d,r)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,o,a,s;try{d.body.id?(t=`{
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:${d.body.id}) {
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
- }`,0<(i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items).length?(o=this.parseModel(i[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,d),s=(0,QueryModel_1.checkOpsConfig)(this.config,"read",d,o),a&&s?null!=(e=d.body)&&e.stopRes||r.send({data:o}):r.status(400).json({err:"Invalid Security Configuration"})):r.send({data:null})):r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}}),this.initList=(y,m)=>__awaiter(this,void 0,void 0,function*(){var d;try{var e=(0,QueryModel_1.checkBaseConfig)(this.config,y);if(e){var r=y.body.query;let t=[],i="",o="",a="";if(y.body.limit&&(o="limit: "+y.body.limit),y.body.cursor&&(a="page : "+Number(y.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{
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 c=[];if(t.map(e=>{e=this.parseModel(e);c.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",y,e)||(s=!1)}),e&&s){let e=null;c.length===y.body.limit&&(e=!0),null!=(d=y.body)&&d.stopRes||m.send({data:c,count:e})}else m.status(400).json({err:"Invalid Security Configuration"})}else m.status(400).json({err:"Invalid Fields"})}catch(e){m.status(400).json({err:e})}}),this.initUpdate=(n,u)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(this.modelChecker(n.body.data)&&n.body.id){var t=`{
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:${n.body.id}) {
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,n),s=(0,QueryModel_1.checkOpsConfig)(this.config,"update",n,o);if(a&&s){const d=n.body.data,r={boardId:Number(this.boardId),itemId:Number(n.body.id),columnValues:{}};Object.keys(d).map(t=>{if("id"!==t){var i=this.modelType().write;let e="";(e=i[t]?i[t]:e)?r.columnValues[t]={[e]:d[t]}:r.columnValues[t]=d[t]}}),r.columnValues=JSON.stringify(r.columnValues),yield(0,exports.queryMondayApi)(this.mondayToken,`
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
- `,r),null!=(e=n.body)&&e.stopRes||u.send({success:!0})}else 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.initDelete=(r,n,u)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(r.body.id){var t=`{
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:${r.body.id}) {
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,a=this.parseModel(i[0]),s=(0,QueryModel_1.checkBaseConfig)(this.config,r),d=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,a);s&&d?(u&&(yield u(a)),o={itemId:Number(r.body.id)},yield(0,exports.queryMondayApi)(this.mondayToken,`
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
- `,o),null!=(e=r.body)&&e.stopRes||n.send({success:!0})):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.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;
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<void>;
22
- initCreate: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<void>;
23
- initGet: (req: any, res: any) => Promise<void>;
24
- initBatchUpdate: (req: any, res: any) => Promise<void>;
25
- initUpdate: (req: any, res: any) => Promise<void>;
26
- initBatchDelete: (req: any, res: any, workflow?: ((dataList: any[]) => Promise<any>) | undefined) => Promise<void>;
27
- initDelete: (req: any, res: any, workflow?: ((data: any) => Promise<any>) | undefined) => Promise<void>;
28
- initList: (req: any, res: any) => Promise<void>;
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) => 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,gCAkD5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAiCtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG,mBA+BjC;IAEF,eAAe,QAAe,GAAG,OAAO,GAAG,mBAqIzC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG,mBAkEpC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC,gCAyH5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC,gCAoCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG,mBA2OlC;IAEF,IAAI,YA4EF;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;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,QAAe,GAAG,OAAO,GAAG;;mBAmEpC;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(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 n?t:new n(function(e){e(t)})).then(i,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,s,i,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 i=(0,QueryModel_1.checkBaseConfig)(this.config,r);let s=!0;if(yield Promise.all(r.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",r,e)||(s=!1)})),i&&s){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),s=(0,QueryModel_1.checkOpsConfig)(this.config,"create",a,a.body.data);if(t&&s){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 i={success:!0};if(null!=(e=a.body)&&e.stopRes)return i;o.send(i)}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 s,i=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,i);if(a&&o)return s={data:i},null!=(e=r.body)&&e.stopRes?s:void n.send(s);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,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 h=g.body.isOr?"$or":"$and",y={};var r=this.parseModel(null!=(s=g.body.data)?s:[]),n=(o&&0<o.length&&(y[h]=[],o.some(e=>"search"===e.type)&&(y.$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=>{y.$or.push({[e]:{$regex:i,$options:"i"}})});break;case"=":y[h].push({[s]:i});break;case"!=":y[h].push({[s]:{$ne:i}});break;case">":y[h].push({[s]:{$gt:i}});break;case"<":y[h].push({[s]:{$lt:i}});break;case"><":Array.isArray(i)&&2<=i.length&&(y[h].push({[s]:{$lt:i}}),y[h]={[s]:{$gte:i[0],$lte:i[1]}});break;case"in":y[h].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({},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!=(i=g.body)&&i.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)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{var s=this.modelChecker(c.body.data)&&c.body.id;if(s){var i=this.mongoDB.db(this.tableId).collection(this.collection),a=yield i.findOne({_id:s}),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))){var d=this.parseModel(c.body.data);if(yield i.updateOne({_id:s},{$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{var l=this.parseModel(c.body.data);if(yield i.updateOne({_id:s},{$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,s;try{if(Array.isArray(f.body.id)){var i=this.mongoDB.db(this.tableId).collection(this.collection),a=yield i.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 i.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,s=null!=(t=e.queryId)?t:"";const i=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(y.$or=[],e.searchIds.map(e=>{y.$or.push({[e]:{$regex:i,$options:"i"}})}));break;case"=":y[s]=i;break;case"!=":y[s]={$ne:i};break;case">":y[s]={$gt:i};break;case"<":y[s]={$lt:i};break;case"><":Array.isArray(i)&&2<=i.length&&(y[s]={$gte:i[0],$lte:i[1]});break;case"in":y[s]={$in:i}}});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!=(s=f.body)&&s.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 s=this.mongoDB.db(this.tableId).collection(this.collection),i=yield s.findOne({_id:t}),a=(0,QueryModel_1.checkBaseConfig)(this.config,n),o=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,i);if(a&&o){l&&(yield l(i)),yield s.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,s,i,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,s=null!=(t=e.queryId)?t:"";const i=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(w.$or=[],e.searchIds.map(e=>{w.$or.push({[e]:{$regex:i,$options:"i"}})}));break;case"=":w[s]=i;break;case"!=":w[s]={$ne:i};break;case">":w[s]={$gt:i};break;case"<":w[s]={$lt:i};break;case"><":Array.isArray(i)&&2<=i.length&&(w[s]={$gte:i[0],$lte:i[1]});break;case"in":w[s]={$in:i}}}),l){var u=[],h=null!=(t=l.queryId)?t:"",y=null!=(s=l.dateId)?s:"baseUpdatedAt";for(const Q of null!=(i=l.range)?i:[]){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=s,this.config=i,this.modelChecker=a,this.lib=o;e=this.isProd?"prod":"dev";this.tableId=r?r+"-"+e:e,this.debug=n}}exports.MongoWrapper=MongoWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,