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