@flusys/nestjs-auth 0.1.0-beta.3 → 1.0.0-rc
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 +274 -301
- package/cjs/config/auth.constants.js +22 -4
- package/cjs/controllers/authentication.controller.js +222 -38
- package/cjs/controllers/branch.controller.js +46 -4
- package/cjs/controllers/company-selection.controller.js +27 -20
- package/cjs/controllers/company.controller.js +46 -4
- package/cjs/controllers/user-permission.controller.js +40 -37
- package/cjs/controllers/user.controller.js +222 -23
- package/cjs/dtos/authentication.dto.js +119 -13
- 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 +0 -6
- package/cjs/entities/user-token.entity.js +129 -0
- package/cjs/guards/auth-throttler.guard.js +53 -0
- package/cjs/interceptors/clear-token.interceptor.js +3 -6
- package/cjs/interceptors/set-token.interceptor.js +38 -31
- package/cjs/interfaces/auth-email-provider.interface.js +45 -0
- package/cjs/interfaces/authentication.interface.js +0 -3
- package/cjs/interfaces/index.js +2 -0
- package/cjs/interfaces/user-enricher.interface.js +4 -0
- package/cjs/modules/auth.module.js +8 -20
- package/cjs/services/auth-config.service.js +42 -47
- package/cjs/services/auth-datasource.provider.js +18 -34
- package/cjs/services/auth-email.service.js +471 -0
- package/cjs/services/authentication.service.js +240 -153
- package/cjs/services/branch.service.js +15 -48
- package/cjs/services/company-selection-session.service.js +1 -1
- package/cjs/services/company.service.js +7 -36
- package/cjs/services/index.js +1 -0
- package/cjs/services/user-permission.service.js +9 -29
- package/cjs/services/user.service.js +228 -107
- package/cjs/strategies/jwt.strategy.js +14 -1
- package/cjs/validators/password.validator.js +45 -0
- package/config/auth.constants.d.ts +5 -0
- package/controllers/authentication.controller.d.ts +13 -9
- package/controllers/company-selection.controller.d.ts +6 -2
- package/controllers/user.controller.d.ts +33 -0
- package/dtos/authentication.dto.d.ts +21 -3
- package/dtos/company-branch.dto.d.ts +0 -1
- package/dtos/company.dto.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 +0 -2
- package/entities/user-token.entity.d.ts +15 -0
- package/fesm/config/auth.constants.js +11 -8
- package/fesm/controllers/authentication.controller.js +224 -40
- package/fesm/controllers/branch.controller.js +49 -7
- package/fesm/controllers/company-selection.controller.js +28 -21
- package/fesm/controllers/company.controller.js +49 -7
- package/fesm/controllers/user-permission.controller.js +41 -38
- package/fesm/controllers/user.controller.js +225 -26
- package/fesm/dtos/authentication.dto.js +123 -111
- 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 +0 -6
- package/fesm/entities/user-token.entity.js +113 -0
- package/fesm/guards/auth-throttler.guard.js +43 -0
- package/fesm/interceptors/clear-token.interceptor.js +2 -5
- package/fesm/interceptors/set-token.interceptor.js +37 -30
- package/fesm/interfaces/auth-email-provider.interface.js +38 -0
- package/fesm/interfaces/authentication.interface.js +1 -7
- package/fesm/interfaces/index.js +2 -0
- package/fesm/interfaces/user-enricher.interface.js +26 -0
- package/fesm/modules/auth.module.js +10 -22
- package/fesm/services/auth-config.service.js +42 -47
- package/fesm/services/auth-datasource.provider.js +19 -35
- package/fesm/services/auth-email.service.js +420 -0
- package/fesm/services/authentication.service.js +238 -151
- package/fesm/services/branch.service.js +16 -49
- package/fesm/services/company-selection-session.service.js +1 -1
- package/fesm/services/company.service.js +8 -37
- package/fesm/services/index.js +1 -0
- package/fesm/services/user-permission.service.js +10 -30
- package/fesm/services/user.service.js +229 -108
- package/fesm/strategies/jwt.strategy.js +14 -1
- package/fesm/validators/password.validator.js +48 -0
- package/guards/auth-throttler.guard.d.ts +7 -0
- package/interceptors/set-token.interceptor.d.ts +1 -0
- 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 +14 -0
- 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 +0 -1
- package/package.json +4 -4
- package/services/auth-config.service.d.ts +5 -1
- package/services/auth-email.service.d.ts +51 -0
- package/services/authentication.service.d.ts +21 -12
- package/services/branch.service.d.ts +2 -5
- package/services/company-selection-session.service.d.ts +1 -1
- package/services/company.service.d.ts +1 -4
- package/services/index.d.ts +1 -0
- package/services/user-permission.service.d.ts +0 -1
- package/services/user.service.d.ts +20 -6
- package/validators/password.validator.d.ts +10 -0
|
@@ -26,42 +26,35 @@ function _ts_param(paramIndex, decorator) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
import { CurrentUser } from '@flusys/nestjs-shared/decorators';
|
|
29
|
-
import { Body, Controller,
|
|
29
|
+
import { Body, Controller, HttpCode, HttpStatus, Inject, Post, UseGuards, UseInterceptors } from '@nestjs/common';
|
|
30
30
|
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
31
31
|
import { LoginResponseDto, SelectDto, SwitchCompanyDto } from '../dtos/authentication.dto';
|
|
32
32
|
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
33
33
|
import { SetToken } from '../interceptors/set-token.interceptor';
|
|
34
34
|
import { AuthenticationService } from '../services/authentication.service';
|
|
35
35
|
export class CompanySelectionController {
|
|
36
|
-
|
|
37
|
-
* Select Company & Branch
|
|
38
|
-
* Used after login when user needs to select company and branch
|
|
39
|
-
*/ async select(dto) {
|
|
36
|
+
async select(dto) {
|
|
40
37
|
return this.authService.select(dto.sessionId, dto.companyId, dto.branchId);
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
* Switch Company/Branch
|
|
44
|
-
* Used to switch company/branch after already logged in
|
|
45
|
-
*/ async switchCompany(userId, dto) {
|
|
39
|
+
async switchCompany(userId, dto) {
|
|
46
40
|
return this.authService.switchCompany(userId, dto.companyId, dto.branchId);
|
|
47
41
|
}
|
|
48
|
-
|
|
49
|
-
* Get user's companies
|
|
50
|
-
*/ async getUserCompanies(userId) {
|
|
42
|
+
async getUserCompanies(userId) {
|
|
51
43
|
const companies = await this.authService.getUserCompanies(userId);
|
|
52
44
|
return {
|
|
53
|
-
|
|
45
|
+
success: true,
|
|
46
|
+
message: 'User companies retrieved successfully',
|
|
47
|
+
data: companies
|
|
54
48
|
};
|
|
55
49
|
}
|
|
56
|
-
|
|
57
|
-
* Get branches for a specific company
|
|
58
|
-
*/ async getUserBranches(userId, companyId) {
|
|
50
|
+
async getUserBranches(userId, companyId) {
|
|
59
51
|
const branches = await this.authService.getUserBranches(userId, companyId);
|
|
60
52
|
return {
|
|
61
|
-
|
|
53
|
+
success: true,
|
|
54
|
+
message: 'Company branches retrieved successfully',
|
|
55
|
+
data: branches
|
|
62
56
|
};
|
|
63
57
|
}
|
|
64
|
-
// NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
|
|
65
58
|
constructor(authService){
|
|
66
59
|
_define_property(this, "authService", void 0);
|
|
67
60
|
this.authService = authService;
|
|
@@ -117,7 +110,8 @@ _ts_decorate([
|
|
|
117
110
|
], CompanySelectionController.prototype, "switchCompany", null);
|
|
118
111
|
_ts_decorate([
|
|
119
112
|
UseGuards(JwtAuthGuard),
|
|
120
|
-
|
|
113
|
+
Post('get-companies'),
|
|
114
|
+
HttpCode(HttpStatus.OK),
|
|
121
115
|
ApiBearerAuth(),
|
|
122
116
|
ApiOperation({
|
|
123
117
|
summary: "Get user's available companies",
|
|
@@ -132,14 +126,27 @@ _ts_decorate([
|
|
|
132
126
|
], CompanySelectionController.prototype, "getUserCompanies", null);
|
|
133
127
|
_ts_decorate([
|
|
134
128
|
UseGuards(JwtAuthGuard),
|
|
135
|
-
|
|
129
|
+
Post('get-company-branches'),
|
|
130
|
+
HttpCode(HttpStatus.OK),
|
|
136
131
|
ApiBearerAuth(),
|
|
137
132
|
ApiOperation({
|
|
138
133
|
summary: 'Get branches for a company',
|
|
139
134
|
description: 'Get list of branches for a specific company that the user has access to'
|
|
140
135
|
}),
|
|
136
|
+
ApiBody({
|
|
137
|
+
schema: {
|
|
138
|
+
properties: {
|
|
139
|
+
companyId: {
|
|
140
|
+
type: 'string'
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
required: [
|
|
144
|
+
'companyId'
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
141
148
|
_ts_param(0, CurrentUser('id')),
|
|
142
|
-
_ts_param(1,
|
|
149
|
+
_ts_param(1, Body('companyId')),
|
|
143
150
|
_ts_metadata("design:type", Function),
|
|
144
151
|
_ts_metadata("design:paramtypes", [
|
|
145
152
|
String,
|
|
@@ -25,22 +25,64 @@ 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 { Controller, Inject
|
|
30
|
-
import {
|
|
28
|
+
import { createApiController, COMPANY_PERMISSIONS } from '@flusys/nestjs-shared/classes';
|
|
29
|
+
import { Controller, Inject } from '@nestjs/common';
|
|
30
|
+
import { ApiTags } from '@nestjs/swagger';
|
|
31
31
|
import { CompanyResponseDto, CreateCompanyDto, UpdateCompanyDto } from '../dtos/company.dto';
|
|
32
|
-
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
33
32
|
import { CompanyService } from '../services/company.service';
|
|
34
|
-
export class CompanyController extends createApiController(CreateCompanyDto, UpdateCompanyDto, CompanyResponseDto
|
|
33
|
+
export class CompanyController extends createApiController(CreateCompanyDto, UpdateCompanyDto, CompanyResponseDto, {
|
|
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
|
+
}
|
|
78
|
+
}) {
|
|
35
79
|
constructor(companyService){
|
|
36
80
|
super(companyService), _define_property(this, "companyService", void 0), this.companyService = companyService;
|
|
37
81
|
}
|
|
38
82
|
}
|
|
39
83
|
CompanyController = _ts_decorate([
|
|
40
84
|
ApiTags('Companies'),
|
|
41
|
-
ApiBearerAuth(),
|
|
42
85
|
Controller('administration/company'),
|
|
43
|
-
UseGuards(JwtAuthGuard),
|
|
44
86
|
_ts_param(0, Inject(CompanyService)),
|
|
45
87
|
_ts_metadata("design:type", Function),
|
|
46
88
|
_ts_metadata("design:paramtypes", [
|
|
@@ -25,18 +25,13 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
import { Body, Controller,
|
|
29
|
-
import { ApiBearerAuth, ApiBody, ApiOperation,
|
|
30
|
-
import { JwtAuthGuard } from '@flusys/nestjs-shared
|
|
28
|
+
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
|
|
29
|
+
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
30
|
+
import { JwtAuthGuard, RequirePermission, USER_PERMISSIONS } from '@flusys/nestjs-shared';
|
|
31
31
|
import { AssignUserCompanyDto, AssignUserBranchDto, UserCompaniesResponseDto, UserBranchesResponseDto } from '../dtos/user-permission.dto';
|
|
32
32
|
import { UserPermissionService } from '../services/user-permission.service';
|
|
33
33
|
export class UserPermissionController {
|
|
34
|
-
|
|
35
|
-
// USER-COMPANY PERMISSIONS
|
|
36
|
-
// ========================================================================
|
|
37
|
-
/**
|
|
38
|
-
* Batch assign/revoke user-company permissions
|
|
39
|
-
*/ async assignUserCompany(dto) {
|
|
34
|
+
async assignUserCompany(dto) {
|
|
40
35
|
let addedCount = 0;
|
|
41
36
|
let removedCount = 0;
|
|
42
37
|
for (const item of dto.items){
|
|
@@ -56,11 +51,8 @@ export class UserPermissionController {
|
|
|
56
51
|
message: `Processed ${addedCount} additions and ${removedCount} removals`
|
|
57
52
|
};
|
|
58
53
|
}
|
|
59
|
-
|
|
60
|
-
* Get user's companies
|
|
61
|
-
*/ async getUserCompanies(userId) {
|
|
54
|
+
async getUserCompanies(userId) {
|
|
62
55
|
const permissions = await this.userPermissionService.findUserCompanies(userId);
|
|
63
|
-
// Map to DTO format with populated company details
|
|
64
56
|
const data = permissions.map((permission)=>({
|
|
65
57
|
id: permission.id,
|
|
66
58
|
userId: permission.userId,
|
|
@@ -69,15 +61,12 @@ export class UserPermissionController {
|
|
|
69
61
|
companySlug: permission.company?.slug || ''
|
|
70
62
|
}));
|
|
71
63
|
return {
|
|
64
|
+
success: true,
|
|
65
|
+
message: 'User companies retrieved successfully',
|
|
72
66
|
data
|
|
73
67
|
};
|
|
74
68
|
}
|
|
75
|
-
|
|
76
|
-
// USER-BRANCH PERMISSIONS
|
|
77
|
-
// ========================================================================
|
|
78
|
-
/**
|
|
79
|
-
* Batch assign/revoke user-branch permissions
|
|
80
|
-
*/ async assignUserBranch(dto) {
|
|
69
|
+
async assignUserBranch(dto) {
|
|
81
70
|
let addedCount = 0;
|
|
82
71
|
let removedCount = 0;
|
|
83
72
|
for (const item of dto.items){
|
|
@@ -97,11 +86,8 @@ export class UserPermissionController {
|
|
|
97
86
|
message: `Processed ${addedCount} additions and ${removedCount} removals`
|
|
98
87
|
};
|
|
99
88
|
}
|
|
100
|
-
|
|
101
|
-
* Get user's branches
|
|
102
|
-
*/ async getUserBranches(userId) {
|
|
89
|
+
async getUserBranches(userId) {
|
|
103
90
|
const permissions = await this.userPermissionService.findUserBranches(userId);
|
|
104
|
-
// Map to DTO format with populated branch details
|
|
105
91
|
const data = permissions.map((permission)=>({
|
|
106
92
|
id: permission.id,
|
|
107
93
|
userId: permission.userId,
|
|
@@ -111,10 +97,11 @@ export class UserPermissionController {
|
|
|
111
97
|
companyId: permission.branch?.companyId || ''
|
|
112
98
|
}));
|
|
113
99
|
return {
|
|
100
|
+
success: true,
|
|
101
|
+
message: 'User branches retrieved successfully',
|
|
114
102
|
data
|
|
115
103
|
};
|
|
116
104
|
}
|
|
117
|
-
// NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
|
|
118
105
|
constructor(userPermissionService){
|
|
119
106
|
_define_property(this, "userPermissionService", void 0);
|
|
120
107
|
this.userPermissionService = userPermissionService;
|
|
@@ -122,6 +109,7 @@ export class UserPermissionController {
|
|
|
122
109
|
}
|
|
123
110
|
_ts_decorate([
|
|
124
111
|
Post('user-company/assign'),
|
|
112
|
+
RequirePermission(USER_PERMISSIONS.UPDATE),
|
|
125
113
|
ApiOperation({
|
|
126
114
|
summary: 'Batch assign/revoke user-company permissions',
|
|
127
115
|
description: `
|
|
@@ -176,22 +164,29 @@ Batch operation to assign or revoke user permissions to companies.
|
|
|
176
164
|
_ts_metadata("design:returntype", Promise)
|
|
177
165
|
], UserPermissionController.prototype, "assignUserCompany", null);
|
|
178
166
|
_ts_decorate([
|
|
179
|
-
|
|
167
|
+
Post('get-user-company'),
|
|
168
|
+
RequirePermission(USER_PERMISSIONS.READ),
|
|
180
169
|
ApiOperation({
|
|
181
170
|
summary: 'Get user companies',
|
|
182
171
|
description: 'Returns all companies the user has access to.'
|
|
183
172
|
}),
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
173
|
+
ApiBody({
|
|
174
|
+
schema: {
|
|
175
|
+
properties: {
|
|
176
|
+
userId: {
|
|
177
|
+
type: 'string'
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
required: [
|
|
181
|
+
'userId'
|
|
182
|
+
]
|
|
183
|
+
}
|
|
189
184
|
}),
|
|
190
185
|
ApiResponse({
|
|
191
186
|
status: 200,
|
|
192
187
|
type: UserCompaniesResponseDto
|
|
193
188
|
}),
|
|
194
|
-
_ts_param(0,
|
|
189
|
+
_ts_param(0, Body('userId')),
|
|
195
190
|
_ts_metadata("design:type", Function),
|
|
196
191
|
_ts_metadata("design:paramtypes", [
|
|
197
192
|
String
|
|
@@ -200,6 +195,7 @@ _ts_decorate([
|
|
|
200
195
|
], UserPermissionController.prototype, "getUserCompanies", null);
|
|
201
196
|
_ts_decorate([
|
|
202
197
|
Post('user-branch/assign'),
|
|
198
|
+
RequirePermission(USER_PERMISSIONS.UPDATE),
|
|
203
199
|
ApiOperation({
|
|
204
200
|
summary: 'Batch assign/revoke user-branch permissions',
|
|
205
201
|
description: `
|
|
@@ -254,22 +250,29 @@ Batch operation to assign or revoke user permissions to branches.
|
|
|
254
250
|
_ts_metadata("design:returntype", Promise)
|
|
255
251
|
], UserPermissionController.prototype, "assignUserBranch", null);
|
|
256
252
|
_ts_decorate([
|
|
257
|
-
|
|
253
|
+
Post('get-user-branch'),
|
|
254
|
+
RequirePermission(USER_PERMISSIONS.READ),
|
|
258
255
|
ApiOperation({
|
|
259
256
|
summary: 'Get user branches',
|
|
260
257
|
description: 'Returns all branches the user has access to.'
|
|
261
258
|
}),
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
259
|
+
ApiBody({
|
|
260
|
+
schema: {
|
|
261
|
+
properties: {
|
|
262
|
+
userId: {
|
|
263
|
+
type: 'string'
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
required: [
|
|
267
|
+
'userId'
|
|
268
|
+
]
|
|
269
|
+
}
|
|
267
270
|
}),
|
|
268
271
|
ApiResponse({
|
|
269
272
|
status: 200,
|
|
270
273
|
type: UserBranchesResponseDto
|
|
271
274
|
}),
|
|
272
|
-
_ts_param(0,
|
|
275
|
+
_ts_param(0, Body('userId')),
|
|
273
276
|
_ts_metadata("design:type", Function),
|
|
274
277
|
_ts_metadata("design:paramtypes", [
|
|
275
278
|
String
|
|
@@ -25,60 +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
|
+
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
30
31
|
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
31
|
-
import { Body, Controller, Inject, Param, Post,
|
|
32
|
+
import { Body, Controller, Inject, Param, Post, UseGuards } from '@nestjs/common';
|
|
32
33
|
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
|
|
33
34
|
import { CreateUserDto, UpdateUserDto, UserResponseDto } from '../dtos/user.dto';
|
|
34
|
-
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
35
35
|
import { UserService } from '../services/user.service';
|
|
36
|
-
export class UserController extends createApiController(CreateUserDto, UpdateUserDto, UserResponseDto
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
export class UserController extends createApiController(CreateUserDto, UpdateUserDto, UserResponseDto, {
|
|
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
|
+
}
|
|
81
|
+
}) {
|
|
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) {
|
|
43
90
|
await this.service.verifyEmail(id);
|
|
44
91
|
return {
|
|
92
|
+
success: true,
|
|
45
93
|
message: 'Email verified successfully'
|
|
46
94
|
};
|
|
47
95
|
}
|
|
48
|
-
|
|
49
|
-
* Verify user phone
|
|
50
|
-
*/ async verifyPhone(id) {
|
|
96
|
+
async verifyPhone(id) {
|
|
51
97
|
await this.service.verifyPhone(id);
|
|
52
98
|
return {
|
|
99
|
+
success: true,
|
|
53
100
|
message: 'Phone verified successfully'
|
|
54
101
|
};
|
|
55
102
|
}
|
|
56
|
-
|
|
57
|
-
* Update user active status
|
|
58
|
-
*
|
|
59
|
-
* When company feature is disabled: Updates User.isActive directly
|
|
60
|
-
* When company feature is enabled: Updates UserCompanyPermission.isActive for logged user's company
|
|
61
|
-
*/ async updateStatus(id, isActive, user) {
|
|
103
|
+
async updateStatus(id, isActive, user) {
|
|
62
104
|
await this.service.updateStatus(id, isActive, user);
|
|
63
105
|
return {
|
|
106
|
+
success: true,
|
|
64
107
|
message: 'Status updated successfully'
|
|
65
108
|
};
|
|
66
109
|
}
|
|
67
|
-
|
|
68
|
-
* Update user profile
|
|
69
|
-
*/ async profile(dto, user) {
|
|
110
|
+
async profile(dto, user) {
|
|
70
111
|
const data = await this.service.profile(dto, user);
|
|
71
112
|
return {
|
|
113
|
+
success: true,
|
|
72
114
|
message: 'Profile updated successfully',
|
|
73
115
|
data
|
|
74
116
|
};
|
|
75
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
|
+
}
|
|
76
151
|
constructor(service){
|
|
77
152
|
super(service), _define_property(this, "service", void 0), this.service = service;
|
|
78
153
|
}
|
|
79
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);
|
|
80
177
|
_ts_decorate([
|
|
81
178
|
Post(':id/verify-email'),
|
|
179
|
+
UseGuards(JwtAuthGuard),
|
|
180
|
+
ApiBearerAuth(),
|
|
181
|
+
RequirePermission(USER_PERMISSIONS.UPDATE),
|
|
82
182
|
ApiOperation({
|
|
83
183
|
summary: 'Verify user email'
|
|
84
184
|
}),
|
|
@@ -95,6 +195,9 @@ _ts_decorate([
|
|
|
95
195
|
], UserController.prototype, "verifyEmail", null);
|
|
96
196
|
_ts_decorate([
|
|
97
197
|
Post(':id/verify-phone'),
|
|
198
|
+
UseGuards(JwtAuthGuard),
|
|
199
|
+
ApiBearerAuth(),
|
|
200
|
+
RequirePermission(USER_PERMISSIONS.UPDATE),
|
|
98
201
|
ApiOperation({
|
|
99
202
|
summary: 'Verify user phone'
|
|
100
203
|
}),
|
|
@@ -110,7 +213,10 @@ _ts_decorate([
|
|
|
110
213
|
_ts_metadata("design:returntype", Promise)
|
|
111
214
|
], UserController.prototype, "verifyPhone", null);
|
|
112
215
|
_ts_decorate([
|
|
113
|
-
|
|
216
|
+
Post(':id/status'),
|
|
217
|
+
UseGuards(JwtAuthGuard),
|
|
218
|
+
ApiBearerAuth(),
|
|
219
|
+
RequirePermission(USER_PERMISSIONS.UPDATE),
|
|
114
220
|
ApiOperation({
|
|
115
221
|
summary: 'Update user active status',
|
|
116
222
|
description: 'Updates user active status. When company feature is enabled, updates the status for the current company context.'
|
|
@@ -139,6 +245,8 @@ _ts_decorate([
|
|
|
139
245
|
], UserController.prototype, "updateStatus", null);
|
|
140
246
|
_ts_decorate([
|
|
141
247
|
Post('profile'),
|
|
248
|
+
UseGuards(JwtAuthGuard),
|
|
249
|
+
ApiBearerAuth(),
|
|
142
250
|
ApiOperation({
|
|
143
251
|
summary: 'Update user profile'
|
|
144
252
|
}),
|
|
@@ -154,11 +262,102 @@ _ts_decorate([
|
|
|
154
262
|
]),
|
|
155
263
|
_ts_metadata("design:returntype", Promise)
|
|
156
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);
|
|
157
358
|
UserController = _ts_decorate([
|
|
158
359
|
ApiTags('Users'),
|
|
159
|
-
ApiBearerAuth(),
|
|
160
360
|
Controller('administration/users'),
|
|
161
|
-
UseGuards(JwtAuthGuard),
|
|
162
361
|
_ts_param(0, Inject(UserService)),
|
|
163
362
|
_ts_metadata("design:type", Function),
|
|
164
363
|
_ts_metadata("design:paramtypes", [
|