@flusys/nestjs-auth 7.0.2 → 8.0.0-beta.1
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 +68 -1
- package/config/auth.constants.d.ts +2 -0
- package/config/event-actions.d.ts +2 -0
- package/config/index.d.ts +3 -3
- package/config/message-keys.d.ts +23 -0
- package/controllers/authentication.controller.d.ts +5 -5
- package/controllers/branch.controller.d.ts +2 -2
- package/controllers/company-selection.controller.d.ts +4 -4
- package/controllers/company.controller.d.ts +2 -2
- package/controllers/email-verification.controller.d.ts +6 -6
- package/controllers/index.d.ts +9 -7
- package/controllers/social-auth-config.controller.d.ts +22 -0
- package/controllers/social-auth.controller.d.ts +11 -0
- package/controllers/user-permission.controller.d.ts +5 -4
- package/controllers/user.controller.d.ts +7 -7
- package/docs/auth-swagger.config.d.ts +2 -2
- package/docs/index.d.ts +1 -1
- package/dtos/index.d.ts +6 -5
- package/dtos/social-auth.dto.d.ts +42 -0
- package/entities/company-branch.entity.d.ts +1 -1
- package/entities/company.entity.d.ts +1 -1
- package/entities/index.d.ts +15 -13
- package/entities/pending-registration.entity.d.ts +1 -1
- package/entities/social-auth-config.entity.d.ts +9 -0
- package/entities/user-company-permission.entity.d.ts +4 -4
- package/enums/index.d.ts +2 -1
- package/enums/social-provider-type.enum.d.ts +6 -0
- package/fesm/118.js +1230 -0
- package/fesm/120.js +2197 -0
- package/fesm/24.js +4389 -0
- package/fesm/370.js +1163 -0
- package/fesm/446.js +877 -0
- package/fesm/chunks/117.js +69 -0
- package/fesm/config/index.js +244 -3
- package/fesm/controllers/index.js +27 -7
- package/fesm/docs/index.js +479 -1
- package/fesm/dtos/index.js +123 -5
- package/fesm/entities/index.js +68 -19
- package/fesm/enums/index.js +53 -1
- package/fesm/helpers/index.js +115 -2
- package/fesm/index.js +1437 -12
- package/fesm/interceptors/index.js +508 -2
- package/fesm/interfaces/index.js +75 -7
- package/fesm/modules/index.js +546 -1
- package/fesm/runtime.js +134 -0
- package/fesm/services/index.js +67 -9
- package/helpers/auth-response.mapper.d.ts +3 -3
- package/helpers/index.d.ts +2 -2
- package/helpers/token.helper.d.ts +2 -2
- package/index.d.ts +13 -12
- package/interceptors/clear-token.interceptor.d.ts +2 -2
- package/interceptors/index.d.ts +2 -2
- package/interceptors/set-token.interceptor.d.ts +2 -2
- package/interfaces/auth-module-options.interface.d.ts +3 -3
- package/interfaces/authentication.interface.d.ts +3 -3
- package/interfaces/company-branch.interface.d.ts +2 -2
- package/interfaces/company.interface.d.ts +1 -1
- package/interfaces/index.d.ts +8 -7
- package/interfaces/social-auth.interface.d.ts +43 -0
- package/interfaces/user-enricher.interface.d.ts +3 -3
- package/modules/auth.module.d.ts +4 -4
- package/modules/index.d.ts +1 -1
- package/package.json +32 -39
- package/providers/facebook.social-provider.d.ts +10 -0
- package/providers/google.social-provider.d.ts +10 -0
- package/providers/index.d.ts +1 -0
- package/providers/linkedin.social-provider.d.ts +10 -0
- package/providers/microsoft.social-provider.d.ts +10 -0
- package/providers/oauth-http.util.d.ts +10 -0
- package/providers/social-provider.registry.d.ts +3 -0
- package/services/auth-config.service.d.ts +4 -3
- package/services/auth-datasource.provider.d.ts +4 -3
- package/services/auth-email.service.d.ts +3 -3
- package/services/authentication.service.d.ts +15 -11
- package/services/branch.service.d.ts +7 -7
- package/services/company.service.d.ts +6 -6
- package/services/index.d.ts +11 -9
- package/services/social-auth-config.service.d.ts +21 -0
- package/services/social-auth.service.d.ts +24 -0
- package/services/user-permission.service.d.ts +8 -4
- package/services/user.service.d.ts +7 -7
- package/strategies/jwt.strategy.d.ts +4 -4
- package/validators/password.validator.d.ts +1 -1
- package/cjs/config/auth.constants.js +0 -41
- package/cjs/config/event-actions.js +0 -45
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -108
- package/cjs/controllers/authentication.controller.js +0 -427
- package/cjs/controllers/authentication.controller.spec.js +0 -219
- package/cjs/controllers/branch.controller.js +0 -102
- package/cjs/controllers/branch.controller.spec.js +0 -134
- package/cjs/controllers/company-selection.controller.js +0 -198
- package/cjs/controllers/company-selection.controller.spec.js +0 -84
- package/cjs/controllers/company.controller.js +0 -102
- package/cjs/controllers/company.controller.spec.js +0 -131
- package/cjs/controllers/email-verification.controller.js +0 -224
- package/cjs/controllers/email-verification.controller.spec.js +0 -142
- package/cjs/controllers/index.js +0 -24
- package/cjs/controllers/user-permission.controller.js +0 -223
- package/cjs/controllers/user-permission.controller.spec.js +0 -138
- package/cjs/controllers/user.controller.js +0 -438
- package/cjs/controllers/user.controller.spec.js +0 -204
- package/cjs/docs/auth-swagger.config.js +0 -453
- package/cjs/docs/auth-swagger.config.spec.js +0 -130
- package/cjs/docs/index.js +0 -18
- package/cjs/dtos/authentication.dto.js +0 -755
- package/cjs/dtos/company-branch.dto.js +0 -294
- package/cjs/dtos/company.dto.js +0 -298
- package/cjs/dtos/index.js +0 -22
- package/cjs/dtos/user-permission.dto.js +0 -358
- package/cjs/dtos/user.dto.js +0 -413
- package/cjs/entities/app-user.entity.js +0 -25
- package/cjs/entities/company-branch.entity.js +0 -163
- package/cjs/entities/company.entity.js +0 -146
- package/cjs/entities/index.js +0 -65
- package/cjs/entities/index.spec.js +0 -73
- package/cjs/entities/pending-registration.entity.js +0 -135
- package/cjs/entities/user-company-permission.entity.js +0 -153
- package/cjs/entities/user-token.entity.js +0 -120
- package/cjs/enums/index.js +0 -18
- package/cjs/enums/user-org-permission-type.enum.js +0 -15
- package/cjs/helpers/auth-response.mapper.js +0 -46
- package/cjs/helpers/auth-response.mapper.spec.js +0 -139
- package/cjs/helpers/index.js +0 -19
- package/cjs/helpers/token.helper.js +0 -58
- package/cjs/helpers/token.helper.spec.js +0 -86
- package/cjs/index.js +0 -29
- package/cjs/interceptors/clear-token.interceptor.js +0 -73
- package/cjs/interceptors/clear-token.interceptor.spec.js +0 -107
- package/cjs/interceptors/index.js +0 -19
- package/cjs/interceptors/set-token.interceptor.js +0 -107
- package/cjs/interceptors/set-token.interceptor.spec.js +0 -165
- package/cjs/interfaces/auth-email-provider.interface.js +0 -45
- package/cjs/interfaces/auth-module-options.interface.js +0 -4
- package/cjs/interfaces/authentication.interface.js +0 -4
- package/cjs/interfaces/company-branch.interface.js +0 -4
- package/cjs/interfaces/company.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -24
- package/cjs/interfaces/user-enricher.interface.js +0 -4
- package/cjs/interfaces/user.interface.js +0 -4
- package/cjs/modules/auth.module.js +0 -202
- package/cjs/modules/auth.module.spec.js +0 -243
- package/cjs/modules/index.js +0 -18
- package/cjs/services/auth-config.service.js +0 -110
- package/cjs/services/auth-config.service.spec.js +0 -97
- package/cjs/services/auth-datasource.provider.js +0 -134
- package/cjs/services/auth-datasource.provider.spec.js +0 -161
- package/cjs/services/auth-email.service.js +0 -539
- package/cjs/services/auth-email.service.spec.js +0 -456
- package/cjs/services/authentication.service.js +0 -1173
- package/cjs/services/authentication.service.spec.js +0 -962
- package/cjs/services/branch.service.js +0 -153
- package/cjs/services/branch.service.spec.js +0 -169
- package/cjs/services/company-selection-session.service.js +0 -121
- package/cjs/services/company-selection-session.service.spec.js +0 -90
- package/cjs/services/company.service.js +0 -140
- package/cjs/services/company.service.spec.js +0 -127
- package/cjs/services/index.js +0 -26
- package/cjs/services/user-permission.service.js +0 -236
- package/cjs/services/user-permission.service.spec.js +0 -254
- package/cjs/services/user.service.js +0 -671
- package/cjs/services/user.service.spec.js +0 -718
- package/cjs/strategies/jwt.strategy.js +0 -140
- package/cjs/strategies/jwt.strategy.spec.js +0 -166
- package/cjs/validators/password.validator.js +0 -45
- package/cjs/validators/password.validator.spec.js +0 -161
- package/fesm/config/auth.constants.js +0 -11
- package/fesm/config/event-actions.js +0 -24
- package/fesm/config/message-keys.js +0 -78
- package/fesm/controllers/authentication.controller.js +0 -417
- package/fesm/controllers/authentication.controller.spec.js +0 -215
- package/fesm/controllers/branch.controller.js +0 -92
- package/fesm/controllers/branch.controller.spec.js +0 -130
- package/fesm/controllers/company-selection.controller.js +0 -188
- package/fesm/controllers/company-selection.controller.spec.js +0 -80
- package/fesm/controllers/company.controller.js +0 -92
- package/fesm/controllers/company.controller.spec.js +0 -127
- package/fesm/controllers/email-verification.controller.js +0 -214
- package/fesm/controllers/email-verification.controller.spec.js +0 -138
- package/fesm/controllers/user-permission.controller.js +0 -213
- package/fesm/controllers/user-permission.controller.spec.js +0 -134
- package/fesm/controllers/user.controller.js +0 -428
- package/fesm/controllers/user.controller.spec.js +0 -200
- package/fesm/docs/auth-swagger.config.js +0 -446
- package/fesm/docs/auth-swagger.config.spec.js +0 -126
- package/fesm/dtos/authentication.dto.js +0 -683
- package/fesm/dtos/company-branch.dto.js +0 -279
- package/fesm/dtos/company.dto.js +0 -283
- package/fesm/dtos/user-permission.dto.js +0 -339
- package/fesm/dtos/user.dto.js +0 -391
- package/fesm/entities/app-user.entity.js +0 -15
- package/fesm/entities/company-branch.entity.js +0 -153
- package/fesm/entities/company.entity.js +0 -136
- package/fesm/entities/index.spec.js +0 -69
- package/fesm/entities/pending-registration.entity.js +0 -125
- package/fesm/entities/user-company-permission.entity.js +0 -136
- package/fesm/entities/user-token.entity.js +0 -104
- package/fesm/enums/user-org-permission-type.enum.js +0 -5
- package/fesm/helpers/auth-response.mapper.js +0 -25
- package/fesm/helpers/auth-response.mapper.spec.js +0 -135
- package/fesm/helpers/token.helper.js +0 -40
- package/fesm/helpers/token.helper.spec.js +0 -82
- package/fesm/interceptors/clear-token.interceptor.js +0 -63
- package/fesm/interceptors/clear-token.interceptor.spec.js +0 -103
- package/fesm/interceptors/set-token.interceptor.js +0 -98
- package/fesm/interceptors/set-token.interceptor.spec.js +0 -161
- package/fesm/interfaces/auth-email-provider.interface.js +0 -38
- package/fesm/interfaces/auth-module-options.interface.js +0 -3
- package/fesm/interfaces/authentication.interface.js +0 -1
- package/fesm/interfaces/company-branch.interface.js +0 -1
- package/fesm/interfaces/company.interface.js +0 -1
- package/fesm/interfaces/user-enricher.interface.js +0 -4
- package/fesm/interfaces/user.interface.js +0 -1
- package/fesm/modules/auth.module.js +0 -192
- package/fesm/modules/auth.module.spec.js +0 -239
- package/fesm/services/auth-config.service.js +0 -100
- package/fesm/services/auth-config.service.spec.js +0 -93
- package/fesm/services/auth-datasource.provider.js +0 -83
- package/fesm/services/auth-datasource.provider.spec.js +0 -157
- package/fesm/services/auth-email.service.js +0 -488
- package/fesm/services/auth-email.service.spec.js +0 -411
- package/fesm/services/authentication.service.js +0 -1122
- package/fesm/services/authentication.service.spec.js +0 -917
- package/fesm/services/branch.service.js +0 -143
- package/fesm/services/branch.service.spec.js +0 -165
- package/fesm/services/company-selection-session.service.js +0 -111
- package/fesm/services/company-selection-session.service.spec.js +0 -86
- package/fesm/services/company.service.js +0 -130
- package/fesm/services/company.service.spec.js +0 -123
- package/fesm/services/user-permission.service.js +0 -226
- package/fesm/services/user-permission.service.spec.js +0 -250
- package/fesm/services/user.service.js +0 -620
- package/fesm/services/user.service.spec.js +0 -673
- package/fesm/strategies/jwt.strategy.js +0 -130
- package/fesm/strategies/jwt.strategy.spec.js +0 -162
- package/fesm/validators/password.validator.js +0 -48
- package/fesm/validators/password.validator.spec.js +0 -157
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { UserPermissionController } from './user-permission.controller';
|
|
2
|
-
import { PermissionType } from '../entities/user-company-permission.entity';
|
|
3
|
-
describe('UserPermissionController', ()=>{
|
|
4
|
-
let controller;
|
|
5
|
-
let mockPermissionService;
|
|
6
|
-
beforeEach(()=>{
|
|
7
|
-
mockPermissionService = {
|
|
8
|
-
findUserCompanies: jest.fn(),
|
|
9
|
-
findUserBranches: jest.fn(),
|
|
10
|
-
assignPermission: jest.fn(),
|
|
11
|
-
revokePermission: jest.fn()
|
|
12
|
-
};
|
|
13
|
-
controller = new UserPermissionController(mockPermissionService);
|
|
14
|
-
});
|
|
15
|
-
describe('assignUserCompany', ()=>{
|
|
16
|
-
it('assigns and revokes company permissions in a single batch', async ()=>{
|
|
17
|
-
const result = await controller.assignUserCompany({
|
|
18
|
-
userId: 'user-1',
|
|
19
|
-
items: [
|
|
20
|
-
{
|
|
21
|
-
targetId: 'company-1',
|
|
22
|
-
isAdd: true
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
targetId: 'company-2',
|
|
26
|
-
isAdd: false
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
});
|
|
30
|
-
expect(mockPermissionService.assignPermission).toHaveBeenCalledWith('user-1', 'company-1', PermissionType.COMPANY);
|
|
31
|
-
expect(mockPermissionService.revokePermission).toHaveBeenCalledWith('user-1', 'company-2', PermissionType.COMPANY);
|
|
32
|
-
expect(result.messageVariables).toEqual({
|
|
33
|
-
added: 1,
|
|
34
|
-
removed: 1
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe('getUserCompanies', ()=>{
|
|
39
|
-
it('maps permission entities to the response DTO shape', async ()=>{
|
|
40
|
-
mockPermissionService.findUserCompanies.mockResolvedValue([
|
|
41
|
-
{
|
|
42
|
-
id: 'perm-1',
|
|
43
|
-
userId: 'user-1',
|
|
44
|
-
targetId: 'company-1',
|
|
45
|
-
company: {
|
|
46
|
-
id: 'company-1',
|
|
47
|
-
name: 'Acme',
|
|
48
|
-
slug: 'acme'
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
]);
|
|
52
|
-
const result = await controller.getUserCompanies('user-1');
|
|
53
|
-
expect(result.data).toEqual([
|
|
54
|
-
{
|
|
55
|
-
id: 'perm-1',
|
|
56
|
-
userId: 'user-1',
|
|
57
|
-
companyId: 'company-1',
|
|
58
|
-
companyName: 'Acme',
|
|
59
|
-
companySlug: 'acme'
|
|
60
|
-
}
|
|
61
|
-
]);
|
|
62
|
-
});
|
|
63
|
-
it('falls back to targetId and empty strings when the company relation is missing', async ()=>{
|
|
64
|
-
mockPermissionService.findUserCompanies.mockResolvedValue([
|
|
65
|
-
{
|
|
66
|
-
id: 'perm-1',
|
|
67
|
-
userId: 'user-1',
|
|
68
|
-
targetId: 'company-1',
|
|
69
|
-
company: undefined
|
|
70
|
-
}
|
|
71
|
-
]);
|
|
72
|
-
const result = await controller.getUserCompanies('user-1');
|
|
73
|
-
expect(result.data[0]).toEqual({
|
|
74
|
-
id: 'perm-1',
|
|
75
|
-
userId: 'user-1',
|
|
76
|
-
companyId: 'company-1',
|
|
77
|
-
companyName: '',
|
|
78
|
-
companySlug: ''
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
describe('assignUserBranch', ()=>{
|
|
83
|
-
it('assigns and revokes branch permissions in a single batch', async ()=>{
|
|
84
|
-
const result = await controller.assignUserBranch({
|
|
85
|
-
userId: 'user-1',
|
|
86
|
-
items: [
|
|
87
|
-
{
|
|
88
|
-
targetId: 'branch-1',
|
|
89
|
-
isAdd: true
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
});
|
|
93
|
-
expect(mockPermissionService.assignPermission).toHaveBeenCalledWith('user-1', 'branch-1', PermissionType.BRANCH);
|
|
94
|
-
expect(result.messageVariables).toEqual({
|
|
95
|
-
added: 1,
|
|
96
|
-
removed: 0
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe('getUserBranches', ()=>{
|
|
101
|
-
it('maps permission entities to the response DTO shape', async ()=>{
|
|
102
|
-
mockPermissionService.findUserBranches.mockResolvedValue([
|
|
103
|
-
{
|
|
104
|
-
id: 'perm-1',
|
|
105
|
-
userId: 'user-1',
|
|
106
|
-
targetId: 'branch-1',
|
|
107
|
-
branch: {
|
|
108
|
-
id: 'branch-1',
|
|
109
|
-
name: 'Main',
|
|
110
|
-
slug: 'main',
|
|
111
|
-
companyId: 'company-1'
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
]);
|
|
115
|
-
const result = await controller.getUserBranches('user-1', 'company-1');
|
|
116
|
-
expect(mockPermissionService.findUserBranches).toHaveBeenCalledWith('user-1', 'company-1');
|
|
117
|
-
expect(result.data).toEqual([
|
|
118
|
-
{
|
|
119
|
-
id: 'perm-1',
|
|
120
|
-
userId: 'user-1',
|
|
121
|
-
branchId: 'branch-1',
|
|
122
|
-
branchName: 'Main',
|
|
123
|
-
branchSlug: 'main',
|
|
124
|
-
companyId: 'company-1'
|
|
125
|
-
}
|
|
126
|
-
]);
|
|
127
|
-
});
|
|
128
|
-
it('supports an optional companyId filter', async ()=>{
|
|
129
|
-
mockPermissionService.findUserBranches.mockResolvedValue([]);
|
|
130
|
-
await controller.getUserBranches('user-1');
|
|
131
|
-
expect(mockPermissionService.findUserBranches).toHaveBeenCalledWith('user-1', undefined);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { createApiController, USER_PERMISSIONS } from '@flusys/nestjs-shared/classes';
|
|
29
|
-
import { CurrentUser, RequireAnyPermission, RequirePermission } from '@flusys/nestjs-shared/decorators';
|
|
30
|
-
import { FilterAndPaginationDto } from '@flusys/nestjs-shared/dtos';
|
|
31
|
-
import { JwtAuthGuard, PermissionGuard } from '@flusys/nestjs-shared/guards';
|
|
32
|
-
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
33
|
-
import { Body, Controller, Inject, Param, Post, Query, UseGuards } from '@nestjs/common';
|
|
34
|
-
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
|
|
35
|
-
import { plainToInstance } from 'class-transformer';
|
|
36
|
-
import { USER_MESSAGES } from '../config';
|
|
37
|
-
import { CreateUserDto, UpdateUserDto, UserLookupResponseDto, UserResponseDto } from '../dtos/user.dto';
|
|
38
|
-
import { UserService } from '../services/user.service';
|
|
39
|
-
export class UserController extends createApiController(CreateUserDto, UpdateUserDto, UserResponseDto, {
|
|
40
|
-
entityName: 'user',
|
|
41
|
-
security: {
|
|
42
|
-
insert: {
|
|
43
|
-
level: 'permission',
|
|
44
|
-
permissions: [
|
|
45
|
-
USER_PERMISSIONS.CREATE
|
|
46
|
-
]
|
|
47
|
-
},
|
|
48
|
-
insertMany: {
|
|
49
|
-
level: 'permission',
|
|
50
|
-
permissions: [
|
|
51
|
-
USER_PERMISSIONS.CREATE
|
|
52
|
-
]
|
|
53
|
-
},
|
|
54
|
-
getById: {
|
|
55
|
-
level: 'permission',
|
|
56
|
-
permissions: [
|
|
57
|
-
USER_PERMISSIONS.READ
|
|
58
|
-
]
|
|
59
|
-
},
|
|
60
|
-
getAll: {
|
|
61
|
-
level: 'permission',
|
|
62
|
-
permissions: [
|
|
63
|
-
USER_PERMISSIONS.READ
|
|
64
|
-
]
|
|
65
|
-
},
|
|
66
|
-
update: {
|
|
67
|
-
level: 'permission',
|
|
68
|
-
permissions: [
|
|
69
|
-
USER_PERMISSIONS.UPDATE
|
|
70
|
-
]
|
|
71
|
-
},
|
|
72
|
-
updateMany: {
|
|
73
|
-
level: 'permission',
|
|
74
|
-
permissions: [
|
|
75
|
-
USER_PERMISSIONS.UPDATE
|
|
76
|
-
]
|
|
77
|
-
},
|
|
78
|
-
delete: {
|
|
79
|
-
level: 'permission',
|
|
80
|
-
permissions: [
|
|
81
|
-
USER_PERMISSIONS.DELETE
|
|
82
|
-
]
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}) {
|
|
86
|
-
async lookup(filterAndPaginationDto, user, search) {
|
|
87
|
-
const result = await this.service.getAll(search ?? '', filterAndPaginationDto, user);
|
|
88
|
-
const data = result.data.map((item)=>plainToInstance(UserLookupResponseDto, item, {
|
|
89
|
-
excludeExtraneousValues: true
|
|
90
|
-
}));
|
|
91
|
-
const page = filterAndPaginationDto.pagination?.currentPage ?? 0;
|
|
92
|
-
const pageSize = filterAndPaginationDto.pagination?.pageSize ?? data.length;
|
|
93
|
-
const totalPages = pageSize > 0 ? Math.ceil(result.total / pageSize) : 1;
|
|
94
|
-
return {
|
|
95
|
-
success: true,
|
|
96
|
-
message: 'Users retrieved successfully',
|
|
97
|
-
messageKey: USER_MESSAGES.LOOKUP_SUCCESS,
|
|
98
|
-
data,
|
|
99
|
-
meta: {
|
|
100
|
-
total: result.total,
|
|
101
|
-
page,
|
|
102
|
-
pageSize,
|
|
103
|
-
count: data.length,
|
|
104
|
-
hasMore: page < totalPages - 1,
|
|
105
|
-
totalPages
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
async getProfileWithExtras(id, user) {
|
|
110
|
-
const data = await this.service.getProfileWithExtras(id, user);
|
|
111
|
-
return {
|
|
112
|
-
success: true,
|
|
113
|
-
message: 'Profile extras retrieved successfully',
|
|
114
|
-
messageKey: USER_MESSAGES.PROFILE_EXTRAS_SUCCESS,
|
|
115
|
-
data
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
async verifyEmail(id) {
|
|
119
|
-
await this.service.verifyEmail(id);
|
|
120
|
-
return {
|
|
121
|
-
success: true,
|
|
122
|
-
message: 'Email verified successfully',
|
|
123
|
-
messageKey: USER_MESSAGES.EMAIL_VERIFY_SUCCESS
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
async verifyPhone(id) {
|
|
127
|
-
await this.service.verifyPhone(id);
|
|
128
|
-
return {
|
|
129
|
-
success: true,
|
|
130
|
-
message: 'Phone verified successfully',
|
|
131
|
-
messageKey: USER_MESSAGES.PHONE_VERIFY_SUCCESS
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
async updateStatus(id, isActive, user) {
|
|
135
|
-
await this.service.updateStatus(id, isActive, user);
|
|
136
|
-
return {
|
|
137
|
-
success: true,
|
|
138
|
-
message: 'Status updated successfully',
|
|
139
|
-
messageKey: USER_MESSAGES.STATUS_UPDATE_SUCCESS
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
async profile(dto, user) {
|
|
143
|
-
const data = await this.service.profile(dto, user);
|
|
144
|
-
return {
|
|
145
|
-
success: true,
|
|
146
|
-
message: 'Profile updated successfully',
|
|
147
|
-
messageKey: USER_MESSAGES.PROFILE_UPDATE_SUCCESS,
|
|
148
|
-
data
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
async getProfileSections() {
|
|
152
|
-
const sections = await this.service.getProfileSections();
|
|
153
|
-
return {
|
|
154
|
-
success: true,
|
|
155
|
-
message: 'Profile sections retrieved successfully',
|
|
156
|
-
messageKey: USER_MESSAGES.PROFILE_SECTIONS_SUCCESS,
|
|
157
|
-
data: sections
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
async getProfileSectionData(id, sectionId, user) {
|
|
161
|
-
const data = await this.service.getProfileSectionData(id, sectionId, user);
|
|
162
|
-
return {
|
|
163
|
-
success: true,
|
|
164
|
-
message: 'Profile section data retrieved successfully',
|
|
165
|
-
messageKey: USER_MESSAGES.PROFILE_SECTION_DATA_SUCCESS,
|
|
166
|
-
data
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
async updateProfileSection(id, sectionId, data, user) {
|
|
170
|
-
await this.service.updateProfileSection(id, sectionId, data, user);
|
|
171
|
-
return {
|
|
172
|
-
success: true,
|
|
173
|
-
message: 'Section updated successfully',
|
|
174
|
-
messageKey: USER_MESSAGES.PROFILE_SECTION_UPDATE_SUCCESS
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
async getProfileCompletion(id, user) {
|
|
178
|
-
const percentage = await this.service.getProfileCompletion(id, user);
|
|
179
|
-
return {
|
|
180
|
-
success: true,
|
|
181
|
-
message: 'Profile completion retrieved successfully',
|
|
182
|
-
messageKey: USER_MESSAGES.PROFILE_COMPLETION_SUCCESS,
|
|
183
|
-
data: {
|
|
184
|
-
completionPercentage: percentage
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
constructor(service){
|
|
189
|
-
super(service), _define_property(this, "service", void 0), this.service = service;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
_ts_decorate([
|
|
193
|
-
Post('lookup'),
|
|
194
|
-
UseGuards(JwtAuthGuard, PermissionGuard),
|
|
195
|
-
ApiBearerAuth(),
|
|
196
|
-
RequireAnyPermission(USER_PERMISSIONS.READ, USER_PERMISSIONS.LOOKUP),
|
|
197
|
-
ApiOperation({
|
|
198
|
-
summary: 'Lookup users for pickers/directory',
|
|
199
|
-
description: 'Lightweight user directory search for selection widgets (event participants, assignees, etc.). ' + 'Returns only id/name/email. Accessible with USER_PERMISSIONS.READ or the narrower USER_PERMISSIONS.LOOKUP, ' + 'so panels that only need to pick a user do not require full user-management access.'
|
|
200
|
-
}),
|
|
201
|
-
ApiQuery({
|
|
202
|
-
name: 'q',
|
|
203
|
-
required: false,
|
|
204
|
-
description: 'Global text search across searchable fields'
|
|
205
|
-
}),
|
|
206
|
-
ApiBody({
|
|
207
|
-
type: FilterAndPaginationDto
|
|
208
|
-
}),
|
|
209
|
-
_ts_param(0, Body()),
|
|
210
|
-
_ts_param(1, CurrentUser()),
|
|
211
|
-
_ts_param(2, Query('q')),
|
|
212
|
-
_ts_metadata("design:type", Function),
|
|
213
|
-
_ts_metadata("design:paramtypes", [
|
|
214
|
-
typeof FilterAndPaginationDto === "undefined" ? Object : FilterAndPaginationDto,
|
|
215
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo,
|
|
216
|
-
String
|
|
217
|
-
]),
|
|
218
|
-
_ts_metadata("design:returntype", Promise)
|
|
219
|
-
], UserController.prototype, "lookup", null);
|
|
220
|
-
_ts_decorate([
|
|
221
|
-
Post(':id/profile-extras'),
|
|
222
|
-
UseGuards(JwtAuthGuard, PermissionGuard),
|
|
223
|
-
ApiBearerAuth(),
|
|
224
|
-
RequirePermission(USER_PERMISSIONS.READ),
|
|
225
|
-
ApiOperation({
|
|
226
|
-
summary: 'Get user profile with extras',
|
|
227
|
-
description: 'Returns user profile along with extra data (roles, permissions, etc.) if UserEnricher is provided.'
|
|
228
|
-
}),
|
|
229
|
-
ApiParam({
|
|
230
|
-
name: 'id',
|
|
231
|
-
description: 'User ID'
|
|
232
|
-
}),
|
|
233
|
-
_ts_param(0, Param('id')),
|
|
234
|
-
_ts_param(1, CurrentUser()),
|
|
235
|
-
_ts_metadata("design:type", Function),
|
|
236
|
-
_ts_metadata("design:paramtypes", [
|
|
237
|
-
String,
|
|
238
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
239
|
-
]),
|
|
240
|
-
_ts_metadata("design:returntype", Promise)
|
|
241
|
-
], UserController.prototype, "getProfileWithExtras", null);
|
|
242
|
-
_ts_decorate([
|
|
243
|
-
Post(':id/verify-email'),
|
|
244
|
-
UseGuards(JwtAuthGuard, PermissionGuard),
|
|
245
|
-
ApiBearerAuth(),
|
|
246
|
-
RequirePermission(USER_PERMISSIONS.UPDATE),
|
|
247
|
-
ApiOperation({
|
|
248
|
-
summary: 'Verify user email'
|
|
249
|
-
}),
|
|
250
|
-
ApiParam({
|
|
251
|
-
name: 'id',
|
|
252
|
-
description: 'User ID'
|
|
253
|
-
}),
|
|
254
|
-
_ts_param(0, Param('id')),
|
|
255
|
-
_ts_metadata("design:type", Function),
|
|
256
|
-
_ts_metadata("design:paramtypes", [
|
|
257
|
-
String
|
|
258
|
-
]),
|
|
259
|
-
_ts_metadata("design:returntype", Promise)
|
|
260
|
-
], UserController.prototype, "verifyEmail", null);
|
|
261
|
-
_ts_decorate([
|
|
262
|
-
Post(':id/verify-phone'),
|
|
263
|
-
UseGuards(JwtAuthGuard, PermissionGuard),
|
|
264
|
-
ApiBearerAuth(),
|
|
265
|
-
RequirePermission(USER_PERMISSIONS.UPDATE),
|
|
266
|
-
ApiOperation({
|
|
267
|
-
summary: 'Verify user phone'
|
|
268
|
-
}),
|
|
269
|
-
ApiParam({
|
|
270
|
-
name: 'id',
|
|
271
|
-
description: 'User ID'
|
|
272
|
-
}),
|
|
273
|
-
_ts_param(0, Param('id')),
|
|
274
|
-
_ts_metadata("design:type", Function),
|
|
275
|
-
_ts_metadata("design:paramtypes", [
|
|
276
|
-
String
|
|
277
|
-
]),
|
|
278
|
-
_ts_metadata("design:returntype", Promise)
|
|
279
|
-
], UserController.prototype, "verifyPhone", null);
|
|
280
|
-
_ts_decorate([
|
|
281
|
-
Post(':id/status'),
|
|
282
|
-
UseGuards(JwtAuthGuard, PermissionGuard),
|
|
283
|
-
ApiBearerAuth(),
|
|
284
|
-
RequirePermission(USER_PERMISSIONS.UPDATE),
|
|
285
|
-
ApiOperation({
|
|
286
|
-
summary: 'Update user active status',
|
|
287
|
-
description: 'Updates user active status. When company feature is enabled, updates the status for the current company context.'
|
|
288
|
-
}),
|
|
289
|
-
ApiParam({
|
|
290
|
-
name: 'id',
|
|
291
|
-
description: 'User ID'
|
|
292
|
-
}),
|
|
293
|
-
ApiBody({
|
|
294
|
-
schema: {
|
|
295
|
-
example: {
|
|
296
|
-
isActive: true
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}),
|
|
300
|
-
_ts_param(0, Param('id')),
|
|
301
|
-
_ts_param(1, Body('isActive')),
|
|
302
|
-
_ts_param(2, CurrentUser()),
|
|
303
|
-
_ts_metadata("design:type", Function),
|
|
304
|
-
_ts_metadata("design:paramtypes", [
|
|
305
|
-
String,
|
|
306
|
-
Boolean,
|
|
307
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
308
|
-
]),
|
|
309
|
-
_ts_metadata("design:returntype", Promise)
|
|
310
|
-
], UserController.prototype, "updateStatus", null);
|
|
311
|
-
_ts_decorate([
|
|
312
|
-
Post('profile'),
|
|
313
|
-
UseGuards(JwtAuthGuard),
|
|
314
|
-
ApiBearerAuth(),
|
|
315
|
-
ApiOperation({
|
|
316
|
-
summary: 'Update user profile'
|
|
317
|
-
}),
|
|
318
|
-
ApiBody({
|
|
319
|
-
type: UpdateUserDto
|
|
320
|
-
}),
|
|
321
|
-
_ts_param(0, Body()),
|
|
322
|
-
_ts_param(1, CurrentUser()),
|
|
323
|
-
_ts_metadata("design:type", Function),
|
|
324
|
-
_ts_metadata("design:paramtypes", [
|
|
325
|
-
typeof UpdateUserDto === "undefined" ? Object : UpdateUserDto,
|
|
326
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
327
|
-
]),
|
|
328
|
-
_ts_metadata("design:returntype", Promise)
|
|
329
|
-
], UserController.prototype, "profile", null);
|
|
330
|
-
_ts_decorate([
|
|
331
|
-
Post('profile-sections'),
|
|
332
|
-
UseGuards(JwtAuthGuard),
|
|
333
|
-
ApiBearerAuth(),
|
|
334
|
-
RequirePermission(USER_PERMISSIONS.READ),
|
|
335
|
-
ApiOperation({
|
|
336
|
-
summary: 'Get profile section definitions',
|
|
337
|
-
description: 'Returns available profile sections for multi-step profile (if enricher configured).'
|
|
338
|
-
}),
|
|
339
|
-
_ts_metadata("design:type", Function),
|
|
340
|
-
_ts_metadata("design:paramtypes", []),
|
|
341
|
-
_ts_metadata("design:returntype", Promise)
|
|
342
|
-
], UserController.prototype, "getProfileSections", null);
|
|
343
|
-
_ts_decorate([
|
|
344
|
-
Post(':id/profile-section/:sectionId'),
|
|
345
|
-
UseGuards(JwtAuthGuard),
|
|
346
|
-
ApiBearerAuth(),
|
|
347
|
-
ApiOperation({
|
|
348
|
-
summary: 'Get profile section data',
|
|
349
|
-
description: 'Returns data for a specific profile section.'
|
|
350
|
-
}),
|
|
351
|
-
ApiParam({
|
|
352
|
-
name: 'id',
|
|
353
|
-
description: 'User ID'
|
|
354
|
-
}),
|
|
355
|
-
ApiParam({
|
|
356
|
-
name: 'sectionId',
|
|
357
|
-
description: 'Section identifier'
|
|
358
|
-
}),
|
|
359
|
-
_ts_param(0, Param('id')),
|
|
360
|
-
_ts_param(1, Param('sectionId')),
|
|
361
|
-
_ts_param(2, CurrentUser()),
|
|
362
|
-
_ts_metadata("design:type", Function),
|
|
363
|
-
_ts_metadata("design:paramtypes", [
|
|
364
|
-
String,
|
|
365
|
-
String,
|
|
366
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
367
|
-
]),
|
|
368
|
-
_ts_metadata("design:returntype", Promise)
|
|
369
|
-
], UserController.prototype, "getProfileSectionData", null);
|
|
370
|
-
_ts_decorate([
|
|
371
|
-
Post(':id/profile-section/:sectionId/update'),
|
|
372
|
-
UseGuards(JwtAuthGuard),
|
|
373
|
-
ApiBearerAuth(),
|
|
374
|
-
ApiOperation({
|
|
375
|
-
summary: 'Update profile section',
|
|
376
|
-
description: 'Updates a specific profile section data.'
|
|
377
|
-
}),
|
|
378
|
-
ApiParam({
|
|
379
|
-
name: 'id',
|
|
380
|
-
description: 'User ID'
|
|
381
|
-
}),
|
|
382
|
-
ApiParam({
|
|
383
|
-
name: 'sectionId',
|
|
384
|
-
description: 'Section identifier'
|
|
385
|
-
}),
|
|
386
|
-
_ts_param(0, Param('id')),
|
|
387
|
-
_ts_param(1, Param('sectionId')),
|
|
388
|
-
_ts_param(2, Body()),
|
|
389
|
-
_ts_param(3, CurrentUser()),
|
|
390
|
-
_ts_metadata("design:type", Function),
|
|
391
|
-
_ts_metadata("design:paramtypes", [
|
|
392
|
-
String,
|
|
393
|
-
String,
|
|
394
|
-
typeof Record === "undefined" ? Object : Record,
|
|
395
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
396
|
-
]),
|
|
397
|
-
_ts_metadata("design:returntype", Promise)
|
|
398
|
-
], UserController.prototype, "updateProfileSection", null);
|
|
399
|
-
_ts_decorate([
|
|
400
|
-
Post(':id/profile-completion'),
|
|
401
|
-
UseGuards(JwtAuthGuard),
|
|
402
|
-
ApiBearerAuth(),
|
|
403
|
-
ApiOperation({
|
|
404
|
-
summary: 'Get profile completion percentage',
|
|
405
|
-
description: 'Returns overall profile completion percentage.'
|
|
406
|
-
}),
|
|
407
|
-
ApiParam({
|
|
408
|
-
name: 'id',
|
|
409
|
-
description: 'User ID'
|
|
410
|
-
}),
|
|
411
|
-
_ts_param(0, Param('id')),
|
|
412
|
-
_ts_param(1, CurrentUser()),
|
|
413
|
-
_ts_metadata("design:type", Function),
|
|
414
|
-
_ts_metadata("design:paramtypes", [
|
|
415
|
-
String,
|
|
416
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
417
|
-
]),
|
|
418
|
-
_ts_metadata("design:returntype", Promise)
|
|
419
|
-
], UserController.prototype, "getProfileCompletion", null);
|
|
420
|
-
UserController = _ts_decorate([
|
|
421
|
-
ApiTags('Users'),
|
|
422
|
-
Controller('administration/users'),
|
|
423
|
-
_ts_param(0, Inject(UserService)),
|
|
424
|
-
_ts_metadata("design:type", Function),
|
|
425
|
-
_ts_metadata("design:paramtypes", [
|
|
426
|
-
typeof UserService === "undefined" ? Object : UserService
|
|
427
|
-
])
|
|
428
|
-
], UserController);
|