@drax/identity-back 3.2.0 → 3.4.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.
@@ -6,7 +6,9 @@ class UserSessionSqliteRepository extends AbstractSqliteRepository {
6
6
  this.searchFields = [];
7
7
  this.booleanFields = [];
8
8
  this.identifier = '_id';
9
- this.populateFields = [{ field: 'user', table: 'users', identifier: '_id' }];
9
+ this.populateFields = [
10
+ { field: 'user', table: 'users', identifier: '_id' }
11
+ ];
10
12
  this.tableFields = [
11
13
  { name: "uuid", type: "TEXT", unique: false, primary: false },
12
14
  { name: "user", type: "TEXT", unique: false, primary: false },
@@ -8,8 +8,12 @@ class UserSqliteRepository extends AbstractSqliteRepository {
8
8
  this.tableName = 'users';
9
9
  this.searchFields = [];
10
10
  this.booleanFields = ['active'];
11
+ this.jsonFields = [];
11
12
  this.identifier = '_id';
12
- this.populateFields = [];
13
+ this.populateFields = [
14
+ { field: 'tenant', table: 'tenants', identifier: '_id' },
15
+ // {field: 'role', table: 'roles', identifier: '_id'}
16
+ ];
13
17
  this.tableFields = [
14
18
  { name: "name", type: "TEXT", unique: false, primary: false },
15
19
  { name: "username", type: "TEXT", unique: true, primary: false },
@@ -36,18 +40,27 @@ class UserSqliteRepository extends AbstractSqliteRepository {
36
40
  if (userData.groups && Array.isArray(userData.groups)) {
37
41
  userData.groups = userData.groups.join(",");
38
42
  }
43
+ if (userData.role && typeof userData.role === 'object' && userData.role._id) {
44
+ userData.role = userData.role._id;
45
+ }
46
+ if (userData.tenant && typeof userData.tenant === 'object' && userData.tenant._id) {
47
+ userData.tenant = userData.tenant._id;
48
+ }
39
49
  userData.active = userData.active ? 1 : 0;
40
50
  if (!await this.findRoleById(userData.role)) {
41
51
  throw new ValidationError([{ field: 'role', reason: 'validation.notfound', value: userData.role }]);
42
52
  }
43
53
  }
44
54
  async prepareItem(user) {
45
- if (user && user.role) {
55
+ if (user && user.role && typeof user.role === 'string') {
46
56
  user.role = await this.findRoleById(user.role);
47
57
  }
48
- if (user && user.tenant) {
58
+ if (user && user.tenant && typeof user.tenant === 'string') {
49
59
  user.tenant = await this.findTenantById(user.tenant);
50
60
  }
61
+ if (user && user.hasOwnProperty('groups')) {
62
+ user.groups = user.groups ? user.groups.split(",") : [];
63
+ }
51
64
  }
52
65
  async updatePartial(id, userData) {
53
66
  return this.update(id, userData);
@@ -69,7 +82,7 @@ class UserSqliteRepository extends AbstractSqliteRepository {
69
82
  return user;
70
83
  }
71
84
  async findByIdWithPassword(id) {
72
- const user = this.db.prepare('SELECT * FROM users WHERE ${this.identifier} = ?').get(id);
85
+ const user = this.db.prepare(`SELECT * FROM users WHERE ${this.identifier} = ?`).get(id);
73
86
  if (!user) {
74
87
  return null;
75
88
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.2.0",
6
+ "version": "3.4.2",
7
7
  "description": "Identity module for user management, authentication and authorization.",
8
8
  "main": "dist/index.js",
9
9
  "types": "types/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "license": "ISC",
30
30
  "dependencies": {
31
31
  "@drax/common-back": "^3.0.0",
32
- "@drax/crud-back": "^3.2.0",
32
+ "@drax/crud-back": "^3.4.2",
33
33
  "@drax/crud-share": "^3.2.0",
34
34
  "@drax/email-back": "^3.1.0",
35
35
  "@drax/identity-share": "^3.0.0",
@@ -63,5 +63,5 @@
63
63
  "debug": "0"
64
64
  }
65
65
  },
66
- "gitHead": "8446a621e05bc1f4fd080c814a3ebdd7ae8a626b"
66
+ "gitHead": "678a645d46927a684bd9c5f9c4aa13ff77266e2d"
67
67
  }
@@ -13,7 +13,9 @@ class UserSessionSqliteRepository extends AbstractSqliteRepository<IUserSession,
13
13
  protected searchFields: string[] = [];
14
14
  protected booleanFields: string[] = [];
15
15
  protected identifier: string = '_id';
16
- protected populateFields = [{field: 'user', table: 'users', identifier: '_id'}]
16
+ protected populateFields = [
17
+ {field: 'user', table: 'users', identifier: '_id'}
18
+ ]
17
19
  protected tableFields: SqliteTableField[] = [
18
20
  {name: "uuid", type: "TEXT", unique: false, primary: false},
19
21
  {name: "user", type: "TEXT", unique: false, primary: false},
@@ -18,8 +18,12 @@ class UserSqliteRepository extends AbstractSqliteRepository<IUser, IUserCreate,
18
18
  protected dataBaseFile: string;
19
19
  protected searchFields: string[] = [];
20
20
  protected booleanFields: string[] = ['active'];
21
+ protected jsonFields: string[] = [];
21
22
  protected identifier: string = '_id';
22
- protected populateFields = []
23
+ protected populateFields = [
24
+ {field: 'tenant', table: 'tenants', identifier: '_id'},
25
+ // {field: 'role', table: 'roles', identifier: '_id'}
26
+ ]
23
27
  protected tableFields: SqliteTableField[] = [
24
28
  {name: "name", type: "TEXT", unique: false, primary: false},
25
29
  {name: "username", type: "TEXT", unique: true, primary: false},
@@ -52,6 +56,15 @@ class UserSqliteRepository extends AbstractSqliteRepository<IUser, IUserCreate,
52
56
  if (userData.groups && Array.isArray(userData.groups)) {
53
57
  userData.groups = userData.groups.join(",")
54
58
  }
59
+
60
+ if (userData.role && typeof userData.role === 'object' && userData.role._id) {
61
+ userData.role = userData.role._id
62
+ }
63
+
64
+ if (userData.tenant && typeof userData.tenant === 'object' && userData.tenant._id) {
65
+ userData.tenant = userData.tenant._id
66
+ }
67
+
55
68
  userData.active = userData.active ? 1 : 0
56
69
 
57
70
  if (!await this.findRoleById(userData.role)) {
@@ -60,13 +73,17 @@ class UserSqliteRepository extends AbstractSqliteRepository<IUser, IUserCreate,
60
73
  }
61
74
 
62
75
  async prepareItem(user: any) {
63
- if (user && user.role) {
76
+ if (user && user.role && typeof user.role === 'string') {
64
77
  user.role = await this.findRoleById(user.role)
65
78
  }
66
79
 
67
- if (user && user.tenant) {
80
+ if (user && user.tenant && typeof user.tenant === 'string') {
68
81
  user.tenant = await this.findTenantById(user.tenant)
69
82
  }
83
+
84
+ if (user && user.hasOwnProperty('groups')) {
85
+ user.groups = user.groups ? user.groups.split(",") : []
86
+ }
70
87
  }
71
88
 
72
89
 
@@ -94,7 +111,7 @@ class UserSqliteRepository extends AbstractSqliteRepository<IUser, IUserCreate,
94
111
  }
95
112
 
96
113
  async findByIdWithPassword(id: string): Promise<IUser | null> {
97
- const user = this.db.prepare('SELECT * FROM users WHERE ${this.identifier} = ?').get(id);
114
+ const user = this.db.prepare(`SELECT * FROM users WHERE ${this.identifier} = ?`).get(id);
98
115
  if (!user) {
99
116
  return null
100
117
  }