@go-mailer/jarvis 3.1.0 → 3.1.2

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.
@@ -20,6 +20,15 @@ const extract_token = (headers) => {
20
20
  return token;
21
21
  };
22
22
 
23
+ const extract_tenant_id = (request) => {
24
+ const { params, query } = request
25
+ let tenant_id = { $exists: true }
26
+ if (query.tenant_id) tenant_id = query.tenant_id
27
+ if (params.tenant_id) tenant_id = params.tenant_id
28
+
29
+ return tenant_id
30
+ }
31
+
23
32
  // main
24
33
  const authenticateUser = async (request, response, next) => {
25
34
  try {
@@ -39,7 +48,7 @@ const authenticateUser = async (request, response, next) => {
39
48
 
40
49
  const { tenant_id, is_admin } = await jwt.verify(token, SECRET, { issuer: ISSUER });
41
50
  request.is_admin = !!is_admin;
42
- request.tenant_id = is_admin ? { $exists: true } : tenant_id;
51
+ request.tenant_id = is_admin ? extract_tenant_id(request) : tenant_id;
43
52
 
44
53
  next();
45
54
  } catch (e) {
package/lib/query.js CHANGED
@@ -1,12 +1,13 @@
1
1
  const buildQuery = (options) => {
2
- const seek_conditions = {}
3
2
  const sort_condition = options.sort_by ? buildSortOrderString(options.sort_by) : ''
4
3
  const fields_to_return = options.return_only ? buildReturnFieldsString(options.return_only) : ''
5
4
  const count = options.count || false
5
+ const seek_conditions = { ...buildBooleanQuery(options.bool || '')}
6
6
 
7
7
  const { skip, limit } = determinePagination(options.page, options.population)
8
8
 
9
9
  /** Delete sort and return fields */
10
+ delete options.bool
10
11
  delete options.count
11
12
  delete options.page
12
13
  delete options.population
@@ -40,6 +41,23 @@ const buildQuery = (options) => {
40
41
  }
41
42
  }
42
43
 
44
+ const buildBooleanQuery = (value) => {
45
+ const values = value.split(',')
46
+ return values.reduce((sac, val) => {
47
+ let truthiness = true
48
+ let key = val
49
+ if (val[0] === '-') {
50
+ truthiness = false
51
+ key = val.substr(1)
52
+ }
53
+
54
+ return {
55
+ ...sac,
56
+ [key]: truthiness
57
+ }
58
+ }, {})
59
+ }
60
+
43
61
  const buildInQuery = (value) => {
44
62
  const values = value.split(':')
45
63
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-mailer/jarvis",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "main": "index.js",
5
5
  "repository": "git@github.com:go-mailer-ltd/jarvis-node.git",
6
6
  "author": "Nathan Oguntuberu <nateoguns.work@gmail.com>",