@flusys/nestjs-auth 1.0.0-beta → 1.0.0
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/README.md +590 -473
- package/cjs/config/auth.constants.js +12 -0
- package/cjs/controllers/authentication.controller.js +365 -24
- package/cjs/controllers/branch.controller.js +44 -1
- package/cjs/controllers/company-selection.controller.js +27 -20
- package/cjs/controllers/company.controller.js +44 -1
- package/cjs/controllers/user-permission.controller.js +82 -154
- package/cjs/controllers/user.controller.js +211 -7
- package/cjs/docs/auth-swagger.config.js +14 -7
- package/cjs/dtos/authentication.dto.js +114 -38
- package/cjs/dtos/index.js +0 -1
- package/cjs/dtos/user-permission.dto.js +28 -0
- package/cjs/dtos/user.dto.js +19 -4
- package/cjs/entities/index.js +5 -1
- package/cjs/entities/pending-registration.entity.js +125 -0
- package/cjs/entities/user-company-permission.entity.js +3 -9
- package/cjs/entities/user-token.entity.js +129 -0
- package/cjs/interceptors/clear-token.interceptor.js +10 -23
- package/cjs/interceptors/set-token.interceptor.js +15 -55
- package/cjs/interfaces/auth-email-provider.interface.js +45 -0
- package/cjs/interfaces/index.js +2 -0
- package/cjs/interfaces/user-enricher.interface.js +4 -0
- package/cjs/modules/auth.module.js +65 -143
- package/cjs/services/auth-config.service.js +25 -27
- package/cjs/services/auth-datasource.provider.js +13 -23
- package/cjs/services/auth-email.service.js +456 -0
- package/cjs/services/authentication.service.js +297 -349
- package/cjs/services/branch.service.js +9 -4
- package/cjs/services/company-selection-session.service.js +1 -1
- package/cjs/services/index.js +1 -0
- package/cjs/services/user-permission.service.js +43 -73
- package/cjs/services/user.service.js +184 -34
- package/cjs/strategies/jwt.strategy.js +44 -44
- package/cjs/validators/password.validator.js +45 -0
- package/config/auth.constants.d.ts +3 -0
- package/controllers/authentication.controller.d.ts +16 -10
- package/controllers/company-selection.controller.d.ts +6 -2
- package/controllers/user-permission.controller.d.ts +5 -4
- package/controllers/user.controller.d.ts +33 -0
- package/dtos/authentication.dto.d.ts +20 -6
- package/dtos/company-branch.dto.d.ts +0 -1
- package/dtos/company.dto.d.ts +0 -1
- package/dtos/index.d.ts +0 -1
- package/dtos/user-permission.dto.d.ts +4 -0
- package/dtos/user.dto.d.ts +1 -2
- package/entities/index.d.ts +7 -3
- package/entities/pending-registration.entity.d.ts +17 -0
- package/entities/user-company-permission.entity.d.ts +1 -3
- package/entities/user-token.entity.d.ts +15 -0
- package/fesm/config/auth.constants.js +6 -2
- package/fesm/controllers/authentication.controller.js +368 -27
- package/fesm/controllers/branch.controller.js +45 -2
- package/fesm/controllers/company-selection.controller.js +28 -21
- package/fesm/controllers/company.controller.js +45 -2
- package/fesm/controllers/user-permission.controller.js +84 -156
- package/fesm/controllers/user.controller.js +214 -10
- package/fesm/docs/auth-swagger.config.js +14 -7
- package/fesm/dtos/authentication.dto.js +101 -39
- package/fesm/dtos/index.js +0 -1
- package/fesm/dtos/user-permission.dto.js +28 -0
- package/fesm/dtos/user.dto.js +20 -5
- package/fesm/entities/index.js +7 -1
- package/fesm/entities/pending-registration.entity.js +115 -0
- package/fesm/entities/user-company-permission.entity.js +3 -9
- package/fesm/entities/user-token.entity.js +113 -0
- package/fesm/interceptors/clear-token.interceptor.js +9 -22
- package/fesm/interceptors/set-token.interceptor.js +14 -54
- package/fesm/interfaces/auth-email-provider.interface.js +38 -0
- package/fesm/interfaces/authentication.interface.js +1 -1
- package/fesm/interfaces/index.js +2 -0
- package/fesm/interfaces/user-enricher.interface.js +26 -0
- package/fesm/modules/auth.module.js +67 -145
- package/fesm/services/auth-config.service.js +26 -28
- package/fesm/services/auth-datasource.provider.js +14 -24
- package/fesm/services/auth-email.service.js +405 -0
- package/fesm/services/authentication.service.js +297 -349
- package/fesm/services/branch.service.js +9 -4
- package/fesm/services/company-selection-session.service.js +1 -1
- package/fesm/services/index.js +1 -0
- package/fesm/services/user-permission.service.js +44 -74
- package/fesm/services/user.service.js +186 -36
- package/fesm/strategies/jwt.strategy.js +44 -44
- package/fesm/validators/password.validator.js +48 -0
- package/interceptors/clear-token.interceptor.d.ts +0 -1
- package/interceptors/set-token.interceptor.d.ts +1 -1
- package/interfaces/auth-email-provider.interface.d.ts +6 -0
- package/interfaces/auth-module-options.interface.d.ts +4 -1
- package/interfaces/authentication.interface.d.ts +13 -3
- package/interfaces/index.d.ts +2 -0
- package/interfaces/user-enricher.interface.d.ts +64 -0
- package/interfaces/user.interface.d.ts +1 -0
- package/modules/auth.module.d.ts +6 -3
- package/package.json +4 -4
- package/services/auth-config.service.d.ts +7 -8
- package/services/auth-datasource.provider.d.ts +2 -4
- package/services/auth-email.service.d.ts +54 -0
- package/services/authentication.service.d.ts +27 -16
- package/services/company-selection-session.service.d.ts +1 -1
- package/services/index.d.ts +1 -0
- package/services/user-permission.service.d.ts +6 -9
- package/services/user.service.d.ts +19 -3
- package/strategies/jwt.strategy.d.ts +4 -1
- package/validators/password.validator.d.ts +10 -0
- package/cjs/dtos/user-company-permission.dto.js +0 -110
- package/dtos/user-company-permission.dto.d.ts +0 -10
- package/fesm/dtos/user-company-permission.dto.js +0 -98
|
@@ -41,7 +41,50 @@ function _ts_param(paramIndex, decorator) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
let CompanyController = class CompanyController extends (0, _classes.createApiController)(_companydto.CreateCompanyDto, _companydto.UpdateCompanyDto, _companydto.CompanyResponseDto, {
|
|
44
|
-
security:
|
|
44
|
+
security: {
|
|
45
|
+
insert: {
|
|
46
|
+
level: 'permission',
|
|
47
|
+
permissions: [
|
|
48
|
+
_classes.COMPANY_PERMISSIONS.CREATE
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
insertMany: {
|
|
52
|
+
level: 'permission',
|
|
53
|
+
permissions: [
|
|
54
|
+
_classes.COMPANY_PERMISSIONS.CREATE
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
getById: {
|
|
58
|
+
level: 'permission',
|
|
59
|
+
permissions: [
|
|
60
|
+
_classes.COMPANY_PERMISSIONS.READ
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
getAll: {
|
|
64
|
+
level: 'permission',
|
|
65
|
+
permissions: [
|
|
66
|
+
_classes.COMPANY_PERMISSIONS.READ
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
update: {
|
|
70
|
+
level: 'permission',
|
|
71
|
+
permissions: [
|
|
72
|
+
_classes.COMPANY_PERMISSIONS.UPDATE
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
updateMany: {
|
|
76
|
+
level: 'permission',
|
|
77
|
+
permissions: [
|
|
78
|
+
_classes.COMPANY_PERMISSIONS.UPDATE
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
delete: {
|
|
82
|
+
level: 'permission',
|
|
83
|
+
permissions: [
|
|
84
|
+
_classes.COMPANY_PERMISSIONS.DELETE
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
45
88
|
}) {
|
|
46
89
|
constructor(companyService){
|
|
47
90
|
super(companyService), _define_property(this, "companyService", void 0), this.companyService = companyService;
|
|
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "UserPermissionController", {
|
|
|
8
8
|
return UserPermissionController;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
const _nestjsshared = require("@flusys/nestjs-shared");
|
|
11
12
|
const _common = require("@nestjs/common");
|
|
12
13
|
const _swagger = require("@nestjs/swagger");
|
|
13
|
-
const _guards = require("@flusys/nestjs-shared/guards");
|
|
14
14
|
const _userpermissiondto = require("../dtos/user-permission.dto");
|
|
15
|
+
const _usercompanypermissionentity = require("../entities/user-company-permission.entity");
|
|
15
16
|
const _userpermissionservice = require("../services/user-permission.service");
|
|
16
17
|
function _define_property(obj, key, value) {
|
|
17
18
|
if (key in obj) {
|
|
@@ -41,123 +42,67 @@ function _ts_param(paramIndex, decorator) {
|
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
let UserPermissionController = class UserPermissionController {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (item.isAdd) {
|
|
50
|
-
await this.userPermissionService.assignUserToCompany({
|
|
51
|
-
userId: dto.userId,
|
|
52
|
-
companyId: item.targetId
|
|
53
|
-
});
|
|
54
|
-
addedCount++;
|
|
55
|
-
} else {
|
|
56
|
-
await this.userPermissionService.revokeCompanyAccess(dto.userId, item.targetId);
|
|
57
|
-
removedCount++;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
45
|
+
async assignUserCompany(dto) {
|
|
46
|
+
return this.processBatchPermissions(dto.userId, dto.items, _usercompanypermissionentity.PermissionType.COMPANY);
|
|
47
|
+
}
|
|
48
|
+
async getUserCompanies(userId) {
|
|
49
|
+
const permissions = await this.permissionService.findUserCompanies(userId);
|
|
60
50
|
return {
|
|
61
51
|
success: true,
|
|
62
|
-
message:
|
|
52
|
+
message: 'User companies retrieved successfully',
|
|
53
|
+
data: permissions.map((p)=>({
|
|
54
|
+
id: p.id,
|
|
55
|
+
userId: p.userId,
|
|
56
|
+
companyId: p.company?.id || p.targetId,
|
|
57
|
+
companyName: p.company?.name || '',
|
|
58
|
+
companySlug: p.company?.slug || ''
|
|
59
|
+
}))
|
|
63
60
|
};
|
|
64
61
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
userId: permission.userId,
|
|
71
|
-
companyId: permission.company?.id || permission.targetId,
|
|
72
|
-
companyName: permission.company?.name || '',
|
|
73
|
-
companySlug: permission.company?.slug || ''
|
|
74
|
-
}));
|
|
62
|
+
async assignUserBranch(dto) {
|
|
63
|
+
return this.processBatchPermissions(dto.userId, dto.items, _usercompanypermissionentity.PermissionType.BRANCH);
|
|
64
|
+
}
|
|
65
|
+
async getUserBranches(userId, companyId) {
|
|
66
|
+
const permissions = await this.permissionService.findUserBranches(userId, companyId);
|
|
75
67
|
return {
|
|
76
|
-
|
|
68
|
+
success: true,
|
|
69
|
+
message: 'User branches retrieved successfully',
|
|
70
|
+
data: permissions.map((p)=>({
|
|
71
|
+
id: p.id,
|
|
72
|
+
userId: p.userId,
|
|
73
|
+
branchId: p.branch?.id || p.targetId,
|
|
74
|
+
branchName: p.branch?.name || '',
|
|
75
|
+
branchSlug: p.branch?.slug || '',
|
|
76
|
+
companyId: p.branch?.companyId || ''
|
|
77
|
+
}))
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
let removedCount = 0;
|
|
83
|
-
for (const item of dto.items){
|
|
80
|
+
/** Process batch permission assignments/revocations */ async processBatchPermissions(userId, items, type) {
|
|
81
|
+
let added = 0, removed = 0;
|
|
82
|
+
for (const item of items){
|
|
84
83
|
if (item.isAdd) {
|
|
85
|
-
await this.
|
|
86
|
-
|
|
87
|
-
branchId: item.targetId
|
|
88
|
-
});
|
|
89
|
-
addedCount++;
|
|
84
|
+
await this.permissionService.assignPermission(userId, item.targetId, type);
|
|
85
|
+
added++;
|
|
90
86
|
} else {
|
|
91
|
-
await this.
|
|
92
|
-
|
|
87
|
+
await this.permissionService.revokePermission(userId, item.targetId, type);
|
|
88
|
+
removed++;
|
|
93
89
|
}
|
|
94
90
|
}
|
|
95
91
|
return {
|
|
96
92
|
success: true,
|
|
97
|
-
message: `Processed ${
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
/** Get user's branches */ async getUserBranches(userId) {
|
|
101
|
-
const permissions = await this.userPermissionService.findUserBranches(userId);
|
|
102
|
-
// Map to DTO format with populated branch details
|
|
103
|
-
const data = permissions.map((permission)=>({
|
|
104
|
-
id: permission.id,
|
|
105
|
-
userId: permission.userId,
|
|
106
|
-
branchId: permission.branch?.id || permission.targetId,
|
|
107
|
-
branchName: permission.branch?.name || '',
|
|
108
|
-
branchSlug: permission.branch?.slug || '',
|
|
109
|
-
companyId: permission.branch?.companyId || ''
|
|
110
|
-
}));
|
|
111
|
-
return {
|
|
112
|
-
data
|
|
93
|
+
message: `Processed ${added} additions and ${removed} removals`
|
|
113
94
|
};
|
|
114
95
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.userPermissionService = userPermissionService;
|
|
96
|
+
constructor(permissionService){
|
|
97
|
+
_define_property(this, "permissionService", void 0);
|
|
98
|
+
this.permissionService = permissionService;
|
|
119
99
|
}
|
|
120
100
|
};
|
|
121
101
|
_ts_decorate([
|
|
122
102
|
(0, _common.Post)('user-company/assign'),
|
|
103
|
+
(0, _nestjsshared.RequirePermission)(_nestjsshared.USER_PERMISSIONS.UPDATE),
|
|
123
104
|
(0, _swagger.ApiOperation)({
|
|
124
|
-
summary: 'Batch assign/revoke user-company permissions'
|
|
125
|
-
description: `
|
|
126
|
-
Batch operation to assign or revoke user permissions to companies.
|
|
127
|
-
|
|
128
|
-
**Example: Add company permissions**
|
|
129
|
-
\`\`\`json
|
|
130
|
-
{
|
|
131
|
-
"userId": "user-id",
|
|
132
|
-
"items": [
|
|
133
|
-
{ "targetId": "company-id-1", "isAdd": true },
|
|
134
|
-
{ "targetId": "company-id-2", "isAdd": true }
|
|
135
|
-
]
|
|
136
|
-
}
|
|
137
|
-
\`\`\`
|
|
138
|
-
|
|
139
|
-
**Example: Remove company permissions**
|
|
140
|
-
\`\`\`json
|
|
141
|
-
{
|
|
142
|
-
"userId": "user-id",
|
|
143
|
-
"items": [
|
|
144
|
-
{ "targetId": "company-id-1", "isAdd": false },
|
|
145
|
-
{ "targetId": "company-id-2", "isAdd": false }
|
|
146
|
-
]
|
|
147
|
-
}
|
|
148
|
-
\`\`\`
|
|
149
|
-
|
|
150
|
-
**Example: Mix add and remove**
|
|
151
|
-
\`\`\`json
|
|
152
|
-
{
|
|
153
|
-
"userId": "user-id",
|
|
154
|
-
"items": [
|
|
155
|
-
{ "targetId": "company-id-1", "isAdd": true },
|
|
156
|
-
{ "targetId": "company-id-2", "isAdd": false }
|
|
157
|
-
]
|
|
158
|
-
}
|
|
159
|
-
\`\`\`
|
|
160
|
-
`
|
|
105
|
+
summary: 'Batch assign/revoke user-company permissions'
|
|
161
106
|
}),
|
|
162
107
|
(0, _swagger.ApiResponse)({
|
|
163
108
|
status: 200,
|
|
@@ -174,22 +119,28 @@ Batch operation to assign or revoke user permissions to companies.
|
|
|
174
119
|
_ts_metadata("design:returntype", Promise)
|
|
175
120
|
], UserPermissionController.prototype, "assignUserCompany", null);
|
|
176
121
|
_ts_decorate([
|
|
177
|
-
(0, _common.
|
|
122
|
+
(0, _common.Post)('get-user-company'),
|
|
123
|
+
(0, _nestjsshared.RequirePermission)(_nestjsshared.USER_PERMISSIONS.READ),
|
|
178
124
|
(0, _swagger.ApiOperation)({
|
|
179
|
-
summary: 'Get user companies'
|
|
180
|
-
description: 'Returns all companies the user has access to.'
|
|
125
|
+
summary: 'Get user companies'
|
|
181
126
|
}),
|
|
182
|
-
(0, _swagger.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
127
|
+
(0, _swagger.ApiBody)({
|
|
128
|
+
schema: {
|
|
129
|
+
properties: {
|
|
130
|
+
userId: {
|
|
131
|
+
type: 'string'
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
required: [
|
|
135
|
+
'userId'
|
|
136
|
+
]
|
|
137
|
+
}
|
|
187
138
|
}),
|
|
188
139
|
(0, _swagger.ApiResponse)({
|
|
189
140
|
status: 200,
|
|
190
141
|
type: _userpermissiondto.UserCompaniesResponseDto
|
|
191
142
|
}),
|
|
192
|
-
_ts_param(0, (0, _common.
|
|
143
|
+
_ts_param(0, (0, _common.Body)('userId')),
|
|
193
144
|
_ts_metadata("design:type", Function),
|
|
194
145
|
_ts_metadata("design:paramtypes", [
|
|
195
146
|
String
|
|
@@ -198,44 +149,9 @@ _ts_decorate([
|
|
|
198
149
|
], UserPermissionController.prototype, "getUserCompanies", null);
|
|
199
150
|
_ts_decorate([
|
|
200
151
|
(0, _common.Post)('user-branch/assign'),
|
|
152
|
+
(0, _nestjsshared.RequirePermission)(_nestjsshared.USER_PERMISSIONS.UPDATE),
|
|
201
153
|
(0, _swagger.ApiOperation)({
|
|
202
|
-
summary: 'Batch assign/revoke user-branch permissions'
|
|
203
|
-
description: `
|
|
204
|
-
Batch operation to assign or revoke user permissions to branches.
|
|
205
|
-
|
|
206
|
-
**Example: Add branch permissions**
|
|
207
|
-
\`\`\`json
|
|
208
|
-
{
|
|
209
|
-
"userId": "user-id",
|
|
210
|
-
"items": [
|
|
211
|
-
{ "targetId": "branch-id-1", "isAdd": true },
|
|
212
|
-
{ "targetId": "branch-id-2", "isAdd": true }
|
|
213
|
-
]
|
|
214
|
-
}
|
|
215
|
-
\`\`\`
|
|
216
|
-
|
|
217
|
-
**Example: Remove branch permissions**
|
|
218
|
-
\`\`\`json
|
|
219
|
-
{
|
|
220
|
-
"userId": "user-id",
|
|
221
|
-
"items": [
|
|
222
|
-
{ "targetId": "branch-id-1", "isAdd": false },
|
|
223
|
-
{ "targetId": "branch-id-2", "isAdd": false }
|
|
224
|
-
]
|
|
225
|
-
}
|
|
226
|
-
\`\`\`
|
|
227
|
-
|
|
228
|
-
**Example: Mix add and remove**
|
|
229
|
-
\`\`\`json
|
|
230
|
-
{
|
|
231
|
-
"userId": "user-id",
|
|
232
|
-
"items": [
|
|
233
|
-
{ "targetId": "branch-id-1", "isAdd": true },
|
|
234
|
-
{ "targetId": "branch-id-2", "isAdd": false }
|
|
235
|
-
]
|
|
236
|
-
}
|
|
237
|
-
\`\`\`
|
|
238
|
-
`
|
|
154
|
+
summary: 'Batch assign/revoke user-branch permissions'
|
|
239
155
|
}),
|
|
240
156
|
(0, _swagger.ApiResponse)({
|
|
241
157
|
status: 200,
|
|
@@ -252,24 +168,36 @@ Batch operation to assign or revoke user permissions to branches.
|
|
|
252
168
|
_ts_metadata("design:returntype", Promise)
|
|
253
169
|
], UserPermissionController.prototype, "assignUserBranch", null);
|
|
254
170
|
_ts_decorate([
|
|
255
|
-
(0, _common.
|
|
171
|
+
(0, _common.Post)('get-user-branch'),
|
|
172
|
+
(0, _nestjsshared.RequirePermission)(_nestjsshared.USER_PERMISSIONS.READ),
|
|
256
173
|
(0, _swagger.ApiOperation)({
|
|
257
|
-
summary: 'Get user branches'
|
|
258
|
-
description: 'Returns all branches the user has access to.'
|
|
174
|
+
summary: 'Get user branches'
|
|
259
175
|
}),
|
|
260
|
-
(0, _swagger.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
176
|
+
(0, _swagger.ApiBody)({
|
|
177
|
+
schema: {
|
|
178
|
+
properties: {
|
|
179
|
+
userId: {
|
|
180
|
+
type: 'string'
|
|
181
|
+
},
|
|
182
|
+
companyId: {
|
|
183
|
+
type: 'string',
|
|
184
|
+
description: 'Optional company ID to filter branches'
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
required: [
|
|
188
|
+
'userId'
|
|
189
|
+
]
|
|
190
|
+
}
|
|
265
191
|
}),
|
|
266
192
|
(0, _swagger.ApiResponse)({
|
|
267
193
|
status: 200,
|
|
268
194
|
type: _userpermissiondto.UserBranchesResponseDto
|
|
269
195
|
}),
|
|
270
|
-
_ts_param(0, (0, _common.
|
|
196
|
+
_ts_param(0, (0, _common.Body)('userId')),
|
|
197
|
+
_ts_param(1, (0, _common.Body)('companyId')),
|
|
271
198
|
_ts_metadata("design:type", Function),
|
|
272
199
|
_ts_metadata("design:paramtypes", [
|
|
200
|
+
String,
|
|
273
201
|
String
|
|
274
202
|
]),
|
|
275
203
|
_ts_metadata("design:returntype", Promise)
|
|
@@ -278,7 +206,7 @@ UserPermissionController = _ts_decorate([
|
|
|
278
206
|
(0, _swagger.ApiTags)('User Permissions'),
|
|
279
207
|
(0, _swagger.ApiBearerAuth)(),
|
|
280
208
|
(0, _common.Controller)('administration/permissions'),
|
|
281
|
-
(0, _common.UseGuards)(
|
|
209
|
+
(0, _common.UseGuards)(_nestjsshared.JwtAuthGuard),
|
|
282
210
|
_ts_param(0, (0, _common.Inject)(_userpermissionservice.UserPermissionService)),
|
|
283
211
|
_ts_metadata("design:type", Function),
|
|
284
212
|
_ts_metadata("design:paramtypes", [
|
|
@@ -44,42 +44,151 @@ function _ts_param(paramIndex, decorator) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
let UserController = class UserController extends (0, _classes.createApiController)(_userdto.CreateUserDto, _userdto.UpdateUserDto, _userdto.UserResponseDto, {
|
|
47
|
-
security:
|
|
47
|
+
security: {
|
|
48
|
+
insert: {
|
|
49
|
+
level: 'permission',
|
|
50
|
+
permissions: [
|
|
51
|
+
_classes.USER_PERMISSIONS.CREATE
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
insertMany: {
|
|
55
|
+
level: 'permission',
|
|
56
|
+
permissions: [
|
|
57
|
+
_classes.USER_PERMISSIONS.CREATE
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
getById: {
|
|
61
|
+
level: 'permission',
|
|
62
|
+
permissions: [
|
|
63
|
+
_classes.USER_PERMISSIONS.READ
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
getAll: {
|
|
67
|
+
level: 'permission',
|
|
68
|
+
permissions: [
|
|
69
|
+
_classes.USER_PERMISSIONS.READ
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
update: {
|
|
73
|
+
level: 'permission',
|
|
74
|
+
permissions: [
|
|
75
|
+
_classes.USER_PERMISSIONS.UPDATE
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
updateMany: {
|
|
79
|
+
level: 'permission',
|
|
80
|
+
permissions: [
|
|
81
|
+
_classes.USER_PERMISSIONS.UPDATE
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
delete: {
|
|
85
|
+
level: 'permission',
|
|
86
|
+
permissions: [
|
|
87
|
+
_classes.USER_PERMISSIONS.DELETE
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
48
91
|
}) {
|
|
49
|
-
|
|
50
|
-
|
|
92
|
+
async getProfileWithExtras(id, user) {
|
|
93
|
+
const data = await this.service.getProfileWithExtras(id, user);
|
|
94
|
+
return {
|
|
95
|
+
success: true,
|
|
96
|
+
data
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async verifyEmail(id) {
|
|
51
100
|
await this.service.verifyEmail(id);
|
|
52
101
|
return {
|
|
102
|
+
success: true,
|
|
53
103
|
message: 'Email verified successfully'
|
|
54
104
|
};
|
|
55
105
|
}
|
|
56
|
-
|
|
106
|
+
async verifyPhone(id) {
|
|
57
107
|
await this.service.verifyPhone(id);
|
|
58
108
|
return {
|
|
109
|
+
success: true,
|
|
59
110
|
message: 'Phone verified successfully'
|
|
60
111
|
};
|
|
61
112
|
}
|
|
62
|
-
|
|
113
|
+
async updateStatus(id, isActive, user) {
|
|
63
114
|
await this.service.updateStatus(id, isActive, user);
|
|
64
115
|
return {
|
|
116
|
+
success: true,
|
|
65
117
|
message: 'Status updated successfully'
|
|
66
118
|
};
|
|
67
119
|
}
|
|
68
|
-
|
|
120
|
+
async profile(dto, user) {
|
|
69
121
|
const data = await this.service.profile(dto, user);
|
|
70
122
|
return {
|
|
123
|
+
success: true,
|
|
71
124
|
message: 'Profile updated successfully',
|
|
72
125
|
data
|
|
73
126
|
};
|
|
74
127
|
}
|
|
128
|
+
async getProfileSections() {
|
|
129
|
+
const sections = await this.service.getProfileSections();
|
|
130
|
+
return {
|
|
131
|
+
success: true,
|
|
132
|
+
message: 'Profile sections retrieved successfully',
|
|
133
|
+
data: sections
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async getProfileSectionData(id, sectionId, user) {
|
|
137
|
+
const data = await this.service.getProfileSectionData(id, sectionId, user);
|
|
138
|
+
return {
|
|
139
|
+
success: true,
|
|
140
|
+
message: 'Profile section data retrieved successfully',
|
|
141
|
+
data
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
async updateProfileSection(id, sectionId, data, user) {
|
|
145
|
+
await this.service.updateProfileSection(id, sectionId, data, user);
|
|
146
|
+
return {
|
|
147
|
+
success: true,
|
|
148
|
+
message: 'Section updated successfully'
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
async getProfileCompletion(id, user) {
|
|
152
|
+
const percentage = await this.service.getProfileCompletion(id, user);
|
|
153
|
+
return {
|
|
154
|
+
success: true,
|
|
155
|
+
message: 'Profile completion retrieved successfully',
|
|
156
|
+
data: {
|
|
157
|
+
completionPercentage: percentage
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
75
161
|
constructor(service){
|
|
76
162
|
super(service), _define_property(this, "service", void 0), this.service = service;
|
|
77
163
|
}
|
|
78
164
|
};
|
|
165
|
+
_ts_decorate([
|
|
166
|
+
(0, _common.Post)(':id/profile-extras'),
|
|
167
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
168
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
169
|
+
(0, _decorators.RequirePermission)(_classes.USER_PERMISSIONS.READ),
|
|
170
|
+
(0, _swagger.ApiOperation)({
|
|
171
|
+
summary: 'Get user profile with extras',
|
|
172
|
+
description: 'Returns user profile along with extra data (roles, permissions, etc.) if UserEnricher is provided.'
|
|
173
|
+
}),
|
|
174
|
+
(0, _swagger.ApiParam)({
|
|
175
|
+
name: 'id',
|
|
176
|
+
description: 'User ID'
|
|
177
|
+
}),
|
|
178
|
+
_ts_param(0, (0, _common.Param)('id')),
|
|
179
|
+
_ts_param(1, (0, _decorators.CurrentUser)()),
|
|
180
|
+
_ts_metadata("design:type", Function),
|
|
181
|
+
_ts_metadata("design:paramtypes", [
|
|
182
|
+
String,
|
|
183
|
+
typeof _interfaces.ILoggedUserInfo === "undefined" ? Object : _interfaces.ILoggedUserInfo
|
|
184
|
+
]),
|
|
185
|
+
_ts_metadata("design:returntype", Promise)
|
|
186
|
+
], UserController.prototype, "getProfileWithExtras", null);
|
|
79
187
|
_ts_decorate([
|
|
80
188
|
(0, _common.Post)(':id/verify-email'),
|
|
81
189
|
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
82
190
|
(0, _swagger.ApiBearerAuth)(),
|
|
191
|
+
(0, _decorators.RequirePermission)(_classes.USER_PERMISSIONS.UPDATE),
|
|
83
192
|
(0, _swagger.ApiOperation)({
|
|
84
193
|
summary: 'Verify user email'
|
|
85
194
|
}),
|
|
@@ -98,6 +207,7 @@ _ts_decorate([
|
|
|
98
207
|
(0, _common.Post)(':id/verify-phone'),
|
|
99
208
|
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
100
209
|
(0, _swagger.ApiBearerAuth)(),
|
|
210
|
+
(0, _decorators.RequirePermission)(_classes.USER_PERMISSIONS.UPDATE),
|
|
101
211
|
(0, _swagger.ApiOperation)({
|
|
102
212
|
summary: 'Verify user phone'
|
|
103
213
|
}),
|
|
@@ -113,9 +223,10 @@ _ts_decorate([
|
|
|
113
223
|
_ts_metadata("design:returntype", Promise)
|
|
114
224
|
], UserController.prototype, "verifyPhone", null);
|
|
115
225
|
_ts_decorate([
|
|
116
|
-
(0, _common.
|
|
226
|
+
(0, _common.Post)(':id/status'),
|
|
117
227
|
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
118
228
|
(0, _swagger.ApiBearerAuth)(),
|
|
229
|
+
(0, _decorators.RequirePermission)(_classes.USER_PERMISSIONS.UPDATE),
|
|
119
230
|
(0, _swagger.ApiOperation)({
|
|
120
231
|
summary: 'Update user active status',
|
|
121
232
|
description: 'Updates user active status. When company feature is enabled, updates the status for the current company context.'
|
|
@@ -161,6 +272,99 @@ _ts_decorate([
|
|
|
161
272
|
]),
|
|
162
273
|
_ts_metadata("design:returntype", Promise)
|
|
163
274
|
], UserController.prototype, "profile", null);
|
|
275
|
+
_ts_decorate([
|
|
276
|
+
(0, _common.Post)('profile-sections'),
|
|
277
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
278
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
279
|
+
(0, _decorators.RequirePermission)(_classes.USER_PERMISSIONS.READ),
|
|
280
|
+
(0, _swagger.ApiOperation)({
|
|
281
|
+
summary: 'Get profile section definitions',
|
|
282
|
+
description: 'Returns available profile sections for multi-step profile (if enricher configured).'
|
|
283
|
+
}),
|
|
284
|
+
_ts_metadata("design:type", Function),
|
|
285
|
+
_ts_metadata("design:paramtypes", []),
|
|
286
|
+
_ts_metadata("design:returntype", Promise)
|
|
287
|
+
], UserController.prototype, "getProfileSections", null);
|
|
288
|
+
_ts_decorate([
|
|
289
|
+
(0, _common.Post)(':id/profile-section/:sectionId'),
|
|
290
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
291
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
292
|
+
(0, _decorators.RequirePermission)(_classes.USER_PERMISSIONS.READ),
|
|
293
|
+
(0, _swagger.ApiOperation)({
|
|
294
|
+
summary: 'Get profile section data',
|
|
295
|
+
description: 'Returns data for a specific profile section.'
|
|
296
|
+
}),
|
|
297
|
+
(0, _swagger.ApiParam)({
|
|
298
|
+
name: 'id',
|
|
299
|
+
description: 'User ID'
|
|
300
|
+
}),
|
|
301
|
+
(0, _swagger.ApiParam)({
|
|
302
|
+
name: 'sectionId',
|
|
303
|
+
description: 'Section identifier'
|
|
304
|
+
}),
|
|
305
|
+
_ts_param(0, (0, _common.Param)('id')),
|
|
306
|
+
_ts_param(1, (0, _common.Param)('sectionId')),
|
|
307
|
+
_ts_param(2, (0, _decorators.CurrentUser)()),
|
|
308
|
+
_ts_metadata("design:type", Function),
|
|
309
|
+
_ts_metadata("design:paramtypes", [
|
|
310
|
+
String,
|
|
311
|
+
String,
|
|
312
|
+
typeof _interfaces.ILoggedUserInfo === "undefined" ? Object : _interfaces.ILoggedUserInfo
|
|
313
|
+
]),
|
|
314
|
+
_ts_metadata("design:returntype", Promise)
|
|
315
|
+
], UserController.prototype, "getProfileSectionData", null);
|
|
316
|
+
_ts_decorate([
|
|
317
|
+
(0, _common.Post)(':id/profile-section/:sectionId/update'),
|
|
318
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
319
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
320
|
+
(0, _decorators.RequirePermission)(_classes.USER_PERMISSIONS.UPDATE),
|
|
321
|
+
(0, _swagger.ApiOperation)({
|
|
322
|
+
summary: 'Update profile section',
|
|
323
|
+
description: 'Updates a specific profile section data.'
|
|
324
|
+
}),
|
|
325
|
+
(0, _swagger.ApiParam)({
|
|
326
|
+
name: 'id',
|
|
327
|
+
description: 'User ID'
|
|
328
|
+
}),
|
|
329
|
+
(0, _swagger.ApiParam)({
|
|
330
|
+
name: 'sectionId',
|
|
331
|
+
description: 'Section identifier'
|
|
332
|
+
}),
|
|
333
|
+
_ts_param(0, (0, _common.Param)('id')),
|
|
334
|
+
_ts_param(1, (0, _common.Param)('sectionId')),
|
|
335
|
+
_ts_param(2, (0, _common.Body)()),
|
|
336
|
+
_ts_param(3, (0, _decorators.CurrentUser)()),
|
|
337
|
+
_ts_metadata("design:type", Function),
|
|
338
|
+
_ts_metadata("design:paramtypes", [
|
|
339
|
+
String,
|
|
340
|
+
String,
|
|
341
|
+
typeof Record === "undefined" ? Object : Record,
|
|
342
|
+
typeof _interfaces.ILoggedUserInfo === "undefined" ? Object : _interfaces.ILoggedUserInfo
|
|
343
|
+
]),
|
|
344
|
+
_ts_metadata("design:returntype", Promise)
|
|
345
|
+
], UserController.prototype, "updateProfileSection", null);
|
|
346
|
+
_ts_decorate([
|
|
347
|
+
(0, _common.Post)(':id/profile-completion'),
|
|
348
|
+
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
349
|
+
(0, _swagger.ApiBearerAuth)(),
|
|
350
|
+
(0, _decorators.RequirePermission)(_classes.USER_PERMISSIONS.READ),
|
|
351
|
+
(0, _swagger.ApiOperation)({
|
|
352
|
+
summary: 'Get profile completion percentage',
|
|
353
|
+
description: 'Returns overall profile completion percentage.'
|
|
354
|
+
}),
|
|
355
|
+
(0, _swagger.ApiParam)({
|
|
356
|
+
name: 'id',
|
|
357
|
+
description: 'User ID'
|
|
358
|
+
}),
|
|
359
|
+
_ts_param(0, (0, _common.Param)('id')),
|
|
360
|
+
_ts_param(1, (0, _decorators.CurrentUser)()),
|
|
361
|
+
_ts_metadata("design:type", Function),
|
|
362
|
+
_ts_metadata("design:paramtypes", [
|
|
363
|
+
String,
|
|
364
|
+
typeof _interfaces.ILoggedUserInfo === "undefined" ? Object : _interfaces.ILoggedUserInfo
|
|
365
|
+
]),
|
|
366
|
+
_ts_metadata("design:returntype", Promise)
|
|
367
|
+
], UserController.prototype, "getProfileCompletion", null);
|
|
164
368
|
UserController = _ts_decorate([
|
|
165
369
|
(0, _swagger.ApiTags)('Users'),
|
|
166
370
|
(0, _common.Controller)('administration/users'),
|