gemcap-be-common 1.2.134 → 1.2.136
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.
- package/models/BorrowerCompliance.model.d.ts +1 -1
- package/models/BorrowerCompliance.model.js +1 -1
- package/models/BorrowerCompliance.model.ts +2 -2
- package/models/UserMobileAccess.model.js +1 -1
- package/models/UserMobileAccess.model.ts +2 -1
- package/package.json +1 -1
- package/services/users.service.d.ts +3 -3
- package/services/users.service.js +111 -198
- package/services/users.service.ts +114 -206
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import mongoose, { Document } from 'mongoose';
|
|
26
|
-
import { IBorrowerItemDocument, IEmailRecipient } from '
|
|
26
|
+
import { IBorrowerItemDocument, IEmailRecipient } from './ComplianceItem.model';
|
|
27
27
|
export interface IComplianceNote {
|
|
28
28
|
note: string;
|
|
29
29
|
date: Date;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BorrowerCompliance = void 0;
|
|
7
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
-
const _models_1 = require("
|
|
8
|
+
const _models_1 = require("./_models");
|
|
9
9
|
const mongooseLeanId = require('../plugins/id.plugin');
|
|
10
10
|
const BorrowerComplianceInstanceSchema = new mongoose_1.default.Schema({
|
|
11
11
|
nextDate: {
|
|
@@ -3,8 +3,8 @@ import mongoose, { Document } from 'mongoose';
|
|
|
3
3
|
import {
|
|
4
4
|
IBorrowerItemDocument,
|
|
5
5
|
IEmailRecipient,
|
|
6
|
-
} from '
|
|
7
|
-
import { MODEL_NAMES } from '
|
|
6
|
+
} from './ComplianceItem.model';
|
|
7
|
+
import { MODEL_NAMES } from './_models';
|
|
8
8
|
|
|
9
9
|
const mongooseLeanId = require('../plugins/id.plugin');
|
|
10
10
|
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.UserMobileAccess = void 0;
|
|
7
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
-
const _models_1 = require("
|
|
8
|
+
const _models_1 = require("./_models");
|
|
9
9
|
const UserMobileAccessSchema = new mongoose_1.default.Schema({
|
|
10
10
|
keycloakUserId: {
|
|
11
11
|
type: String,
|
package/package.json
CHANGED
|
@@ -42,7 +42,7 @@ export declare class UsersService {
|
|
|
42
42
|
getUserRepresentationById(authorization: string, userId: string): Promise<IKeycloakUser>;
|
|
43
43
|
getUserRepresentationByUsername(authorization: string, username: string): Promise<IKeycloakUser>;
|
|
44
44
|
getKeyCloakAdminBearer(): Promise<any>;
|
|
45
|
-
getUserList(authorization:
|
|
45
|
+
getUserList(authorization: string): Promise<IKeycloakUser[]>;
|
|
46
46
|
getUsersWithRoles(authorization: string): Promise<{
|
|
47
47
|
keycloakUserId: string;
|
|
48
48
|
_id: any;
|
|
@@ -86,7 +86,7 @@ export declare class UsersService {
|
|
|
86
86
|
getUserRoles(authorization: string, userId: string): Promise<{
|
|
87
87
|
realmMappings: IKeycloakRole[];
|
|
88
88
|
}>;
|
|
89
|
-
createUser(authorization:
|
|
89
|
+
createUser(authorization: string, user: any): Promise<any>;
|
|
90
90
|
updateUser(authorization: string, userId: string, keyValue: any): Promise<any>;
|
|
91
91
|
updateMobileUser(userId: string, keyValue: {
|
|
92
92
|
[key: string]: string | number | boolean;
|
|
@@ -97,7 +97,7 @@ export declare class UsersService {
|
|
|
97
97
|
resetPassword(authorization: string, userId: string, temporaryPassword: string): Promise<any>;
|
|
98
98
|
createNewPasswordWithEmail(authorization: string, userId: string, newPassword: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
99
99
|
deleteUser(authorization: string, userId: string): Promise<void>;
|
|
100
|
-
getRoleList(authorization:
|
|
100
|
+
getRoleList(authorization: string): Promise<IKeycloakRole[]>;
|
|
101
101
|
groupRoles(roles: IKeycloakRole[]): IGroupedKeycloakRoles;
|
|
102
102
|
mapRolesToUsers(authorization: string, users: IKeycloakUser[]): Promise<{
|
|
103
103
|
roles: IGroupedKeycloakRoles;
|
|
@@ -9,12 +9,12 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
9
9
|
const axios_1 = __importDefault(require("axios"));
|
|
10
10
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
11
11
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
12
|
+
const qs_1 = __importDefault(require("qs"));
|
|
12
13
|
const User_model_1 = require("../models/User.model");
|
|
13
|
-
const user_logs_db_1 = require("../db/user-logs.db");
|
|
14
|
-
const UserLog_model_1 = require("../models/UserLog.model");
|
|
15
14
|
const BorrowerCompliance_model_1 = require("../models/BorrowerCompliance.model");
|
|
16
15
|
const UserMobileAccess_model_1 = require("../models/UserMobileAccess.model");
|
|
17
|
-
const
|
|
16
|
+
const UserLog_model_1 = require("../models/UserLog.model");
|
|
17
|
+
const user_logs_db_1 = require("../db/user-logs.db");
|
|
18
18
|
class UsersService {
|
|
19
19
|
config;
|
|
20
20
|
constructor(config) {
|
|
@@ -48,8 +48,7 @@ class UsersService {
|
|
|
48
48
|
},
|
|
49
49
|
};
|
|
50
50
|
const result = await axios_1.default.request(options);
|
|
51
|
-
|
|
52
|
-
return user;
|
|
51
|
+
return result.data;
|
|
53
52
|
}
|
|
54
53
|
async getUserRepresentationByUsername(authorization, username) {
|
|
55
54
|
const options = {
|
|
@@ -64,50 +63,31 @@ class UsersService {
|
|
|
64
63
|
const users = result.data;
|
|
65
64
|
return users.find((user) => user.username === username);
|
|
66
65
|
}
|
|
67
|
-
getKeyCloakAdminBearer() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
form: {
|
|
76
|
-
username: this.config.adminUser,
|
|
77
|
-
password: this.config.adminPass,
|
|
78
|
-
client_id: 'admin-cli',
|
|
79
|
-
grant_type: 'password',
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
request(options, (error, res, body) => {
|
|
83
|
-
if (!error && res.statusCode === 200) {
|
|
84
|
-
resolve(JSON.parse(body));
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
reject(error);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
66
|
+
async getKeyCloakAdminBearer() {
|
|
67
|
+
const url = `${this.config.keycloakHost}/realms/master/protocol/openid-connect/token`;
|
|
68
|
+
const data = qs_1.default.stringify({
|
|
69
|
+
username: this.config.adminUser,
|
|
70
|
+
password: this.config.adminPass,
|
|
71
|
+
client_id: 'admin-cli',
|
|
72
|
+
grant_type: 'password',
|
|
90
73
|
});
|
|
74
|
+
const headers = {
|
|
75
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
76
|
+
};
|
|
77
|
+
const response = await axios_1.default.post(url, data, { headers });
|
|
78
|
+
return response.data;
|
|
91
79
|
}
|
|
92
|
-
getUserList(authorization) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (!error) {
|
|
104
|
-
resolve(JSON.parse(body));
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
reject(error);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
});
|
|
80
|
+
async getUserList(authorization) {
|
|
81
|
+
const options = {
|
|
82
|
+
method: 'GET',
|
|
83
|
+
url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users`,
|
|
84
|
+
headers: {
|
|
85
|
+
'Content-Type': 'application/json',
|
|
86
|
+
Authorization: `Bearer ${authorization}`,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
const result = await axios_1.default.request(options);
|
|
90
|
+
return result.data;
|
|
111
91
|
}
|
|
112
92
|
async getUsersWithRoles(authorization) {
|
|
113
93
|
const users = await this.getUserList(authorization);
|
|
@@ -121,73 +101,45 @@ class UsersService {
|
|
|
121
101
|
}
|
|
122
102
|
return usersAndAccess;
|
|
123
103
|
}
|
|
124
|
-
getUserRoles(authorization, userId) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (!error) {
|
|
136
|
-
resolve(JSON.parse(body));
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
reject(error);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
104
|
+
async getUserRoles(authorization, userId) {
|
|
105
|
+
const options = {
|
|
106
|
+
method: 'GET',
|
|
107
|
+
url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings`,
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
Authorization: `Bearer ${authorization}`,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
const result = await axios_1.default.request(options);
|
|
114
|
+
return result.data;
|
|
143
115
|
}
|
|
144
|
-
createUser(authorization, user) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
request(options, (error, res, body) => {
|
|
159
|
-
if (!error) {
|
|
160
|
-
resolve(body);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
console.error({ error });
|
|
164
|
-
reject(error);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
116
|
+
async createUser(authorization, user) {
|
|
117
|
+
const options = {
|
|
118
|
+
method: 'POST',
|
|
119
|
+
url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users`,
|
|
120
|
+
headers: {
|
|
121
|
+
'Content-Type': 'application/json',
|
|
122
|
+
Authorization: `Bearer ${authorization}`,
|
|
123
|
+
},
|
|
124
|
+
data: {
|
|
125
|
+
...user,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
const result = await axios_1.default.request(options);
|
|
129
|
+
return result.data;
|
|
168
130
|
}
|
|
169
|
-
updateUser(authorization, userId, keyValue) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
request(options, (error, res, body) => {
|
|
182
|
-
if (!error) {
|
|
183
|
-
resolve(body);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
console.error({ error });
|
|
187
|
-
reject(error);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
});
|
|
131
|
+
async updateUser(authorization, userId, keyValue) {
|
|
132
|
+
const options = {
|
|
133
|
+
method: 'PUT',
|
|
134
|
+
url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}`,
|
|
135
|
+
headers: {
|
|
136
|
+
'Content-Type': 'application/json',
|
|
137
|
+
Authorization: `Bearer ${authorization}`,
|
|
138
|
+
},
|
|
139
|
+
data: keyValue,
|
|
140
|
+
};
|
|
141
|
+
const result = await axios_1.default.request(options);
|
|
142
|
+
return result.data;
|
|
191
143
|
}
|
|
192
144
|
async updateMobileUser(userId, keyValue) {
|
|
193
145
|
await UserMobileAccess_model_1.UserMobileAccess.findOneAndUpdate({ keycloakUserId: userId }, keyValue, { upsert: true });
|
|
@@ -196,74 +148,44 @@ class UsersService {
|
|
|
196
148
|
await User_model_1.UserModel
|
|
197
149
|
.findOneAndUpdate({ keycloakUserId }, userAccess);
|
|
198
150
|
}
|
|
199
|
-
removeUserRoles(authorization, userId, roles) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
request(options, (error, res, body) => {
|
|
212
|
-
if (!error) {
|
|
213
|
-
resolve(body);
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
console.error({ error });
|
|
217
|
-
reject(error);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
});
|
|
151
|
+
async removeUserRoles(authorization, userId, roles) {
|
|
152
|
+
const options = {
|
|
153
|
+
method: 'DELETE',
|
|
154
|
+
url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings/realm`,
|
|
155
|
+
headers: {
|
|
156
|
+
'Content-Type': 'application/json',
|
|
157
|
+
Authorization: `Bearer ${authorization}`,
|
|
158
|
+
},
|
|
159
|
+
data: [...roles],
|
|
160
|
+
};
|
|
161
|
+
const result = await axios_1.default.request(options);
|
|
162
|
+
return result.data;
|
|
221
163
|
}
|
|
222
|
-
addUserRoles(authorization, userId, roles) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
request(options, (error, res, body) => {
|
|
235
|
-
if (!error) {
|
|
236
|
-
resolve(body);
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
console.error({ error });
|
|
240
|
-
reject(error);
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
});
|
|
164
|
+
async addUserRoles(authorization, userId, roles) {
|
|
165
|
+
const options = {
|
|
166
|
+
method: 'POST',
|
|
167
|
+
url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings/realm`,
|
|
168
|
+
headers: {
|
|
169
|
+
'Content-Type': 'application/json',
|
|
170
|
+
Authorization: `Bearer ${authorization}`,
|
|
171
|
+
},
|
|
172
|
+
data: [...roles],
|
|
173
|
+
};
|
|
174
|
+
const result = await axios_1.default.request(options);
|
|
175
|
+
return result.data;
|
|
244
176
|
}
|
|
245
|
-
resetPassword(authorization, userId, temporaryPassword) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
request(options, (error, res, body) => {
|
|
258
|
-
if (!error) {
|
|
259
|
-
resolve(body);
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
console.error({ error });
|
|
263
|
-
reject(error);
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
});
|
|
177
|
+
async resetPassword(authorization, userId, temporaryPassword) {
|
|
178
|
+
const options = {
|
|
179
|
+
method: 'PUT',
|
|
180
|
+
url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/reset-password`,
|
|
181
|
+
headers: {
|
|
182
|
+
'Content-Type': 'application/json',
|
|
183
|
+
Authorization: `Bearer ${authorization}`,
|
|
184
|
+
},
|
|
185
|
+
data: { value: temporaryPassword, temporary: true },
|
|
186
|
+
};
|
|
187
|
+
const result = await axios_1.default.request(options);
|
|
188
|
+
return result.data;
|
|
267
189
|
}
|
|
268
190
|
async createNewPasswordWithEmail(authorization, userId, newPassword) {
|
|
269
191
|
const options = {
|
|
@@ -303,26 +225,17 @@ class UsersService {
|
|
|
303
225
|
console.log(error);
|
|
304
226
|
}
|
|
305
227
|
}
|
|
306
|
-
getRoleList(authorization) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (!error) {
|
|
318
|
-
resolve(JSON.parse(body));
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
console.error({ error });
|
|
322
|
-
reject(error);
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
});
|
|
228
|
+
async getRoleList(authorization) {
|
|
229
|
+
const options = {
|
|
230
|
+
method: 'GET',
|
|
231
|
+
url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/roles`,
|
|
232
|
+
headers: {
|
|
233
|
+
'Content-Type': 'application/json',
|
|
234
|
+
Authorization: `Bearer ${authorization}`,
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
const result = await axios_1.default.request(options);
|
|
238
|
+
return result.data;
|
|
326
239
|
}
|
|
327
240
|
groupRoles(roles) {
|
|
328
241
|
return roles.reduce((acc, role) => {
|