@flusys/nestjs-auth 1.0.0-beta → 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.
Files changed (95) hide show
  1. package/README.md +274 -291
  2. package/cjs/config/auth.constants.js +12 -0
  3. package/cjs/controllers/authentication.controller.js +219 -10
  4. package/cjs/controllers/branch.controller.js +44 -1
  5. package/cjs/controllers/company-selection.controller.js +27 -20
  6. package/cjs/controllers/company.controller.js +44 -1
  7. package/cjs/controllers/user-permission.controller.js +40 -25
  8. package/cjs/controllers/user.controller.js +211 -7
  9. package/cjs/dtos/authentication.dto.js +119 -13
  10. package/cjs/dtos/user-permission.dto.js +28 -0
  11. package/cjs/dtos/user.dto.js +19 -4
  12. package/cjs/entities/index.js +5 -1
  13. package/cjs/entities/pending-registration.entity.js +125 -0
  14. package/cjs/entities/user-company-permission.entity.js +0 -6
  15. package/cjs/entities/user-token.entity.js +129 -0
  16. package/cjs/guards/auth-throttler.guard.js +53 -0
  17. package/cjs/interceptors/clear-token.interceptor.js +3 -6
  18. package/cjs/interceptors/set-token.interceptor.js +38 -31
  19. package/cjs/interfaces/auth-email-provider.interface.js +45 -0
  20. package/cjs/interfaces/index.js +2 -0
  21. package/cjs/interfaces/user-enricher.interface.js +4 -0
  22. package/cjs/modules/auth.module.js +8 -20
  23. package/cjs/services/auth-config.service.js +23 -2
  24. package/cjs/services/auth-datasource.provider.js +5 -3
  25. package/cjs/services/auth-email.service.js +471 -0
  26. package/cjs/services/authentication.service.js +169 -77
  27. package/cjs/services/branch.service.js +6 -5
  28. package/cjs/services/company-selection-session.service.js +1 -1
  29. package/cjs/services/index.js +1 -0
  30. package/cjs/services/user-permission.service.js +0 -2
  31. package/cjs/services/user.service.js +213 -34
  32. package/cjs/validators/password.validator.js +45 -0
  33. package/config/auth.constants.d.ts +3 -0
  34. package/controllers/authentication.controller.d.ts +13 -9
  35. package/controllers/company-selection.controller.d.ts +6 -2
  36. package/controllers/user.controller.d.ts +33 -0
  37. package/dtos/authentication.dto.d.ts +21 -3
  38. package/dtos/company-branch.dto.d.ts +0 -1
  39. package/dtos/company.dto.d.ts +0 -1
  40. package/dtos/user-permission.dto.d.ts +4 -0
  41. package/dtos/user.dto.d.ts +1 -2
  42. package/entities/index.d.ts +7 -3
  43. package/entities/pending-registration.entity.d.ts +17 -0
  44. package/entities/user-company-permission.entity.d.ts +0 -2
  45. package/entities/user-token.entity.d.ts +15 -0
  46. package/fesm/config/auth.constants.js +6 -2
  47. package/fesm/controllers/authentication.controller.js +221 -12
  48. package/fesm/controllers/branch.controller.js +45 -2
  49. package/fesm/controllers/company-selection.controller.js +28 -21
  50. package/fesm/controllers/company.controller.js +45 -2
  51. package/fesm/controllers/user-permission.controller.js +41 -26
  52. package/fesm/controllers/user.controller.js +214 -10
  53. package/fesm/dtos/authentication.dto.js +106 -14
  54. package/fesm/dtos/user-permission.dto.js +28 -0
  55. package/fesm/dtos/user.dto.js +20 -5
  56. package/fesm/entities/index.js +7 -1
  57. package/fesm/entities/pending-registration.entity.js +115 -0
  58. package/fesm/entities/user-company-permission.entity.js +0 -6
  59. package/fesm/entities/user-token.entity.js +113 -0
  60. package/fesm/guards/auth-throttler.guard.js +43 -0
  61. package/fesm/interceptors/clear-token.interceptor.js +2 -5
  62. package/fesm/interceptors/set-token.interceptor.js +37 -30
  63. package/fesm/interfaces/auth-email-provider.interface.js +38 -0
  64. package/fesm/interfaces/authentication.interface.js +1 -1
  65. package/fesm/interfaces/index.js +2 -0
  66. package/fesm/interfaces/user-enricher.interface.js +26 -0
  67. package/fesm/modules/auth.module.js +10 -22
  68. package/fesm/services/auth-config.service.js +24 -3
  69. package/fesm/services/auth-datasource.provider.js +6 -4
  70. package/fesm/services/auth-email.service.js +420 -0
  71. package/fesm/services/authentication.service.js +169 -77
  72. package/fesm/services/branch.service.js +6 -5
  73. package/fesm/services/company-selection-session.service.js +1 -1
  74. package/fesm/services/index.js +1 -0
  75. package/fesm/services/user-permission.service.js +1 -3
  76. package/fesm/services/user.service.js +215 -36
  77. package/fesm/validators/password.validator.js +48 -0
  78. package/guards/auth-throttler.guard.d.ts +7 -0
  79. package/interceptors/set-token.interceptor.d.ts +1 -0
  80. package/interfaces/auth-email-provider.interface.d.ts +6 -0
  81. package/interfaces/auth-module-options.interface.d.ts +4 -1
  82. package/interfaces/authentication.interface.d.ts +14 -0
  83. package/interfaces/index.d.ts +2 -0
  84. package/interfaces/user-enricher.interface.d.ts +64 -0
  85. package/interfaces/user.interface.d.ts +1 -0
  86. package/modules/auth.module.d.ts +0 -1
  87. package/package.json +4 -4
  88. package/services/auth-config.service.d.ts +5 -1
  89. package/services/auth-email.service.d.ts +51 -0
  90. package/services/authentication.service.d.ts +16 -11
  91. package/services/company-selection-session.service.d.ts +1 -1
  92. package/services/index.d.ts +1 -0
  93. package/services/user-permission.service.d.ts +0 -1
  94. package/services/user.service.d.ts +19 -3
  95. package/validators/password.validator.d.ts +10 -0
@@ -16,14 +16,26 @@ _export(exports, {
16
16
  get BCRYPT_SALT_ROUNDS () {
17
17
  return BCRYPT_SALT_ROUNDS;
18
18
  },
19
+ get DEFAULT_COOKIE_NAME () {
20
+ return DEFAULT_COOKIE_NAME;
21
+ },
22
+ get MAX_COOKIE_BYTES () {
23
+ return MAX_COOKIE_BYTES;
24
+ },
19
25
  get SESSION_CACHE_PREFIX () {
20
26
  return SESSION_CACHE_PREFIX;
21
27
  },
22
28
  get TOKEN_REVOKED_PREFIX () {
23
29
  return TOKEN_REVOKED_PREFIX;
30
+ },
31
+ get USER_ENRICHER () {
32
+ return USER_ENRICHER;
24
33
  }
25
34
  });
26
35
  const AUTH_MODULE_OPTIONS = 'AUTH_MODULE_OPTIONS';
36
+ const USER_ENRICHER = 'USER_ENRICHER';
27
37
  const BCRYPT_SALT_ROUNDS = 12;
38
+ const DEFAULT_COOKIE_NAME = 'fsn_refresh_token';
39
+ const MAX_COOKIE_BYTES = 3500;
28
40
  const SESSION_CACHE_PREFIX = 'auth:session';
29
41
  const TOKEN_REVOKED_PREFIX = 'auth:revoked';
@@ -13,11 +13,14 @@ const _guards = require("@flusys/nestjs-shared/guards");
13
13
  const _interfaces = require("@flusys/nestjs-shared/interfaces");
14
14
  const _common = require("@nestjs/common");
15
15
  const _swagger = require("@nestjs/swagger");
16
+ const _throttler = require("@nestjs/throttler");
16
17
  const _express = require("express");
17
18
  const _authenticationdto = require("../dtos/authentication.dto");
19
+ const _dtos = require("@flusys/nestjs-shared/dtos");
18
20
  const _cleartokeninterceptor = require("../interceptors/clear-token.interceptor");
19
21
  const _settokeninterceptor = require("../interceptors/set-token.interceptor");
20
22
  const _authconfigservice = require("../services/auth-config.service");
23
+ const _authemailservice = require("../services/auth-email.service");
21
24
  const _authenticationservice = require("../services/authentication.service");
22
25
  function _define_property(obj, key, value) {
23
26
  if (key in obj) {
@@ -47,16 +50,20 @@ function _ts_param(paramIndex, decorator) {
47
50
  };
48
51
  }
49
52
  let AuthenticationController = class AuthenticationController {
50
- // Core Endpoints
51
- /** Login - Returns tokens or company/branch selection requirement */ async login(loginDto) {
53
+ buildAuthUrl(req, path) {
54
+ const frontendUrl = this.authConfig?.getFrontendUrl();
55
+ return frontendUrl ? `${frontendUrl}${path}` : `${req.protocol}://${req.get('host')}${path}`;
56
+ }
57
+ async login(loginDto) {
52
58
  const result = await this.authService.login(loginDto.email, loginDto.password);
53
59
  if ('requiresSelection' in result) {
54
60
  return result;
55
61
  }
56
62
  return result;
57
63
  }
58
- /** Register new user. If company feature enabled, can join/create company. */ async register(registrationDto) {
59
- const result = await this.authService.register(registrationDto);
64
+ /** Register new user. If company feature enabled, can join/create company. */ async register(req, registrationDto) {
65
+ const verifyUrlBase = this.buildAuthUrl(req, '/auth/verify-email');
66
+ const result = await this.authService.register(registrationDto, verifyUrlBase);
60
67
  return {
61
68
  ...result,
62
69
  companyFeatureEnabled: this.authConfig?.isCompanyFeatureEnabled() ?? false
@@ -77,26 +84,82 @@ let AuthenticationController = class AuthenticationController {
77
84
  /** Logout - Clears refresh token cookie for browsers */ async logout(userId) {
78
85
  await this.authService.logout(userId);
79
86
  return {
87
+ success: true,
80
88
  message: 'Logged out successfully'
81
89
  };
82
90
  }
83
- /** Change password */ async changePassword(userId, dto) {
91
+ async changePassword(userId, dto) {
84
92
  await this.authService.changePassword(userId, dto.currentPassword, dto.newPassword);
85
93
  return {
94
+ success: true,
86
95
  message: 'Password changed successfully'
87
96
  };
88
97
  }
89
- // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
90
- constructor(authService, authConfig){
98
+ async forgotPassword(req, dto) {
99
+ if (!this.authEmailService) {
100
+ return {
101
+ success: false,
102
+ message: 'Email service is not configured'
103
+ };
104
+ }
105
+ return this.authEmailService.forgotPassword(dto.email, this.buildAuthUrl(req, '/auth/reset-password'));
106
+ }
107
+ async resetPassword(dto) {
108
+ if (!this.authEmailService) {
109
+ return {
110
+ success: false,
111
+ message: 'Email service is not configured'
112
+ };
113
+ }
114
+ return this.authEmailService.resetPassword(dto.token, dto.newPassword);
115
+ }
116
+ async resendVerification(req, dto) {
117
+ if (!this.authEmailService) {
118
+ return {
119
+ success: false,
120
+ message: 'Email service is not configured'
121
+ };
122
+ }
123
+ return this.authEmailService.resendVerificationEmail(dto.email, this.buildAuthUrl(req, '/auth/verify-email'));
124
+ }
125
+ /** Verify email - Verify email using token. Handles both pending registration and existing user verification. */ async verifyEmail(dto) {
126
+ if (!this.authEmailService) {
127
+ return {
128
+ success: false,
129
+ message: 'Email service is not configured'
130
+ };
131
+ }
132
+ const result = await this.authEmailService.verifyEmail(dto.token);
133
+ if (result.type === 'pending') {
134
+ const registrationResult = await this.authService.createUserFromPendingRegistration(result.pending);
135
+ return {
136
+ ...registrationResult,
137
+ companyFeatureEnabled: this.authConfig?.isCompanyFeatureEnabled() ?? false
138
+ };
139
+ }
140
+ return {
141
+ success: true,
142
+ message: result.message
143
+ };
144
+ }
145
+ constructor(authService, authConfig, authEmailService){
91
146
  _define_property(this, "authService", void 0);
92
147
  _define_property(this, "authConfig", void 0);
148
+ _define_property(this, "authEmailService", void 0);
93
149
  this.authService = authService;
94
150
  this.authConfig = authConfig;
151
+ this.authEmailService = authEmailService;
95
152
  }
96
153
  };
97
154
  _ts_decorate([
98
155
  (0, _common.Post)('login'),
99
156
  (0, _common.HttpCode)(_common.HttpStatus.OK),
157
+ (0, _throttler.Throttle)({
158
+ default: {
159
+ limit: 5,
160
+ ttl: 60000
161
+ }
162
+ }),
100
163
  (0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
101
164
  (0, _swagger.ApiOperation)({
102
165
  summary: 'User login'
@@ -122,6 +185,12 @@ _ts_decorate([
122
185
  _ts_decorate([
123
186
  (0, _common.Post)('register'),
124
187
  (0, _common.HttpCode)(_common.HttpStatus.CREATED),
188
+ (0, _throttler.Throttle)({
189
+ default: {
190
+ limit: 3,
191
+ ttl: 60000
192
+ }
193
+ }),
125
194
  (0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
126
195
  (0, _swagger.ApiOperation)({
127
196
  summary: 'Register new user'
@@ -133,9 +202,11 @@ _ts_decorate([
133
202
  status: 201,
134
203
  type: _authenticationdto.RegistrationResponseDto
135
204
  }),
136
- _ts_param(0, (0, _common.Body)()),
205
+ _ts_param(0, (0, _common.Req)()),
206
+ _ts_param(1, (0, _common.Body)()),
137
207
  _ts_metadata("design:type", Function),
138
208
  _ts_metadata("design:paramtypes", [
209
+ typeof _express.Request === "undefined" ? Object : _express.Request,
139
210
  typeof _authenticationdto.RegistrationDto === "undefined" ? Object : _authenticationdto.RegistrationDto
140
211
  ]),
141
212
  _ts_metadata("design:returntype", Promise)
@@ -143,6 +214,12 @@ _ts_decorate([
143
214
  _ts_decorate([
144
215
  (0, _common.Post)('refresh'),
145
216
  (0, _common.HttpCode)(_common.HttpStatus.OK),
217
+ (0, _throttler.Throttle)({
218
+ default: {
219
+ limit: 30,
220
+ ttl: 60000
221
+ }
222
+ }),
146
223
  (0, _swagger.ApiOperation)({
147
224
  summary: 'Refresh access token'
148
225
  }),
@@ -160,7 +237,8 @@ _ts_decorate([
160
237
  ], AuthenticationController.prototype, "refreshToken", null);
161
238
  _ts_decorate([
162
239
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
163
- (0, _common.Get)('me'),
240
+ (0, _common.Post)('me'),
241
+ (0, _throttler.SkipThrottle)(),
164
242
  (0, _swagger.ApiBearerAuth)(),
165
243
  (0, _swagger.ApiOperation)({
166
244
  summary: 'Get current user info'
@@ -180,11 +258,16 @@ _ts_decorate([
180
258
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
181
259
  (0, _common.Post)('logout'),
182
260
  (0, _common.HttpCode)(_common.HttpStatus.OK),
261
+ (0, _throttler.SkipThrottle)(),
183
262
  (0, _common.UseInterceptors)(_cleartokeninterceptor.ClearToken),
184
263
  (0, _swagger.ApiBearerAuth)(),
185
264
  (0, _swagger.ApiOperation)({
186
265
  summary: 'Logout user'
187
266
  }),
267
+ (0, _swagger.ApiResponse)({
268
+ status: 200,
269
+ type: _dtos.MessageResponseDto
270
+ }),
188
271
  _ts_param(0, (0, _decorators.CurrentUser)('id')),
189
272
  _ts_metadata("design:type", Function),
190
273
  _ts_metadata("design:paramtypes", [
@@ -196,6 +279,12 @@ _ts_decorate([
196
279
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
197
280
  (0, _common.Post)('change-password'),
198
281
  (0, _common.HttpCode)(_common.HttpStatus.OK),
282
+ (0, _throttler.Throttle)({
283
+ default: {
284
+ limit: 5,
285
+ ttl: 60000
286
+ }
287
+ }),
199
288
  (0, _swagger.ApiBearerAuth)(),
200
289
  (0, _swagger.ApiOperation)({
201
290
  summary: 'Change password'
@@ -203,6 +292,10 @@ _ts_decorate([
203
292
  (0, _swagger.ApiBody)({
204
293
  type: _authenticationdto.ChangePasswordDto
205
294
  }),
295
+ (0, _swagger.ApiResponse)({
296
+ status: 200,
297
+ type: _dtos.MessageResponseDto
298
+ }),
206
299
  _ts_param(0, (0, _decorators.CurrentUser)('id')),
207
300
  _ts_param(1, (0, _common.Body)()),
208
301
  _ts_metadata("design:type", Function),
@@ -212,15 +305,131 @@ _ts_decorate([
212
305
  ]),
213
306
  _ts_metadata("design:returntype", Promise)
214
307
  ], AuthenticationController.prototype, "changePassword", null);
308
+ _ts_decorate([
309
+ (0, _common.Post)('forgot-password'),
310
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
311
+ (0, _throttler.Throttle)({
312
+ default: {
313
+ limit: 3,
314
+ ttl: 300000
315
+ }
316
+ }),
317
+ (0, _swagger.ApiOperation)({
318
+ summary: 'Request password reset email'
319
+ }),
320
+ (0, _swagger.ApiBody)({
321
+ type: _authenticationdto.ForgotPasswordDto
322
+ }),
323
+ (0, _swagger.ApiResponse)({
324
+ status: 200,
325
+ type: _dtos.MessageResponseDto
326
+ }),
327
+ _ts_param(0, (0, _common.Req)()),
328
+ _ts_param(1, (0, _common.Body)()),
329
+ _ts_metadata("design:type", Function),
330
+ _ts_metadata("design:paramtypes", [
331
+ typeof _express.Request === "undefined" ? Object : _express.Request,
332
+ typeof _authenticationdto.ForgotPasswordDto === "undefined" ? Object : _authenticationdto.ForgotPasswordDto
333
+ ]),
334
+ _ts_metadata("design:returntype", Promise)
335
+ ], AuthenticationController.prototype, "forgotPassword", null);
336
+ _ts_decorate([
337
+ (0, _common.Post)('reset-password'),
338
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
339
+ (0, _throttler.Throttle)({
340
+ default: {
341
+ limit: 5,
342
+ ttl: 900000
343
+ }
344
+ }),
345
+ (0, _swagger.ApiOperation)({
346
+ summary: 'Reset password using token'
347
+ }),
348
+ (0, _swagger.ApiBody)({
349
+ type: _authenticationdto.ResetPasswordDto
350
+ }),
351
+ (0, _swagger.ApiResponse)({
352
+ status: 200,
353
+ type: _dtos.MessageResponseDto
354
+ }),
355
+ _ts_param(0, (0, _common.Body)()),
356
+ _ts_metadata("design:type", Function),
357
+ _ts_metadata("design:paramtypes", [
358
+ typeof _authenticationdto.ResetPasswordDto === "undefined" ? Object : _authenticationdto.ResetPasswordDto
359
+ ]),
360
+ _ts_metadata("design:returntype", Promise)
361
+ ], AuthenticationController.prototype, "resetPassword", null);
362
+ _ts_decorate([
363
+ (0, _common.Post)('resend-verification'),
364
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
365
+ (0, _throttler.Throttle)({
366
+ default: {
367
+ limit: 3,
368
+ ttl: 300000
369
+ }
370
+ }),
371
+ (0, _swagger.ApiOperation)({
372
+ summary: 'Resend email verification link'
373
+ }),
374
+ (0, _swagger.ApiBody)({
375
+ type: _authenticationdto.ResendVerificationDto
376
+ }),
377
+ (0, _swagger.ApiResponse)({
378
+ status: 200,
379
+ type: _dtos.MessageResponseDto
380
+ }),
381
+ _ts_param(0, (0, _common.Req)()),
382
+ _ts_param(1, (0, _common.Body)()),
383
+ _ts_metadata("design:type", Function),
384
+ _ts_metadata("design:paramtypes", [
385
+ typeof _express.Request === "undefined" ? Object : _express.Request,
386
+ typeof _authenticationdto.ResendVerificationDto === "undefined" ? Object : _authenticationdto.ResendVerificationDto
387
+ ]),
388
+ _ts_metadata("design:returntype", Promise)
389
+ ], AuthenticationController.prototype, "resendVerification", null);
390
+ _ts_decorate([
391
+ (0, _common.Post)('verify-email'),
392
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
393
+ (0, _throttler.Throttle)({
394
+ default: {
395
+ limit: 10,
396
+ ttl: 60000
397
+ }
398
+ }),
399
+ (0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
400
+ (0, _swagger.ApiOperation)({
401
+ summary: 'Verify email using token'
402
+ }),
403
+ (0, _swagger.ApiBody)({
404
+ type: _authenticationdto.VerifyEmailDto
405
+ }),
406
+ (0, _swagger.ApiResponse)({
407
+ status: 200,
408
+ type: _dtos.MessageResponseDto
409
+ }),
410
+ (0, _swagger.ApiResponse)({
411
+ status: 200,
412
+ type: _authenticationdto.RegistrationResponseDto
413
+ }),
414
+ _ts_param(0, (0, _common.Body)()),
415
+ _ts_metadata("design:type", Function),
416
+ _ts_metadata("design:paramtypes", [
417
+ typeof _authenticationdto.VerifyEmailDto === "undefined" ? Object : _authenticationdto.VerifyEmailDto
418
+ ]),
419
+ _ts_metadata("design:returntype", Promise)
420
+ ], AuthenticationController.prototype, "verifyEmail", null);
215
421
  AuthenticationController = _ts_decorate([
216
422
  (0, _swagger.ApiTags)('Authentication'),
217
423
  (0, _common.Controller)('auth'),
218
424
  _ts_param(0, (0, _common.Inject)(_authenticationservice.AuthenticationService)),
219
425
  _ts_param(1, (0, _common.Optional)()),
220
426
  _ts_param(1, (0, _common.Inject)(_authconfigservice.AuthConfigService)),
427
+ _ts_param(2, (0, _common.Optional)()),
428
+ _ts_param(2, (0, _common.Inject)(_authemailservice.AuthEmailService)),
221
429
  _ts_metadata("design:type", Function),
222
430
  _ts_metadata("design:paramtypes", [
223
431
  typeof _authenticationservice.AuthenticationService === "undefined" ? Object : _authenticationservice.AuthenticationService,
224
- typeof _authconfigservice.AuthConfigService === "undefined" ? Object : _authconfigservice.AuthConfigService
432
+ typeof _authconfigservice.AuthConfigService === "undefined" ? Object : _authconfigservice.AuthConfigService,
433
+ typeof _authemailservice.AuthEmailService === "undefined" ? Object : _authemailservice.AuthEmailService
225
434
  ])
226
435
  ], AuthenticationController);
@@ -41,7 +41,50 @@ function _ts_param(paramIndex, decorator) {
41
41
  };
42
42
  }
43
43
  let BranchController = class BranchController extends (0, _classes.createApiController)(_companybranchdto.CreateCompanyBranchDto, _companybranchdto.UpdateCompanyBranchDto, _companybranchdto.CompanyBranchResponseDto, {
44
- security: 'jwt'
44
+ security: {
45
+ insert: {
46
+ level: 'permission',
47
+ permissions: [
48
+ _classes.BRANCH_PERMISSIONS.CREATE
49
+ ]
50
+ },
51
+ insertMany: {
52
+ level: 'permission',
53
+ permissions: [
54
+ _classes.BRANCH_PERMISSIONS.CREATE
55
+ ]
56
+ },
57
+ getById: {
58
+ level: 'permission',
59
+ permissions: [
60
+ _classes.BRANCH_PERMISSIONS.READ
61
+ ]
62
+ },
63
+ getAll: {
64
+ level: 'permission',
65
+ permissions: [
66
+ _classes.BRANCH_PERMISSIONS.READ
67
+ ]
68
+ },
69
+ update: {
70
+ level: 'permission',
71
+ permissions: [
72
+ _classes.BRANCH_PERMISSIONS.UPDATE
73
+ ]
74
+ },
75
+ updateMany: {
76
+ level: 'permission',
77
+ permissions: [
78
+ _classes.BRANCH_PERMISSIONS.UPDATE
79
+ ]
80
+ },
81
+ delete: {
82
+ level: 'permission',
83
+ permissions: [
84
+ _classes.BRANCH_PERMISSIONS.DELETE
85
+ ]
86
+ }
87
+ }
45
88
  }) {
46
89
  constructor(branchService){
47
90
  super(branchService), _define_property(this, "branchService", void 0), this.branchService = branchService;
@@ -43,35 +43,28 @@ function _ts_param(paramIndex, decorator) {
43
43
  };
44
44
  }
45
45
  let CompanySelectionController = class CompanySelectionController {
46
- /**
47
- * Select Company & Branch
48
- * Used after login when user needs to select company and branch
49
- */ async select(dto) {
46
+ async select(dto) {
50
47
  return this.authService.select(dto.sessionId, dto.companyId, dto.branchId);
51
48
  }
52
- /**
53
- * Switch Company/Branch
54
- * Used to switch company/branch after already logged in
55
- */ async switchCompany(userId, dto) {
49
+ async switchCompany(userId, dto) {
56
50
  return this.authService.switchCompany(userId, dto.companyId, dto.branchId);
57
51
  }
58
- /**
59
- * Get user's companies
60
- */ async getUserCompanies(userId) {
52
+ async getUserCompanies(userId) {
61
53
  const companies = await this.authService.getUserCompanies(userId);
62
54
  return {
63
- companies
55
+ success: true,
56
+ message: 'User companies retrieved successfully',
57
+ data: companies
64
58
  };
65
59
  }
66
- /**
67
- * Get branches for a specific company
68
- */ async getUserBranches(userId, companyId) {
60
+ async getUserBranches(userId, companyId) {
69
61
  const branches = await this.authService.getUserBranches(userId, companyId);
70
62
  return {
71
- branches
63
+ success: true,
64
+ message: 'Company branches retrieved successfully',
65
+ data: branches
72
66
  };
73
67
  }
74
- // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
75
68
  constructor(authService){
76
69
  _define_property(this, "authService", void 0);
77
70
  this.authService = authService;
@@ -127,7 +120,8 @@ _ts_decorate([
127
120
  ], CompanySelectionController.prototype, "switchCompany", null);
128
121
  _ts_decorate([
129
122
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
130
- (0, _common.Get)('companies'),
123
+ (0, _common.Post)('get-companies'),
124
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
131
125
  (0, _swagger.ApiBearerAuth)(),
132
126
  (0, _swagger.ApiOperation)({
133
127
  summary: "Get user's available companies",
@@ -142,14 +136,27 @@ _ts_decorate([
142
136
  ], CompanySelectionController.prototype, "getUserCompanies", null);
143
137
  _ts_decorate([
144
138
  (0, _common.UseGuards)(_guards.JwtAuthGuard),
145
- (0, _common.Get)('companies/:companyId/branches'),
139
+ (0, _common.Post)('get-company-branches'),
140
+ (0, _common.HttpCode)(_common.HttpStatus.OK),
146
141
  (0, _swagger.ApiBearerAuth)(),
147
142
  (0, _swagger.ApiOperation)({
148
143
  summary: 'Get branches for a company',
149
144
  description: 'Get list of branches for a specific company that the user has access to'
150
145
  }),
146
+ (0, _swagger.ApiBody)({
147
+ schema: {
148
+ properties: {
149
+ companyId: {
150
+ type: 'string'
151
+ }
152
+ },
153
+ required: [
154
+ 'companyId'
155
+ ]
156
+ }
157
+ }),
151
158
  _ts_param(0, (0, _decorators.CurrentUser)('id')),
152
- _ts_param(1, (0, _common.Param)('companyId')),
159
+ _ts_param(1, (0, _common.Body)('companyId')),
153
160
  _ts_metadata("design:type", Function),
154
161
  _ts_metadata("design:paramtypes", [
155
162
  String,
@@ -41,7 +41,50 @@ function _ts_param(paramIndex, decorator) {
41
41
  };
42
42
  }
43
43
  let CompanyController = class CompanyController extends (0, _classes.createApiController)(_companydto.CreateCompanyDto, _companydto.UpdateCompanyDto, _companydto.CompanyResponseDto, {
44
- security: 'jwt'
44
+ security: {
45
+ insert: {
46
+ level: 'permission',
47
+ permissions: [
48
+ _classes.COMPANY_PERMISSIONS.CREATE
49
+ ]
50
+ },
51
+ insertMany: {
52
+ level: 'permission',
53
+ permissions: [
54
+ _classes.COMPANY_PERMISSIONS.CREATE
55
+ ]
56
+ },
57
+ getById: {
58
+ level: 'permission',
59
+ permissions: [
60
+ _classes.COMPANY_PERMISSIONS.READ
61
+ ]
62
+ },
63
+ getAll: {
64
+ level: 'permission',
65
+ permissions: [
66
+ _classes.COMPANY_PERMISSIONS.READ
67
+ ]
68
+ },
69
+ update: {
70
+ level: 'permission',
71
+ permissions: [
72
+ _classes.COMPANY_PERMISSIONS.UPDATE
73
+ ]
74
+ },
75
+ updateMany: {
76
+ level: 'permission',
77
+ permissions: [
78
+ _classes.COMPANY_PERMISSIONS.UPDATE
79
+ ]
80
+ },
81
+ delete: {
82
+ level: 'permission',
83
+ permissions: [
84
+ _classes.COMPANY_PERMISSIONS.DELETE
85
+ ]
86
+ }
87
+ }
45
88
  }) {
46
89
  constructor(companyService){
47
90
  super(companyService), _define_property(this, "companyService", void 0), this.companyService = companyService;