@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,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "BranchController", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return BranchController;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _classes = require("@flusys/nestjs-shared/classes");
|
|
12
|
-
const _common = require("@nestjs/common");
|
|
13
|
-
const _swagger = require("@nestjs/swagger");
|
|
14
|
-
const _companybranchdto = require("../dtos/company-branch.dto");
|
|
15
|
-
const _branchservice = require("../services/branch.service");
|
|
16
|
-
function _define_property(obj, key, value) {
|
|
17
|
-
if (key in obj) {
|
|
18
|
-
Object.defineProperty(obj, key, {
|
|
19
|
-
value: value,
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
obj[key] = value;
|
|
26
|
-
}
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
30
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
31
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
32
|
-
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;
|
|
33
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
34
|
-
}
|
|
35
|
-
function _ts_metadata(k, v) {
|
|
36
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
37
|
-
}
|
|
38
|
-
function _ts_param(paramIndex, decorator) {
|
|
39
|
-
return function(target, key) {
|
|
40
|
-
decorator(target, key, paramIndex);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
let BranchController = class BranchController extends (0, _classes.createApiController)(_companybranchdto.CreateCompanyBranchDto, _companybranchdto.UpdateCompanyBranchDto, _companybranchdto.CompanyBranchResponseDto, {
|
|
44
|
-
entityName: 'branch',
|
|
45
|
-
security: {
|
|
46
|
-
insert: {
|
|
47
|
-
level: 'permission',
|
|
48
|
-
permissions: [
|
|
49
|
-
_classes.BRANCH_PERMISSIONS.CREATE
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
insertMany: {
|
|
53
|
-
level: 'permission',
|
|
54
|
-
permissions: [
|
|
55
|
-
_classes.BRANCH_PERMISSIONS.CREATE
|
|
56
|
-
]
|
|
57
|
-
},
|
|
58
|
-
getById: {
|
|
59
|
-
level: 'permission',
|
|
60
|
-
permissions: [
|
|
61
|
-
_classes.BRANCH_PERMISSIONS.READ
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
|
-
getAll: {
|
|
65
|
-
level: 'permission',
|
|
66
|
-
permissions: [
|
|
67
|
-
_classes.BRANCH_PERMISSIONS.READ
|
|
68
|
-
]
|
|
69
|
-
},
|
|
70
|
-
update: {
|
|
71
|
-
level: 'permission',
|
|
72
|
-
permissions: [
|
|
73
|
-
_classes.BRANCH_PERMISSIONS.UPDATE
|
|
74
|
-
]
|
|
75
|
-
},
|
|
76
|
-
updateMany: {
|
|
77
|
-
level: 'permission',
|
|
78
|
-
permissions: [
|
|
79
|
-
_classes.BRANCH_PERMISSIONS.UPDATE
|
|
80
|
-
]
|
|
81
|
-
},
|
|
82
|
-
delete: {
|
|
83
|
-
level: 'permission',
|
|
84
|
-
permissions: [
|
|
85
|
-
_classes.BRANCH_PERMISSIONS.DELETE
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}) {
|
|
90
|
-
constructor(branchService){
|
|
91
|
-
super(branchService), _define_property(this, "branchService", void 0), this.branchService = branchService;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
BranchController = _ts_decorate([
|
|
95
|
-
(0, _swagger.ApiTags)('Branches'),
|
|
96
|
-
(0, _common.Controller)('administration/branch'),
|
|
97
|
-
_ts_param(0, (0, _common.Inject)(_branchservice.BranchService)),
|
|
98
|
-
_ts_metadata("design:type", Function),
|
|
99
|
-
_ts_metadata("design:paramtypes", [
|
|
100
|
-
typeof _branchservice.BranchService === "undefined" ? Object : _branchservice.BranchService
|
|
101
|
-
])
|
|
102
|
-
], BranchController);
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _loggedusermock = require("@test-utils/mocks/logged-user.mock");
|
|
6
|
-
const _branchcontroller = require("./branch.controller");
|
|
7
|
-
function buildBranch(overrides = {}) {
|
|
8
|
-
return {
|
|
9
|
-
id: 'branch-1',
|
|
10
|
-
name: 'Main Branch',
|
|
11
|
-
slug: 'main-branch',
|
|
12
|
-
companyId: 'company-1',
|
|
13
|
-
parentId: null,
|
|
14
|
-
logoId: null,
|
|
15
|
-
address: null,
|
|
16
|
-
phone: null,
|
|
17
|
-
email: null,
|
|
18
|
-
serial: null,
|
|
19
|
-
isActive: true,
|
|
20
|
-
readOnly: false,
|
|
21
|
-
additionalFields: null,
|
|
22
|
-
createdAt: new Date(),
|
|
23
|
-
updatedAt: new Date(),
|
|
24
|
-
...overrides
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
describe('BranchController', ()=>{
|
|
28
|
-
let controller;
|
|
29
|
-
let mockBranchService;
|
|
30
|
-
beforeEach(()=>{
|
|
31
|
-
mockBranchService = {
|
|
32
|
-
insert: jest.fn(),
|
|
33
|
-
insertMany: jest.fn(),
|
|
34
|
-
findById: jest.fn(),
|
|
35
|
-
findByIds: jest.fn(),
|
|
36
|
-
update: jest.fn(),
|
|
37
|
-
updateMany: jest.fn(),
|
|
38
|
-
bulkUpsert: jest.fn(),
|
|
39
|
-
getAll: jest.fn(),
|
|
40
|
-
delete: jest.fn()
|
|
41
|
-
};
|
|
42
|
-
controller = new _branchcontroller.BranchController(mockBranchService);
|
|
43
|
-
});
|
|
44
|
-
it('wires the injected service onto the generated controller base', ()=>{
|
|
45
|
-
expect(controller.branchService).toBe(mockBranchService);
|
|
46
|
-
expect(controller.service).toBe(mockBranchService);
|
|
47
|
-
});
|
|
48
|
-
describe('insert', ()=>{
|
|
49
|
-
it('creates a branch and returns the mapped response', async ()=>{
|
|
50
|
-
const user = (0, _loggedusermock.buildMockUser)();
|
|
51
|
-
const branch = buildBranch();
|
|
52
|
-
mockBranchService.insert.mockResolvedValue(branch);
|
|
53
|
-
const result = await controller.insert({
|
|
54
|
-
name: 'Main Branch',
|
|
55
|
-
slug: 'main-branch',
|
|
56
|
-
companyId: 'company-1'
|
|
57
|
-
}, user);
|
|
58
|
-
expect(mockBranchService.insert).toHaveBeenCalledWith({
|
|
59
|
-
name: 'Main Branch',
|
|
60
|
-
slug: 'main-branch',
|
|
61
|
-
companyId: 'company-1'
|
|
62
|
-
}, user);
|
|
63
|
-
expect(result.success).toBe(true);
|
|
64
|
-
expect(result.data).toEqual(expect.objectContaining({
|
|
65
|
-
id: 'branch-1',
|
|
66
|
-
slug: 'main-branch'
|
|
67
|
-
}));
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
describe('getById', ()=>{
|
|
71
|
-
it('retrieves a branch by id', async ()=>{
|
|
72
|
-
const branch = buildBranch();
|
|
73
|
-
mockBranchService.findById.mockResolvedValue(branch);
|
|
74
|
-
const result = await controller.getById('branch-1', {}, null);
|
|
75
|
-
expect(mockBranchService.findById).toHaveBeenCalledWith('branch-1', null, undefined);
|
|
76
|
-
expect(result.data).toEqual(expect.objectContaining({
|
|
77
|
-
id: 'branch-1'
|
|
78
|
-
}));
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
describe('getAll', ()=>{
|
|
82
|
-
it('paginates branches and maps the response list', async ()=>{
|
|
83
|
-
mockBranchService.getAll.mockResolvedValue({
|
|
84
|
-
data: [
|
|
85
|
-
buildBranch()
|
|
86
|
-
],
|
|
87
|
-
total: 1
|
|
88
|
-
});
|
|
89
|
-
const result = await controller.getAll({}, (0, _loggedusermock.buildMockUser)(), 'main');
|
|
90
|
-
expect(mockBranchService.getAll).toHaveBeenCalledWith('main', {}, (0, _loggedusermock.buildMockUser)());
|
|
91
|
-
expect(result.data).toHaveLength(1);
|
|
92
|
-
expect(result.meta.total).toBe(1);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
describe('update', ()=>{
|
|
96
|
-
it('updates a branch and returns the mapped response', async ()=>{
|
|
97
|
-
const branch = buildBranch({
|
|
98
|
-
name: 'Updated Branch'
|
|
99
|
-
});
|
|
100
|
-
mockBranchService.update.mockResolvedValue(branch);
|
|
101
|
-
const result = await controller.update({
|
|
102
|
-
id: 'branch-1',
|
|
103
|
-
name: 'Updated Branch'
|
|
104
|
-
}, (0, _loggedusermock.buildMockUser)());
|
|
105
|
-
expect(mockBranchService.update).toHaveBeenCalledWith({
|
|
106
|
-
id: 'branch-1',
|
|
107
|
-
name: 'Updated Branch'
|
|
108
|
-
}, (0, _loggedusermock.buildMockUser)());
|
|
109
|
-
expect(result.data).toEqual(expect.objectContaining({
|
|
110
|
-
name: 'Updated Branch'
|
|
111
|
-
}));
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
describe('delete', ()=>{
|
|
115
|
-
it('delegates soft-delete to the service', async ()=>{
|
|
116
|
-
mockBranchService.delete.mockResolvedValue({
|
|
117
|
-
count: 1
|
|
118
|
-
});
|
|
119
|
-
const result = await controller.delete({
|
|
120
|
-
id: [
|
|
121
|
-
'branch-1'
|
|
122
|
-
],
|
|
123
|
-
type: 'delete'
|
|
124
|
-
}, (0, _loggedusermock.buildMockUser)());
|
|
125
|
-
expect(mockBranchService.delete).toHaveBeenCalledWith({
|
|
126
|
-
id: [
|
|
127
|
-
'branch-1'
|
|
128
|
-
],
|
|
129
|
-
type: 'delete'
|
|
130
|
-
}, (0, _loggedusermock.buildMockUser)());
|
|
131
|
-
expect(result.success).toBe(true);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "CompanySelectionController", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return CompanySelectionController;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _config = require("../config");
|
|
12
|
-
const _decorators = require("@flusys/nestjs-shared/decorators");
|
|
13
|
-
const _common = require("@nestjs/common");
|
|
14
|
-
const _swagger = require("@nestjs/swagger");
|
|
15
|
-
const _authenticationdto = require("../dtos/authentication.dto");
|
|
16
|
-
const _guards = require("@flusys/nestjs-shared/guards");
|
|
17
|
-
const _settokeninterceptor = require("../interceptors/set-token.interceptor");
|
|
18
|
-
const _authenticationservice = require("../services/authentication.service");
|
|
19
|
-
function _define_property(obj, key, value) {
|
|
20
|
-
if (key in obj) {
|
|
21
|
-
Object.defineProperty(obj, key, {
|
|
22
|
-
value: value,
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true
|
|
26
|
-
});
|
|
27
|
-
} else {
|
|
28
|
-
obj[key] = value;
|
|
29
|
-
}
|
|
30
|
-
return obj;
|
|
31
|
-
}
|
|
32
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
33
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
34
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
35
|
-
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;
|
|
36
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
37
|
-
}
|
|
38
|
-
function _ts_metadata(k, v) {
|
|
39
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
40
|
-
}
|
|
41
|
-
function _ts_param(paramIndex, decorator) {
|
|
42
|
-
return function(target, key) {
|
|
43
|
-
decorator(target, key, paramIndex);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
let CompanySelectionController = class CompanySelectionController {
|
|
47
|
-
async select(dto) {
|
|
48
|
-
const data = await this.authService.select(dto.sessionId, dto.companyId, dto.branchId);
|
|
49
|
-
return {
|
|
50
|
-
success: true,
|
|
51
|
-
message: 'Company selected successfully',
|
|
52
|
-
messageKey: _config.AUTH_MESSAGES.SELECT_SUCCESS,
|
|
53
|
-
data
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
async switchCompany(userId, dto) {
|
|
57
|
-
const data = await this.authService.switchCompany(userId, dto.companyId, dto.branchId);
|
|
58
|
-
return {
|
|
59
|
-
success: true,
|
|
60
|
-
message: 'Company switched successfully',
|
|
61
|
-
messageKey: _config.AUTH_MESSAGES.SWITCH_COMPANY_SUCCESS,
|
|
62
|
-
data
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
async getUserCompanies(userId) {
|
|
66
|
-
const companies = await this.authService.getUserCompanies(userId);
|
|
67
|
-
return {
|
|
68
|
-
success: true,
|
|
69
|
-
message: 'User companies retrieved successfully',
|
|
70
|
-
messageKey: _config.AUTH_MESSAGES.COMPANY_LIST_SUCCESS,
|
|
71
|
-
data: companies
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
async getUserBranches(userId, companyId) {
|
|
75
|
-
const branches = await this.authService.getUserBranches(userId, companyId);
|
|
76
|
-
return {
|
|
77
|
-
success: true,
|
|
78
|
-
message: 'Company branches retrieved successfully',
|
|
79
|
-
messageKey: _config.AUTH_MESSAGES.BRANCH_LIST_SUCCESS,
|
|
80
|
-
data: branches
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
constructor(authService){
|
|
84
|
-
_define_property(this, "authService", void 0);
|
|
85
|
-
this.authService = authService;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
_ts_decorate([
|
|
89
|
-
(0, _common.Post)('select'),
|
|
90
|
-
(0, _common.HttpCode)(_common.HttpStatus.OK),
|
|
91
|
-
(0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
|
|
92
|
-
(0, _swagger.ApiOperation)({
|
|
93
|
-
summary: 'Select company and branch after login',
|
|
94
|
-
description: 'Complete login by selecting company and branch when multiple options are available'
|
|
95
|
-
}),
|
|
96
|
-
(0, _swagger.ApiBody)({
|
|
97
|
-
type: _authenticationdto.SelectDto
|
|
98
|
-
}),
|
|
99
|
-
(0, _swagger.ApiResponse)({
|
|
100
|
-
status: 200,
|
|
101
|
-
description: 'Company selected, tokens returned'
|
|
102
|
-
}),
|
|
103
|
-
_ts_param(0, (0, _common.Body)()),
|
|
104
|
-
_ts_metadata("design:type", Function),
|
|
105
|
-
_ts_metadata("design:paramtypes", [
|
|
106
|
-
typeof _authenticationdto.SelectDto === "undefined" ? Object : _authenticationdto.SelectDto
|
|
107
|
-
]),
|
|
108
|
-
_ts_metadata("design:returntype", Promise)
|
|
109
|
-
], CompanySelectionController.prototype, "select", null);
|
|
110
|
-
_ts_decorate([
|
|
111
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
112
|
-
(0, _common.Post)('switch-company'),
|
|
113
|
-
(0, _common.HttpCode)(_common.HttpStatus.OK),
|
|
114
|
-
(0, _common.UseInterceptors)(_settokeninterceptor.SetToken),
|
|
115
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
116
|
-
(0, _swagger.ApiOperation)({
|
|
117
|
-
summary: 'Switch to different company/branch',
|
|
118
|
-
description: 'Switch to a different company and branch while already authenticated'
|
|
119
|
-
}),
|
|
120
|
-
(0, _swagger.ApiBody)({
|
|
121
|
-
type: _authenticationdto.SwitchCompanyDto
|
|
122
|
-
}),
|
|
123
|
-
(0, _swagger.ApiResponse)({
|
|
124
|
-
status: 200,
|
|
125
|
-
description: 'Company switched, new tokens returned'
|
|
126
|
-
}),
|
|
127
|
-
_ts_param(0, (0, _decorators.CurrentUser)('id')),
|
|
128
|
-
_ts_param(1, (0, _common.Body)()),
|
|
129
|
-
_ts_metadata("design:type", Function),
|
|
130
|
-
_ts_metadata("design:paramtypes", [
|
|
131
|
-
String,
|
|
132
|
-
typeof _authenticationdto.SwitchCompanyDto === "undefined" ? Object : _authenticationdto.SwitchCompanyDto
|
|
133
|
-
]),
|
|
134
|
-
_ts_metadata("design:returntype", Promise)
|
|
135
|
-
], CompanySelectionController.prototype, "switchCompany", null);
|
|
136
|
-
_ts_decorate([
|
|
137
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
138
|
-
(0, _common.Post)('get-companies'),
|
|
139
|
-
(0, _common.HttpCode)(_common.HttpStatus.OK),
|
|
140
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
141
|
-
(0, _swagger.ApiOperation)({
|
|
142
|
-
summary: "Get user's available companies",
|
|
143
|
-
description: 'Get list of companies the current user has access to'
|
|
144
|
-
}),
|
|
145
|
-
(0, _swagger.ApiResponse)({
|
|
146
|
-
status: 200,
|
|
147
|
-
description: 'User companies retrieved successfully'
|
|
148
|
-
}),
|
|
149
|
-
_ts_param(0, (0, _decorators.CurrentUser)('id')),
|
|
150
|
-
_ts_metadata("design:type", Function),
|
|
151
|
-
_ts_metadata("design:paramtypes", [
|
|
152
|
-
String
|
|
153
|
-
]),
|
|
154
|
-
_ts_metadata("design:returntype", Promise)
|
|
155
|
-
], CompanySelectionController.prototype, "getUserCompanies", null);
|
|
156
|
-
_ts_decorate([
|
|
157
|
-
(0, _common.UseGuards)(_guards.JwtAuthGuard),
|
|
158
|
-
(0, _common.Post)('get-company-branches'),
|
|
159
|
-
(0, _common.HttpCode)(_common.HttpStatus.OK),
|
|
160
|
-
(0, _swagger.ApiBearerAuth)(),
|
|
161
|
-
(0, _swagger.ApiOperation)({
|
|
162
|
-
summary: 'Get branches for a company',
|
|
163
|
-
description: 'Get list of branches for a specific company that the user has access to'
|
|
164
|
-
}),
|
|
165
|
-
(0, _swagger.ApiBody)({
|
|
166
|
-
schema: {
|
|
167
|
-
properties: {
|
|
168
|
-
companyId: {
|
|
169
|
-
type: 'string'
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
required: [
|
|
173
|
-
'companyId'
|
|
174
|
-
]
|
|
175
|
-
}
|
|
176
|
-
}),
|
|
177
|
-
(0, _swagger.ApiResponse)({
|
|
178
|
-
status: 200,
|
|
179
|
-
description: 'Company branches retrieved successfully'
|
|
180
|
-
}),
|
|
181
|
-
_ts_param(0, (0, _decorators.CurrentUser)('id')),
|
|
182
|
-
_ts_param(1, (0, _common.Body)('companyId')),
|
|
183
|
-
_ts_metadata("design:type", Function),
|
|
184
|
-
_ts_metadata("design:paramtypes", [
|
|
185
|
-
String,
|
|
186
|
-
String
|
|
187
|
-
]),
|
|
188
|
-
_ts_metadata("design:returntype", Promise)
|
|
189
|
-
], CompanySelectionController.prototype, "getUserBranches", null);
|
|
190
|
-
CompanySelectionController = _ts_decorate([
|
|
191
|
-
(0, _swagger.ApiTags)('Company Selection'),
|
|
192
|
-
(0, _common.Controller)('auth'),
|
|
193
|
-
_ts_param(0, (0, _common.Inject)(_authenticationservice.AuthenticationService)),
|
|
194
|
-
_ts_metadata("design:type", Function),
|
|
195
|
-
_ts_metadata("design:paramtypes", [
|
|
196
|
-
typeof _authenticationservice.AuthenticationService === "undefined" ? Object : _authenticationservice.AuthenticationService
|
|
197
|
-
])
|
|
198
|
-
], CompanySelectionController);
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
const _companyselectioncontroller = require("./company-selection.controller");
|
|
6
|
-
describe('CompanySelectionController', ()=>{
|
|
7
|
-
let controller;
|
|
8
|
-
let mockAuthService;
|
|
9
|
-
beforeEach(()=>{
|
|
10
|
-
mockAuthService = {
|
|
11
|
-
select: jest.fn(),
|
|
12
|
-
switchCompany: jest.fn(),
|
|
13
|
-
getUserCompanies: jest.fn(),
|
|
14
|
-
getUserBranches: jest.fn()
|
|
15
|
-
};
|
|
16
|
-
controller = new _companyselectioncontroller.CompanySelectionController(mockAuthService);
|
|
17
|
-
});
|
|
18
|
-
describe('select', ()=>{
|
|
19
|
-
it('completes login with the selected company/branch', async ()=>{
|
|
20
|
-
mockAuthService.select.mockResolvedValue({
|
|
21
|
-
accessToken: 'a'
|
|
22
|
-
});
|
|
23
|
-
const result = await controller.select({
|
|
24
|
-
sessionId: 'sess-1',
|
|
25
|
-
companyId: 'company-1',
|
|
26
|
-
branchId: 'branch-1'
|
|
27
|
-
});
|
|
28
|
-
expect(mockAuthService.select).toHaveBeenCalledWith('sess-1', 'company-1', 'branch-1');
|
|
29
|
-
expect(result).toEqual(expect.objectContaining({
|
|
30
|
-
success: true,
|
|
31
|
-
data: {
|
|
32
|
-
accessToken: 'a'
|
|
33
|
-
}
|
|
34
|
-
}));
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe('switchCompany', ()=>{
|
|
38
|
-
it('switches company for the authenticated user', async ()=>{
|
|
39
|
-
mockAuthService.switchCompany.mockResolvedValue({
|
|
40
|
-
accessToken: 'b'
|
|
41
|
-
});
|
|
42
|
-
const result = await controller.switchCompany('user-1', {
|
|
43
|
-
companyId: 'company-2',
|
|
44
|
-
branchId: 'branch-2'
|
|
45
|
-
});
|
|
46
|
-
expect(mockAuthService.switchCompany).toHaveBeenCalledWith('user-1', 'company-2', 'branch-2');
|
|
47
|
-
expect(result.data).toEqual({
|
|
48
|
-
accessToken: 'b'
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe('getUserCompanies', ()=>{
|
|
53
|
-
it('returns the companies the user has access to', async ()=>{
|
|
54
|
-
mockAuthService.getUserCompanies.mockResolvedValue([
|
|
55
|
-
{
|
|
56
|
-
id: 'company-1'
|
|
57
|
-
}
|
|
58
|
-
]);
|
|
59
|
-
const result = await controller.getUserCompanies('user-1');
|
|
60
|
-
expect(mockAuthService.getUserCompanies).toHaveBeenCalledWith('user-1');
|
|
61
|
-
expect(result.data).toEqual([
|
|
62
|
-
{
|
|
63
|
-
id: 'company-1'
|
|
64
|
-
}
|
|
65
|
-
]);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
describe('getUserBranches', ()=>{
|
|
69
|
-
it('returns the branches for the given company', async ()=>{
|
|
70
|
-
mockAuthService.getUserBranches.mockResolvedValue([
|
|
71
|
-
{
|
|
72
|
-
id: 'branch-1'
|
|
73
|
-
}
|
|
74
|
-
]);
|
|
75
|
-
const result = await controller.getUserBranches('user-1', 'company-1');
|
|
76
|
-
expect(mockAuthService.getUserBranches).toHaveBeenCalledWith('user-1', 'company-1');
|
|
77
|
-
expect(result.data).toEqual([
|
|
78
|
-
{
|
|
79
|
-
id: 'branch-1'
|
|
80
|
-
}
|
|
81
|
-
]);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "CompanyController", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return CompanyController;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _classes = require("@flusys/nestjs-shared/classes");
|
|
12
|
-
const _common = require("@nestjs/common");
|
|
13
|
-
const _swagger = require("@nestjs/swagger");
|
|
14
|
-
const _companydto = require("../dtos/company.dto");
|
|
15
|
-
const _companyservice = require("../services/company.service");
|
|
16
|
-
function _define_property(obj, key, value) {
|
|
17
|
-
if (key in obj) {
|
|
18
|
-
Object.defineProperty(obj, key, {
|
|
19
|
-
value: value,
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
obj[key] = value;
|
|
26
|
-
}
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
30
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
31
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
32
|
-
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;
|
|
33
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
34
|
-
}
|
|
35
|
-
function _ts_metadata(k, v) {
|
|
36
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
37
|
-
}
|
|
38
|
-
function _ts_param(paramIndex, decorator) {
|
|
39
|
-
return function(target, key) {
|
|
40
|
-
decorator(target, key, paramIndex);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
let CompanyController = class CompanyController extends (0, _classes.createApiController)(_companydto.CreateCompanyDto, _companydto.UpdateCompanyDto, _companydto.CompanyResponseDto, {
|
|
44
|
-
entityName: 'company',
|
|
45
|
-
security: {
|
|
46
|
-
insert: {
|
|
47
|
-
level: 'permission',
|
|
48
|
-
permissions: [
|
|
49
|
-
_classes.COMPANY_PERMISSIONS.CREATE
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
insertMany: {
|
|
53
|
-
level: 'permission',
|
|
54
|
-
permissions: [
|
|
55
|
-
_classes.COMPANY_PERMISSIONS.CREATE
|
|
56
|
-
]
|
|
57
|
-
},
|
|
58
|
-
getById: {
|
|
59
|
-
level: 'permission',
|
|
60
|
-
permissions: [
|
|
61
|
-
_classes.COMPANY_PERMISSIONS.READ
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
|
-
getAll: {
|
|
65
|
-
level: 'permission',
|
|
66
|
-
permissions: [
|
|
67
|
-
_classes.COMPANY_PERMISSIONS.READ
|
|
68
|
-
]
|
|
69
|
-
},
|
|
70
|
-
update: {
|
|
71
|
-
level: 'permission',
|
|
72
|
-
permissions: [
|
|
73
|
-
_classes.COMPANY_PERMISSIONS.UPDATE
|
|
74
|
-
]
|
|
75
|
-
},
|
|
76
|
-
updateMany: {
|
|
77
|
-
level: 'permission',
|
|
78
|
-
permissions: [
|
|
79
|
-
_classes.COMPANY_PERMISSIONS.UPDATE
|
|
80
|
-
]
|
|
81
|
-
},
|
|
82
|
-
delete: {
|
|
83
|
-
level: 'permission',
|
|
84
|
-
permissions: [
|
|
85
|
-
_classes.COMPANY_PERMISSIONS.DELETE
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}) {
|
|
90
|
-
constructor(companyService){
|
|
91
|
-
super(companyService), _define_property(this, "companyService", void 0), this.companyService = companyService;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
CompanyController = _ts_decorate([
|
|
95
|
-
(0, _swagger.ApiTags)('Companies'),
|
|
96
|
-
(0, _common.Controller)('administration/company'),
|
|
97
|
-
_ts_param(0, (0, _common.Inject)(_companyservice.CompanyService)),
|
|
98
|
-
_ts_metadata("design:type", Function),
|
|
99
|
-
_ts_metadata("design:paramtypes", [
|
|
100
|
-
typeof _companyservice.CompanyService === "undefined" ? Object : _companyservice.CompanyService
|
|
101
|
-
])
|
|
102
|
-
], CompanyController);
|