blixify-server 0.1.47 → 0.1.49

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":"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
+ {"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,qDAchB,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;;mBAyDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBA+CjC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;mBAiGlC;IAEF,UAAU,QAAe,GAAG,OAAO,GAAG;;mBAsFpC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBA8DtC;IAEF,IAAI,YA8CF;CACH"}
@@ -1,5 +1,5 @@
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
- mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
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{a(n.next(e))}catch(e){t(e)}}function s(e){try{a(n.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(o,s)}a((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:"","API-version":"2023-10"}})});exports.queryMondayApi=queryMondayApi;class MondayWrapper{constructor(e,t,i,o,s,a,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=(u,l,c)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(u.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,u),o=(0,QueryModel_1.checkOpsConfig)(this.config,"create",u,u.body.data);if(i&&o){var s=u.body.data,a=(c&&(yield c(s)),{boardId:this.boardId,groupId:this.groupId,itemName:null!=(e=u.body.data.name)?e:"Item",columnValues:JSON.stringify(s)}),d=yield(0,exports.queryMondayApi)(this.mondayToken,`
2
+ mutation ($boardId: ID!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
3
3
  create_item (
4
4
  board_id: $boardId,
5
5
  group_id: $groupId,
@@ -9,44 +9,68 @@
9
9
  id
10
10
  }
11
11
  }
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
- boards(ids: ${Number(this.boardId)}) {
14
- items(ids:${r.body.id}) {
15
- id
16
- name
17
- column_values {
12
+ `,a),r=(console.log("see tis",d),d.data.data.create_item.id),n={success:r};if(null!=(t=u.body)&&t.stopRes)return n;l.send(n)}else l.status(400).json({err:"Invalid Security Configuration"})}else l.status(400).json({err:"Invalid Model Structure"})}catch(e){console.log(e),l.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=`query {
13
+ boards(ids: ${this.boardId}) {
14
+ items_page (limit: 1, query_params: {ids:${r.body.id}}) {
15
+ cursor
16
+ items {
18
17
  id
19
- text
20
- value
18
+ name
19
+ column_values {
20
+ id
21
+ text
22
+ value
23
+ }
21
24
  }
22
25
  }
23
26
  }
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{
27
+ }`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items_page.items;if(0<i.length){var o,s=this.parseModel(i[0]),a=(0,QueryModel_1.checkBaseConfig)(this.config,r),d=(0,QueryModel_1.checkOpsConfig)(this.config,"read",r,s);if(a&&d)return o={data:s},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="",s="";if(m.body.limit&&(o="limit: "+m.body.limit),m.body.cursor&&(s="page : "+Number(m.body.cursor)),r&&0<r.length){var n=r[0],u=(o=o&&" , "+o,s=s&&" , "+s,i=`query { items_page_by_column_values (${o} ${s} board_id: ${this.boardId}, columns: [{column_id: "${n.queryId}", column_values: ["${n.value}"]}]) { cursor items {id name column_values {id text value} }}}`,yield(0,exports.queryMondayApi)(this.mondayToken,i));t=u.data.data.items_page_by_column_values.items}else{let e="";e=o&&s?o+" , "+s:o||s,i=e?`query {
25
28
  boards(ids:${this.boardId}){
26
- items(${e}){
29
+ items_page(${e}) {
30
+ cursor
31
+ items {
32
+ id
33
+ name
34
+ column_values {
35
+ id
36
+ text
37
+ value
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }`:`query {
43
+ boards(ids:${this.boardId}){
44
+ items_page {
45
+ cursor
46
+ items {
47
+ id
48
+ name
49
+ column_values {
50
+ id
51
+ text
52
+ value
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }`;var l=yield(0,exports.queryMondayApi)(this.mondayToken,i);t=l.data.data.boards[0].items_page.items}let a=!0;const y=[];if(t.map(e=>{e=this.parseModel(e);y.push(e),(0,QueryModel_1.checkOpsConfig)(this.config,"read",m,e)||(a=!1)}),e&&a){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=`query {
58
+ boards(ids: ${this.boardId}) {
59
+ items_page (limit: 1, query_params: {ids:${u.body.id}}) {
60
+ cursor
61
+ items {
27
62
  id
28
63
  name
29
- column_values{
64
+ column_values {
30
65
  id
31
66
  text
32
67
  value
33
68
  }
34
69
  }
35
70
  }
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
- boards(ids: ${Number(this.boardId)}) {
38
- items(ids:${u.body.id}) {
39
- id
40
- name
41
- column_values {
42
- id
43
- text
44
- value
45
- }
46
- }
47
71
  }
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
- mutation ($boardId: Int!, $itemId: Int!, $columnValues: JSON!) {
72
+ }`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items_page.items;if(i.length<=0)throw"Error";var o=this.parseModel(i[0]),s=(0,QueryModel_1.checkBaseConfig)(this.config,u),a=(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,o);if(s&&a){const r=u.body.data,n={boardId:this.boardId,itemId: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,`
73
+ mutation ($boardId: ID!, $itemId: ID!, $columnValues: JSON!) {
50
74
  change_multiple_column_values(
51
75
  item_id: $itemId,
52
76
  board_id: $boardId,
@@ -55,22 +79,25 @@
55
79
  id
56
80
  }
57
81
  }
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
- boards(ids: ${Number(this.boardId)}) {
60
- items(ids:${n.body.id}) {
61
- id
62
- name
63
- column_values {
82
+ `,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=`query {
83
+ boards(ids: ${this.boardId}) {
84
+ items_page (limit: 1, query_params: {ids:${n.body.id}}) {
85
+ cursor
86
+ items {
64
87
  id
65
- text
66
- value
88
+ name
89
+ column_values {
90
+ id
91
+ text
92
+ value
93
+ }
67
94
  }
68
95
  }
69
96
  }
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
- mutation ($itemId: Int!){
97
+ }`,i=(yield(0,exports.queryMondayApi)(this.mondayToken,t)).data.data.boards[0].items_page.items;if(i.length<=0)throw"Error";var o=this.parseModel(i[0]),s=(0,QueryModel_1.checkBaseConfig)(this.config,n),a=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",n,o);if(s&&a){l&&(yield l(o));var d={itemId:n.body.id},r=(yield(0,exports.queryMondayApi)(this.mondayToken,`
98
+ mutation ($itemId: ID!){
72
99
  delete_item (item_id: $itemId) {
73
100
  id
74
101
  }
75
102
  }
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;
103
+ `,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=s,this.modelType=a,this.lib=d}}exports.MondayWrapper=MondayWrapper;
@@ -1 +1 @@
1
- {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,SAAM;IACb,KAAK,EAAE,GAAG,CAAC;IAEX,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI;IAa3D,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBAyE5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAgDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBAgCjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAiJtC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAuFtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBA6H5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAqCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBA2OlC;IAEF,IAAI,YA+EF;CACH"}
1
+ {"version":3,"file":"mongoWrapper.d.ts","sourceRoot":"","sources":["../../src/apis/mongoWrapper.ts"],"names":[],"mappings":"AAQA,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAGrD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,EAAE,GAAG,CAAM;IAClB,UAAU,SAAM;IAChB,MAAM,UAAS;IACf,MAAM,EAAE,cAAc,CAQpB;IACF,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,SAAM;IACb,KAAK,EAAE,GAAG,CAAC;IAEX,YAAY,QAAS,GAAG,aAEtB;gBAGA,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,EACrD,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI;IAa3D,UAAU,SAAU,GAAG,SAIrB;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBAyE5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAgDtC;IAEF,OAAO,QAAe,GAAG,OAAO,GAAG;;mBAgCjC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAmJtC;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAuFtC;IAEF,eAAe,QACR,GAAG,OACH,GAAG,yBACc,GAAG,EAAE,KAAK,QAAQ,GAAG,CAAC;;mBA6H5C;IAEF,UAAU,QACH,GAAG,OACH,GAAG,qBACU,GAAG,KAAK,QAAQ,GAAG,CAAC;;mBAqCtC;IAEF,QAAQ,QAAe,GAAG,OAAO,GAAG;;;;;mBA2OlC;IAEF,IAAI,YA+EF;CACH"}
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,d){return new(r=r||Promise)(function(i,t){function s(e){try{a(d.next(e))}catch(e){t(e)}}function o(e){try{a(d.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,o)}a((d=d.apply(e,n||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=void 0;const moment_timezone_1=__importDefault(require("moment-timezone")),QueryModel_1=require("../model/QueryModel"),utils_1=require("./utils");class MongoWrapper{constructor(e,t,i,s,o,a,n,r){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.tableId="",this.modelChecker=e=>!1,this.parseModel=e=>(delete e._id,e.baseUpdatedAt=(0,moment_timezone_1.default)().toDate(),e),this.initBatchCreate=(u,c,h)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(Array.isArray(u.body.data)){let t=!0;u.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||c.status(400).json({err:"Invalid Model Structure"});var s=(0,QueryModel_1.checkBaseConfig)(this.config,u);let i=!0;const d=[];if(yield Promise.all(u.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,e)||(i=!1),u.body.unique&&null!=e&&e[u.body.unique]&&d.push(e[u.body.unique])})),s&&i){var o=this.mongoDB.db(this.tableId).collection(this.collection);if(0<d.length){var a=yield(yield o.find({[u.body.unique]:{$in:d}})).toArray();if(0<a.length)return void c.status(400).json({err:`Unique:${a.map(e=>e[u.body.unique])} exists`})}const l=[];var n=u.body.data.map(e=>(l.push(e._id),Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_timezone_1.default)().toDate()}))),r=(h&&(yield h(n)),yield o.insertMany(n),{success:l});if(null!=(e=u.body)&&e.stopRes)return r;c.send(r)}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initCreate=(n,r,d)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(n.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,n),s=(0,QueryModel_1.checkOpsConfig)(this.config,"create",n,n.body.data);if(i&&s){var o=this.mongoDB.db(this.tableId).collection(this.collection);if(n.body.data.baseUpdatedAt=(0,moment_timezone_1.default)().toDate(),n.body.unique&&null!=(e=n.body.data)&&e[n.body.unique])if(yield o.findOne({[n.body.unique]:n.body.data[n.body.unique]}))return void r.status(400).json({err:`Unique:${n.body.data[n.body.unique]} exists`});d&&(yield d(n.body.data)),yield o.insertOne(n.body.data);var a={success:!0};if(null!=(t=n.body)&&t.stopRes)return a;r.send(a)}else r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initGet=(n,r)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=n.body.id;if(t){var i,s=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:t}),o=(0,QueryModel_1.checkBaseConfig)(this.config,n),a=(0,QueryModel_1.checkOpsConfig)(this.config,"read",n,s);if(o&&a)return i={data:s},null!=(e=n.body)&&e.stopRes?i:void r.send(i);r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}}),this.initBatchUpdate=(p,m,v)=>__awaiter(this,void 0,void 0,function*(){var e,i,s;try{if(this.modelChecker(p.body.data)&&p.body.query){var o=p.body.unsetData,a=null!=(e=p.body.query)?e:[];const y=p.body.isOr?"$or":"$and",b={};var n=this.parseModel(null!=(i=p.body.data)?i:[]),r=(a&&0<a.length&&(b[y]=[],a.some(e=>"search"===e.type)&&(b.$or=[]),a.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&e.searchIds.map(e=>{b.$or.push({[e]:{$regex:s,$options:"i"}})});break;case"=":b[y].push({[i]:s});break;case"!=":b[y].push({[i]:{$ne:s}});break;case">":b[y].push({[i]:{$gt:s}});break;case"<":b[y].push({[i]:{$lt:s}});break;case"><":Array.isArray(s)&&2<=s.length&&(b[y].push({[i]:{$lt:s}}),b[y]={[i]:{$gte:s[0],$lte:s[1]}});break;case"in":b[y].push({[i]:{$in:s}})}})),(0,QueryModel_1.checkBaseConfig)(this.config,p));let t=!0;var d=this.mongoDB.db(this.tableId).collection(this.collection),l=yield(yield d.find(Object.assign({},b))).toArray();const f=[];if(yield Promise.all(l.map(e=>{p.body.sensitive&&!(0,moment_timezone_1.default)(p.body.data.baseUpdatedAt).isAfter((0,moment_timezone_1.default)(e.baseUpdatedAt))&&m.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",p,e)||(t=!1);e=(0,utils_1.compareUpdatedFields)(e,p.body.data).workflowUpdateFields;f.concat(e)})),r&&t){const g={};var u={},c=(o&&(o.forEach(e=>{g[e]=""}),u.$unset=Object.assign({},g)),n&&(u.$set=Object.assign({},n)),v&&(yield v(f)),yield d.updateMany(b,u),f.map(e=>e._id)),h={success:c};if(null!=(s=p.body)&&s.stopRes)return h;m.send(h)}else m.status(400).json({err:"Invalid Security Configuration"})}}catch(e){m.status(400).json({err:e})}}),this.initUpdate=(y,b,f)=>__awaiter(this,void 0,void 0,function*(){var e,t,i;try{var s=this.modelChecker(y.body.data)&&y.body.id;if(s){var o=this.mongoDB.db(this.tableId).collection(this.collection),a=yield o.findOne({_id:s}),n=(this.debug&&this.debug(y.body,a),(0,QueryModel_1.checkBaseConfig)(this.config,y)),r=(0,QueryModel_1.checkOpsConfig)(this.config,"update",y,a);if(n&&r){if(y.body.unique&&null!=(e=y.body.data)&&e[y.body.unique]){var d=yield o.findOne({[y.body.unique]:y.body.data[y.body.unique]});if(d&&y.body.id!==d._id)return void b.status(400).json({err:y.body.data[y.body.unique]+" exists"})}var{workflowUpdateFields:l,updatedFields:u}=(0,utils_1.compareUpdatedFields)(a,y.body.data),c={success:!0},h=(f&&(yield f(l)),this.parseModel(u));if(y.body.sensitive)if((0,moment_timezone_1.default)(y.body.data.baseUpdatedAt).isAfter((0,moment_timezone_1.default)(a.baseUpdatedAt))){if(yield o.updateOne({_id:s},{$set:Object.assign({},h)}),null!=(t=y.body)&&t.stopRes)return c;b.send(c)}else b.status(400).json({err:"Refresh Sensitive Model"});else{if(yield o.updateOne({_id:s},{$set:Object.assign({},h)}),null!=(i=y.body)&&i.stopRes)return c;b.send(c)}}else b.status(400).json({err:"Invalid Security Configuration"})}else b.status(400).json({err:"Invalid Model Structure"})}catch(e){this.debug&&this.debug(null,null,e),b.status(400).json({err:e})}}),this.initBatchDelete=(f,g,p)=>__awaiter(this,void 0,void 0,function*(){var e,i;try{if(Array.isArray(f.body.id)){var s=this.mongoDB.db(this.tableId).collection(this.collection),o=yield s.find({_id:{$in:f.body.id}}),a=(0,QueryModel_1.checkBaseConfig)(this.config,f),n=yield o.toArray();let t=!0;if(0<n.length&&(yield Promise.all(n.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",f,e)||(t=!1)}))),a&&t){p&&(yield p(n)),yield s.deleteMany({_id:{$in:f.body.id}});var r={success:f.body.id};if(null!=(e=f.body)&&e.stopRes)return r;g.send(r)}else g.status(400).json({err:"Invalid Security Configuration"})}else{var d=f.body.query;const y={};d&&0<d.length&&d.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(y.$or=[],e.searchIds.map(e=>{y.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":y[i]=s;break;case"!=":y[i]={$ne:s};break;case">":y[i]={$gt:s};break;case"<":y[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(y[i]={$gte:s[0],$lte:s[1]});break;case"in":y[i]={$in:s}}});var l=this.mongoDB.db(this.tableId).collection(this.collection),u=yield l.find(y).toArray(),c=(0,QueryModel_1.checkBaseConfig)(this.config,f);let t=!0;const b=[];if(0<u.length&&u.map(e=>{b.push(e._id),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",f,e)||(t=!1)}),p&&(yield p(u)),c&&t){yield l.deleteMany(y);var h={success:b};if(null!=(i=f.body)&&i.stopRes)return h;g.send(h)}else g.status(400).json({err:"Invalid Security Configuration"})}}catch(e){g.status(400).json({err:e})}}),this.initDelete=(r,d,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=r.body.id;if(t){var i=this.mongoDB.db(this.tableId).collection(this.collection),s=yield i.findOne({_id:t}),o=(0,QueryModel_1.checkBaseConfig)(this.config,r),a=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,s);if(o&&a){l&&(yield l(s)),yield i.findOneAndDelete({_id:t});var n={success:!0};if(null!=(e=r.body)&&e.stopRes)return n;d.send(n)}else d.status(400).json({err:"Invalid Security Configuration"})}else d.status(400).json({err:"Invalid Fields"})}catch(e){d.status(400).json({err:e})}}),this.initList=(U,z)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,o,a,n,r,d;try{var l=(0,QueryModel_1.checkBaseConfig)(this.config,U);if(l){var u=U.body.aggregate,c=null!=(e=U.body.query)?e:[];const w={};if(c&&0<c.length&&c.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(w.$or=[],e.searchIds.map(e=>{w.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":w[i]=s;break;case"!=":w[i]={$ne:s};break;case">":w[i]={$gt:s};break;case"<":w[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(w[i]={$gte:s[0],$lte:s[1]});break;case"in":w[i]={$in:s}}}),u){var h=[],y=null!=(t=u.queryId)?t:"",b=null!=(i=u.dateId)?i:"baseUpdatedAt";for(const Q of null!=(s=u.range)?s:[]){Object.assign({},w);var f=Q.split("-"),[g,p=(0,moment_timezone_1.default)().format("DD/MM/YYYY HH:mm:ss")]=f,m=2===f.length,v=(0,moment_timezone_1.default)(g,"DD/MM/YYYY").isValid(),_=(0,moment_timezone_1.default)(p,"DD/MM/YYYY").isValid(),$=(0,moment_timezone_1.default)(g,"DD/MM/YYYY HH:mm:ss").tz("Asia/Kuala_lumpur").toDate(),M=(0,moment_timezone_1.default)(p,"DD/MM/YYYY HH:mm:ss").tz("Asia/Kuala_lumpur").toDate();if(!v||!_)return void z.status(400).json({err:"Invalid Aggregate Range Configuration"});var k=m?{$match:Object.assign(Object.assign({},w),{[b]:{$gte:$,$lte:M}})}:{$match:Object.assign(Object.assign({},w),{[b]:{$lte:$}})},I=[];let e=!1;var j=m?Q:"Begining until "+(0,moment_timezone_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("DD/MM/YYYY");switch(u.type){case"avg":I.push(k,{$group:{_id:j,value:{$avg:"$"+y}}});break;case"sum":I.push(k,{$group:{_id:j,value:{$sum:"$"+y}}});break;case"count":e=!0}if(0===I.length&&!e)return void z.status(400).json({err:"Invalid Aggregate Configuration"});var C=this.mongoDB.db(this.tableId).collection(this.collection);let t=0;t=e?yield C.find(k.$match).count({}):null!=(a=null==(o=(yield C.aggregate(I).toArray())[0])?void 0:o.value)?a:0,h.push({_id:j,value:t})}var D={data:h};if(null!=(n=U.body)&&n.stopRes)return D;z.send(D)}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(w);var O,A,q,B=yield e.count({}),Y=(U.body.cursor&&(e=e.skip(U.body.cursor)),U.body.stopLimit||(e=e.limit(null!=(r=U.body.limit)?r:10)),U.body.sort&&(A={[(O=U.body.sort).sortId]:"asc"===O.type?1:-1},e=e.sort(A)),yield e.toArray());let t=!0;if(0<Y.length&&Y.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",U,e)||(t=!1)}),l&&t)return q={data:Y,count:B},null!=(d=U.body)&&d.stopRes?q:void z.send(q);z.status(400).json({err:"Invalid Security Configuration"})}}else z.status(400).json({err:"Invalid Security Configuration"})}catch(e){z.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.mongoDB=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=a;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e,this.debug=r}}exports.MongoWrapper=MongoWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,d){return new(r=r||Promise)(function(i,t){function s(e){try{a(d.next(e))}catch(e){t(e)}}function o(e){try{a(d.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,o)}a((d=d.apply(e,n||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MongoWrapper=void 0;const moment_timezone_1=__importDefault(require("moment-timezone")),QueryModel_1=require("../model/QueryModel"),utils_1=require("./utils");class MongoWrapper{constructor(e,t,i,s,o,a,n,r){this.mongoDB="",this.collection="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.tableId="",this.modelChecker=e=>!1,this.parseModel=e=>(delete e._id,e.baseUpdatedAt=(0,moment_timezone_1.default)().toDate(),e),this.initBatchCreate=(u,c,h)=>__awaiter(this,void 0,void 0,function*(){var e;try{if(Array.isArray(u.body.data)){let t=!0;u.body.data.map(e=>{this.modelChecker(e)||(t=!1)}),t||c.status(400).json({err:"Invalid Model Structure"});var s=(0,QueryModel_1.checkBaseConfig)(this.config,u);let i=!0;const d=[];if(yield Promise.all(u.body.data.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"update",u,e)||(i=!1),u.body.unique&&null!=e&&e[u.body.unique]&&d.push(e[u.body.unique])})),s&&i){var o=this.mongoDB.db(this.tableId).collection(this.collection);if(0<d.length){var a=yield(yield o.find({[u.body.unique]:{$in:d}})).toArray();if(0<a.length)return void c.status(400).json({err:`Unique:${a.map(e=>e[u.body.unique])} exists`})}const l=[];var n=u.body.data.map(e=>(l.push(e._id),Object.assign(Object.assign({},e),{baseUpdatedAt:(0,moment_timezone_1.default)().toDate()}))),r=(h&&(yield h(n)),yield o.insertMany(n),{success:l});if(null!=(e=u.body)&&e.stopRes)return r;c.send(r)}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initCreate=(n,r,d)=>__awaiter(this,void 0,void 0,function*(){var e,t;try{if(this.modelChecker(n.body.data)){var i=(0,QueryModel_1.checkBaseConfig)(this.config,n),s=(0,QueryModel_1.checkOpsConfig)(this.config,"create",n,n.body.data);if(i&&s){var o=this.mongoDB.db(this.tableId).collection(this.collection);if(n.body.data.baseUpdatedAt=(0,moment_timezone_1.default)().toDate(),n.body.unique&&null!=(e=n.body.data)&&e[n.body.unique])if(yield o.findOne({[n.body.unique]:n.body.data[n.body.unique]}))return void r.status(400).json({err:`Unique:${n.body.data[n.body.unique]} exists`});d&&(yield d(n.body.data)),yield o.insertOne(n.body.data);var a={success:!0};if(null!=(t=n.body)&&t.stopRes)return a;r.send(a)}else r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Model Structure"})}catch(e){r.status(400).json({err:e})}}),this.initGet=(n,r)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=n.body.id;if(t){var i,s=yield this.mongoDB.db(this.tableId).collection(this.collection).findOne({_id:t}),o=(0,QueryModel_1.checkBaseConfig)(this.config,n),a=(0,QueryModel_1.checkOpsConfig)(this.config,"read",n,s);if(o&&a)return i={data:s},null!=(e=n.body)&&e.stopRes?i:void r.send(i);r.status(400).json({err:"Invalid Security Configuration"})}else r.status(400).json({err:"Invalid Fields"})}catch(e){r.status(400).json({err:e})}}),this.initBatchUpdate=(p,m,v)=>__awaiter(this,void 0,void 0,function*(){var e,i,s;try{if(this.modelChecker(p.body.data)&&p.body.query||p.body.unsetData){var o=p.body.unsetData,a=null!=(e=p.body.query)?e:[];const y=p.body.isOr?"$or":"$and",b={};var n=this.parseModel(null!=(i=p.body.data)?i:[]),r=(a&&0<a.length&&(b[y]=[],a.some(e=>"search"===e.type)&&(b.$or=[]),a.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&e.searchIds.map(e=>{b.$or.push({[e]:{$regex:s,$options:"i"}})});break;case"=":b[y].push({[i]:s});break;case"!=":b[y].push({[i]:{$ne:s}});break;case">":b[y].push({[i]:{$gt:s}});break;case"<":b[y].push({[i]:{$lt:s}});break;case"><":Array.isArray(s)&&2<=s.length&&(b[y].push({[i]:{$lt:s}}),b[y]={[i]:{$gte:s[0],$lte:s[1]}});break;case"in":b[y].push({[i]:{$in:s}})}})),(0,QueryModel_1.checkBaseConfig)(this.config,p));let t=!0;var d=this.mongoDB.db(this.tableId).collection(this.collection),l=yield(yield d.find(Object.assign({},b))).toArray();const f=[];if(yield Promise.all(l.map(e=>{p.body.sensitive&&!(0,moment_timezone_1.default)(p.body.data.baseUpdatedAt).isAfter((0,moment_timezone_1.default)(e.baseUpdatedAt))&&m.status(400).json({err:"Refresh Sensitive Model"}),(0,QueryModel_1.checkOpsConfig)(this.config,"update",p,e)||(t=!1);e=(0,utils_1.compareUpdatedFields)(e,p.body.data).workflowUpdateFields;f.concat(e)})),r&&t){const g={};var u={},c=(o&&(o.forEach(e=>{g[e]=""}),u.$unset=Object.assign({},g)),n&&(u.$set=Object.assign({},n)),v&&(yield v(f)),yield d.updateMany(b,u),f.map(e=>e._id)),h={success:c};if(null!=(s=p.body)&&s.stopRes)return h;m.send(h)}else m.status(400).json({err:"Invalid Security Configuration"})}}catch(e){m.status(400).json({err:e})}}),this.initUpdate=(y,b,f)=>__awaiter(this,void 0,void 0,function*(){var e,t,i;try{var s=this.modelChecker(y.body.data)&&y.body.id;if(s){var o=this.mongoDB.db(this.tableId).collection(this.collection),a=yield o.findOne({_id:s}),n=(this.debug&&this.debug(y.body,a),(0,QueryModel_1.checkBaseConfig)(this.config,y)),r=(0,QueryModel_1.checkOpsConfig)(this.config,"update",y,a);if(n&&r){if(y.body.unique&&null!=(e=y.body.data)&&e[y.body.unique]){var d=yield o.findOne({[y.body.unique]:y.body.data[y.body.unique]});if(d&&y.body.id!==d._id)return void b.status(400).json({err:y.body.data[y.body.unique]+" exists"})}var{workflowUpdateFields:l,updatedFields:u}=(0,utils_1.compareUpdatedFields)(a,y.body.data),c={success:!0},h=(f&&(yield f(l)),this.parseModel(u));if(y.body.sensitive)if((0,moment_timezone_1.default)(y.body.data.baseUpdatedAt).isAfter((0,moment_timezone_1.default)(a.baseUpdatedAt))){if(yield o.updateOne({_id:s},{$set:Object.assign({},h)}),null!=(t=y.body)&&t.stopRes)return c;b.send(c)}else b.status(400).json({err:"Refresh Sensitive Model"});else{if(yield o.updateOne({_id:s},{$set:Object.assign({},h)}),null!=(i=y.body)&&i.stopRes)return c;b.send(c)}}else b.status(400).json({err:"Invalid Security Configuration"})}else b.status(400).json({err:"Invalid Model Structure"})}catch(e){this.debug&&this.debug(null,null,e),b.status(400).json({err:e})}}),this.initBatchDelete=(f,g,p)=>__awaiter(this,void 0,void 0,function*(){var e,i;try{if(Array.isArray(f.body.id)){var s=this.mongoDB.db(this.tableId).collection(this.collection),o=yield s.find({_id:{$in:f.body.id}}),a=(0,QueryModel_1.checkBaseConfig)(this.config,f),n=yield o.toArray();let t=!0;if(0<n.length&&(yield Promise.all(n.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"delete",f,e)||(t=!1)}))),a&&t){p&&(yield p(n)),yield s.deleteMany({_id:{$in:f.body.id}});var r={success:f.body.id};if(null!=(e=f.body)&&e.stopRes)return r;g.send(r)}else g.status(400).json({err:"Invalid Security Configuration"})}else{var d=f.body.query;const y={};d&&0<d.length&&d.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(y.$or=[],e.searchIds.map(e=>{y.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":y[i]=s;break;case"!=":y[i]={$ne:s};break;case">":y[i]={$gt:s};break;case"<":y[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(y[i]={$gte:s[0],$lte:s[1]});break;case"in":y[i]={$in:s}}});var l=this.mongoDB.db(this.tableId).collection(this.collection),u=yield l.find(y).toArray(),c=(0,QueryModel_1.checkBaseConfig)(this.config,f);let t=!0;const b=[];if(0<u.length&&u.map(e=>{b.push(e._id),(0,QueryModel_1.checkOpsConfig)(this.config,"delete",f,e)||(t=!1)}),p&&(yield p(u)),c&&t){yield l.deleteMany(y);var h={success:b};if(null!=(i=f.body)&&i.stopRes)return h;g.send(h)}else g.status(400).json({err:"Invalid Security Configuration"})}}catch(e){g.status(400).json({err:e})}}),this.initDelete=(r,d,l)=>__awaiter(this,void 0,void 0,function*(){var e;try{var t=r.body.id;if(t){var i=this.mongoDB.db(this.tableId).collection(this.collection),s=yield i.findOne({_id:t}),o=(0,QueryModel_1.checkBaseConfig)(this.config,r),a=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",r,s);if(o&&a){l&&(yield l(s)),yield i.findOneAndDelete({_id:t});var n={success:!0};if(null!=(e=r.body)&&e.stopRes)return n;d.send(n)}else d.status(400).json({err:"Invalid Security Configuration"})}else d.status(400).json({err:"Invalid Fields"})}catch(e){d.status(400).json({err:e})}}),this.initList=(U,z)=>__awaiter(this,void 0,void 0,function*(){var e,t,i,s,o,a,n,r,d;try{var l=(0,QueryModel_1.checkBaseConfig)(this.config,U);if(l){var u=U.body.aggregate,c=null!=(e=U.body.query)?e:[];const w={};if(c&&0<c.length&&c.map(e=>{var t,i=null!=(t=e.queryId)?t:"";const s=e.value;switch(e.type){case"search":e.searchIds&&0<e.searchIds.length&&(w.$or=[],e.searchIds.map(e=>{w.$or.push({[e]:{$regex:s,$options:"i"}})}));break;case"=":w[i]=s;break;case"!=":w[i]={$ne:s};break;case">":w[i]={$gt:s};break;case"<":w[i]={$lt:s};break;case"><":Array.isArray(s)&&2<=s.length&&(w[i]={$gte:s[0],$lte:s[1]});break;case"in":w[i]={$in:s}}}),u){var h=[],y=null!=(t=u.queryId)?t:"",b=null!=(i=u.dateId)?i:"baseUpdatedAt";for(const Q of null!=(s=u.range)?s:[]){Object.assign({},w);var f=Q.split("-"),[g,p=(0,moment_timezone_1.default)().format("DD/MM/YYYY HH:mm:ss")]=f,m=2===f.length,v=(0,moment_timezone_1.default)(g,"DD/MM/YYYY").isValid(),_=(0,moment_timezone_1.default)(p,"DD/MM/YYYY").isValid(),$=(0,moment_timezone_1.default)(g,"DD/MM/YYYY HH:mm:ss").tz("Asia/Kuala_lumpur").toDate(),M=(0,moment_timezone_1.default)(p,"DD/MM/YYYY HH:mm:ss").tz("Asia/Kuala_lumpur").toDate();if(!v||!_)return void z.status(400).json({err:"Invalid Aggregate Range Configuration"});var k=m?{$match:Object.assign(Object.assign({},w),{[b]:{$gte:$,$lte:M}})}:{$match:Object.assign(Object.assign({},w),{[b]:{$lte:$}})},I=[];let e=!1;var j=m?Q:"Begining until "+(0,moment_timezone_1.default)(g,"DD/MM/YYYY HH:mm:ss").format("DD/MM/YYYY");switch(u.type){case"avg":I.push(k,{$group:{_id:j,value:{$avg:"$"+y}}});break;case"sum":I.push(k,{$group:{_id:j,value:{$sum:"$"+y}}});break;case"count":e=!0}if(0===I.length&&!e)return void z.status(400).json({err:"Invalid Aggregate Configuration"});var C=this.mongoDB.db(this.tableId).collection(this.collection);let t=0;t=e?yield C.find(k.$match).count({}):null!=(a=null==(o=(yield C.aggregate(I).toArray())[0])?void 0:o.value)?a:0,h.push({_id:j,value:t})}var D={data:h};if(null!=(n=U.body)&&n.stopRes)return D;z.send(D)}else{let e=this.mongoDB.db(this.tableId).collection(this.collection).find(w);var O,A,q,B=yield e.count({}),Y=(U.body.cursor&&(e=e.skip(U.body.cursor)),U.body.stopLimit||(e=e.limit(null!=(r=U.body.limit)?r:10)),U.body.sort&&(A={[(O=U.body.sort).sortId]:"asc"===O.type?1:-1},e=e.sort(A)),yield e.toArray());let t=!0;if(0<Y.length&&Y.map(e=>{(0,QueryModel_1.checkOpsConfig)(this.config,"read",U,e)||(t=!1)}),l&&t)return q={data:Y,count:B},null!=(d=U.body)&&d.stopRes?q:void z.send(q);z.status(400).json({err:"Invalid Security Configuration"})}}else z.status(400).json({err:"Invalid Security Configuration"})}catch(e){z.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return e.post("/create",(e,t)=>{this.initCreate(e,t)}),e.post("/batchCreate",(e,t)=>{this.initBatchCreate(e,t)}),e.post("/get",(e,t)=>{this.initGet(e,t)}),e.post("/update",(e,t)=>{this.initUpdate(e,t)}),e.post("/batchUpdate",(e,t)=>{this.initBatchUpdate(e,t)}),e.post("/delete",(e,t)=>{this.initDelete(e,t)}),e.post("/batchDelete",(e,t)=>{this.initBatchDelete(e,t)}),e.post("/list",(e,t)=>{this.initList(e,t)}),e},this.mongoDB=e,this.collection=t,this.isProd=i,this.config=s,this.modelChecker=o,this.lib=a;e=this.isProd?"prod":"dev";this.tableId=n?n+"-"+e:e,this.debug=r}}exports.MongoWrapper=MongoWrapper;
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,l){return new(r=r||Promise)(function(i,t){function s(e){try{a(l.next(e))}catch(e){t(e)}}function o(e){try{a(l.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,o)}a((l=l.apply(e,n||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UploadWrapper=void 0;const QueryModel_1=require("../model/QueryModel"),axios_1=__importDefault(require("axios")),mime_1=__importDefault(require("mime"));class UploadWrapper{constructor(e,t,i,s,o){this.uploadAdmin="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.storageType="firebase",this.modelChecker=(e,t)=>!(!e.assetCollectionName||!e.assetParentId||!t&&!e.assetFileName),this.initUpload=(d,c,u)=>__awaiter(this,void 0,void 0,function*(){try{const l=d.body.data;if(this.modelChecker(l)&&(d.file||l.downloadLink)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,u,d,l);if(e&&t){const n=this.lib.randomUUID();if("aws"===this.storageType){var i,s=(n,r)=>new Promise((o,a)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===n,t=new this.uploadAdmin.S3;let i;e||(s=d.file.originalname.split(".").pop(),i="mbtiles"===s?"application/vnd.mapbox-vector-tile":mime_1.default.getType(s)||d.file.mimetype);var s={Bucket:`${l.bucketName}/${l.assetCollectionName}/`+l.assetParentId,Key:e?l.assetFileName:d.file.originalname,Body:e?r.data:d.file.buffer,ContentType:e?r.headers["content-type"]:i};t.upload(s,function(e){e?a(e):o("aws")})}));l.downloadLink?(i=yield(0,axios_1.default)({method:"GET",url:l.downloadLink,responseType:"arraybuffer"})).data&&(yield s("buffer",i)):yield s("file")}else{const r=this.uploadAdmin.storage().bucket();var o,a=(o,a)=>new Promise((i,s)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===o,t={contentType:e?a.headers["content-type"]:d.file.mimetype,customMetadata:{"file-name":"buffer"===o?l.assetFileName:d.file.originalname},metadata:{firebaseStorageDownloadTokens:n}},t=r.file(`${l.assetCollectionName}/${l.assetParentId}/`+l.assetFileName).createWriteStream({metadata:t});t.end(e?a.data:d.file.buffer),t.on("error",s),t.on("finish",i)}));l.downloadLink?(o=yield(0,axios_1.default)({method:"GET",url:l.downloadLink,responseType:"arraybuffer"})).data&&(yield a("buffer",o)):yield a("file")}c.send({data:n})}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initDelete=(a,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=a.body.data;this.modelChecker(o)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,a),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",a,o),e&&t?("aws"===this.storageType?(i=new this.uploadAdmin.S3,s={Bucket:`${o.bucketName}/${o.assetCollectionName}/`+o.assetParentId,Key:o.assetFileName},yield i.deleteObject(s).promise()):yield this.uploadAdmin.storage().bucket().file(`${o.assetCollectionName}/${o.assetParentId}/`+o.assetFileName).delete(),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.deleteGoogleFolderContents=a=>__awaiter(this,void 0,void 0,function*(){try{var e={prefix:a.name,autoPaginate:!1},[t]=yield this.uploadAdmin.storage().bucket().getFiles(e),i=[];for(const s of t)i.push(s.delete());for(const o of t)o.name.endsWith("/")&&i.push(this.deleteGoogleFolderContents(o));yield Promise.all(i)}catch(e){}}),this.deleteAWSFolderContent=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e=new this.uploadAdmin.S3,t=(yield e.listObjectsV2({Bucket:o,Prefix:a}).promise()).Contents.map(e=>e.Key),i=[];for(const s of t)i.push(e.deleteObject({Bucket:o,Key:s}).promise());yield Promise.all(i)}catch(e){}}),this.initDeleteDirectory=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=o.body.data;this.modelChecker(s,!0)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,s),e&&t?("aws"===this.storageType?yield this.deleteAWSFolderContent(""+s.bucketName,`${s.assetCollectionName}/${s.assetParentId}/`):(i=this.uploadAdmin.storage().bucket().file(`${s.assetCollectionName}/${s.assetParentId}/`),yield this.deleteGoogleFolderContents(i)),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.initBatchDeleteDirectory=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{const s=o.body.data;var e,t,i=JSON.parse(s.assetParentId);this.modelChecker(s,!0)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,s),e&&t?(yield Promise.all(i.map(t=>__awaiter(this,void 0,void 0,function*(){var e;"aws"===this.storageType?yield this.deleteAWSFolderContent(""+s.bucketName,s.assetCollectionName+`/${t}/`):(e=this.uploadAdmin.storage().bucket().file(s.assetCollectionName+`/${t}/`),yield this.deleteGoogleFolderContents(e))}))),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.initGet=(n,r)=>__awaiter(this,void 0,void 0,function*(){try{const{bucketName:e,assetCollectionName:t,assetParentId:i,fileName:s}=n.params;if("aws"===this.storageType){const o=new this.uploadAdmin.S3,a={Bucket:e,Key:t+`/${i}/`+s};o.headObject(a,e=>__awaiter(this,void 0,void 0,function*(){if(e&&"NotFound"===e.code)r.status(404).send({message:"File not found"});else{var t=yield o.getObject(a).promise(),i=s.split(".").pop();let e;e="mbtiles"===i?"application/vnd.mapbox-vector-tile":mime_1.default.getType(i)||t.ContentType,r.set("Content-Type",e),r.send(t.Body)}}))}}catch(e){r.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return this.lib.cors&&e.use(this.lib.cors()),e.post("/upload",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"create")}),e.post("/update",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"update")}),e.post("/delete",this.initDelete),e.post("/deleteDirectory",this.initDeleteDirectory),e.post("/batchDeleteDirectory",this.initBatchDeleteDirectory),e.get("/get/:bucketName/:assetCollectionName/:assetParentId/:fileName",this.initGet),e},this.uploadAdmin=e,this.isProd=t,this.config=i,this.lib=s,this.storageType=null!=o?o:"firebase"}}exports.UploadWrapper=UploadWrapper;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,l){return new(r=r||Promise)(function(i,t){function s(e){try{a(l.next(e))}catch(e){t(e)}}function o(e){try{a(l.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?i(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(s,o)}a((l=l.apply(e,n||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UploadWrapper=void 0;const QueryModel_1=require("../model/QueryModel"),axios_1=__importDefault(require("axios")),mime_1=__importDefault(require("mime"));class UploadWrapper{constructor(e,t,i,s,o){this.uploadAdmin="",this.isProd=!1,this.config={baseConfig:[],opsConfig:{read:[],create:[],update:[],delete:[]}},this.storageType="firebase",this.modelChecker=(e,t)=>!(!e.assetCollectionName||!e.assetParentId||!t&&!e.assetFileName),this.initUpload=(d,c,u)=>__awaiter(this,void 0,void 0,function*(){try{const l=d.body.data;if(this.modelChecker(l)&&(d.file||l.downloadLink)){var e=(0,QueryModel_1.checkBaseConfig)(this.config,d),t=(0,QueryModel_1.checkOpsConfig)(this.config,u,d,l);if(e&&t){const n=this.lib.randomUUID();if("aws"===this.storageType){var i,s=(n,r)=>new Promise((o,a)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===n,t=new this.uploadAdmin.S3;let i;e||(s=d.file.originalname.split(".").pop(),i="mbtiles"===s?"application/vnd.mapbox-vector-tile":mime_1.default.getType(s)||d.file.mimetype);var s={Bucket:`${l.bucketName}/${l.assetCollectionName}/`+l.assetParentId,Key:l.assetFileName,Body:e?r.data:d.file.buffer,ContentType:e?r.headers["content-type"]:i};t.upload(s,function(e){e?a(e):o("aws")})}));l.downloadLink?(i=yield(0,axios_1.default)({method:"GET",url:l.downloadLink,responseType:"arraybuffer"})).data&&(yield s("buffer",i)):yield s("file")}else{const r=this.uploadAdmin.storage().bucket();var o,a=(o,a)=>new Promise((i,s)=>__awaiter(this,void 0,void 0,function*(){var e="buffer"===o,t={contentType:e?a.headers["content-type"]:d.file.mimetype,customMetadata:{"file-name":"buffer"===o?l.assetFileName:d.file.originalname},metadata:{firebaseStorageDownloadTokens:n}},t=r.file(`${l.assetCollectionName}/${l.assetParentId}/`+l.assetFileName).createWriteStream({metadata:t});t.end(e?a.data:d.file.buffer),t.on("error",s),t.on("finish",i)}));l.downloadLink?(o=yield(0,axios_1.default)({method:"GET",url:l.downloadLink,responseType:"arraybuffer"})).data&&(yield a("buffer",o)):yield a("file")}c.send({data:n})}else c.status(400).json({err:"Invalid Security Configuration"})}else c.status(400).json({err:"Invalid Fields"})}catch(e){c.status(400).json({err:e})}}),this.initDelete=(a,n)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s,o=a.body.data;this.modelChecker(o)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,a),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",a,o),e&&t?("aws"===this.storageType?(i=new this.uploadAdmin.S3,s={Bucket:`${o.bucketName}/${o.assetCollectionName}/`+o.assetParentId,Key:o.assetFileName},yield i.deleteObject(s).promise()):yield this.uploadAdmin.storage().bucket().file(`${o.assetCollectionName}/${o.assetParentId}/`+o.assetFileName).delete(),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.deleteGoogleFolderContents=a=>__awaiter(this,void 0,void 0,function*(){try{var e={prefix:a.name,autoPaginate:!1},[t]=yield this.uploadAdmin.storage().bucket().getFiles(e),i=[];for(const s of t)i.push(s.delete());for(const o of t)o.name.endsWith("/")&&i.push(this.deleteGoogleFolderContents(o));yield Promise.all(i)}catch(e){}}),this.deleteAWSFolderContent=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e=new this.uploadAdmin.S3,t=(yield e.listObjectsV2({Bucket:o,Prefix:a}).promise()).Contents.map(e=>e.Key),i=[];for(const s of t)i.push(e.deleteObject({Bucket:o,Key:s}).promise());yield Promise.all(i)}catch(e){}}),this.initDeleteDirectory=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{var e,t,i,s=o.body.data;this.modelChecker(s,!0)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,s),e&&t?("aws"===this.storageType?yield this.deleteAWSFolderContent(""+s.bucketName,`${s.assetCollectionName}/${s.assetParentId}/`):(i=this.uploadAdmin.storage().bucket().file(`${s.assetCollectionName}/${s.assetParentId}/`),yield this.deleteGoogleFolderContents(i)),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.initBatchDeleteDirectory=(o,a)=>__awaiter(this,void 0,void 0,function*(){try{const s=o.body.data;var e,t,i=JSON.parse(s.assetParentId);this.modelChecker(s,!0)?(e=(0,QueryModel_1.checkBaseConfig)(this.config,o),t=(0,QueryModel_1.checkOpsConfig)(this.config,"delete",o,s),e&&t?(yield Promise.all(i.map(t=>__awaiter(this,void 0,void 0,function*(){var e;"aws"===this.storageType?yield this.deleteAWSFolderContent(""+s.bucketName,s.assetCollectionName+`/${t}/`):(e=this.uploadAdmin.storage().bucket().file(s.assetCollectionName+`/${t}/`),yield this.deleteGoogleFolderContents(e))}))),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.initGet=(n,r)=>__awaiter(this,void 0,void 0,function*(){try{const{bucketName:e,assetCollectionName:t,assetParentId:i,fileName:s}=n.params;if("aws"===this.storageType){const o=new this.uploadAdmin.S3,a={Bucket:e,Key:t+`/${i}/`+s};o.headObject(a,e=>__awaiter(this,void 0,void 0,function*(){if(e&&"NotFound"===e.code)r.status(404).send({message:"File not found"});else{var t=yield o.getObject(a).promise(),i=s.split(".").pop();let e;e="mbtiles"===i?"application/vnd.mapbox-vector-tile":mime_1.default.getType(i)||t.ContentType,r.set("Content-Type",e),r.send(t.Body)}}))}}catch(e){r.status(400).json({err:e})}}),this.init=()=>{var e=this.lib.express.Router();return this.lib.cors&&e.use(this.lib.cors()),e.post("/upload",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"create")}),e.post("/update",this.lib.multer.single("file"),(e,t)=>{this.initUpload(e,t,"update")}),e.post("/delete",this.initDelete),e.post("/deleteDirectory",this.initDeleteDirectory),e.post("/batchDeleteDirectory",this.initBatchDeleteDirectory),e.get("/get/:bucketName/:assetCollectionName/:assetParentId/:fileName",this.initGet),e},this.uploadAdmin=e,this.isProd=t,this.config=i,this.lib=s,this.storageType=null!=o?o:"firebase"}}exports.UploadWrapper=UploadWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blixify-server",
3
- "version": "0.1.47",
3
+ "version": "0.1.49",
4
4
  "license": "MIT",
5
5
  "main": "dist/apis/index.js",
6
6
  "private": false,