@campxdev/server-shared 1.1.22-alpha.4 → 1.1.23
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/dist/common/config/mongo.config.d.ts +3 -3
- package/dist/common/config/mongo.config.js +23 -23
- package/dist/common/databases/mongoose.repository.d.ts +40 -40
- package/dist/common/databases/mongoose.repository.js +94 -94
- package/dist/common/decorators/request.decorators.d.ts +5 -5
- package/dist/common/decorators/request.decorators.js +36 -36
- package/dist/common/decorators/time-validation.decorator.d.ts +2 -2
- package/dist/common/decorators/time-validation.decorator.js +26 -26
- package/dist/common/filters/unhandled-exception.filter.d.ts +4 -4
- package/dist/common/filters/unhandled-exception.filter.js +38 -38
- package/dist/common/guards/guard.d.ts +8 -8
- package/dist/common/guards/guard.js +24 -24
- package/dist/common/index.d.ts +11 -11
- package/dist/common/index.js +27 -27
- package/dist/common/interceptors/request.interceptor.d.ts +17 -17
- package/dist/common/interceptors/request.interceptor.js +132 -132
- package/dist/common/interfaces/context.interface.d.ts +102 -102
- package/dist/common/interfaces/context.interface.js +2 -2
- package/dist/common/store/request-store.d.ts +32 -32
- package/dist/common/store/request-store.js +125 -125
- package/dist/common/store/store-config.d.ts +6 -6
- package/dist/common/store/store-config.js +23 -23
- package/dist/common/store/store.interceptor.d.ts +5 -5
- package/dist/common/store/store.interceptor.js +37 -37
- package/dist/domain/db-connection.module.d.ts +3 -3
- package/dist/domain/db-connection.module.js +29 -29
- package/dist/domain/entities/department.entity.d.ts +9 -9
- package/dist/domain/entities/department.entity.js +50 -50
- package/dist/domain/entities/evaluator.entity.d.ts +17 -17
- package/dist/domain/entities/evaluator.entity.js +112 -112
- package/dist/domain/entities/leads.entity.d.ts +26 -26
- package/dist/domain/entities/leads.entity.js +161 -161
- package/dist/domain/entities/profile-permission.entity.d.ts +13 -13
- package/dist/domain/entities/profile-permission.entity.js +70 -70
- package/dist/domain/entities/profile.entity.d.ts +25 -25
- package/dist/domain/entities/profile.entity.js +98 -98
- package/dist/domain/entities/program.entity.d.ts +13 -13
- package/dist/domain/entities/program.entity.js +70 -70
- package/dist/domain/entities/student.entity.d.ts +57 -57
- package/dist/domain/entities/student.entity.js +279 -279
- package/dist/domain/entities/user.entity.d.ts +23 -23
- package/dist/domain/entities/user.entity.js +147 -147
- package/dist/domain/index.d.ts +12 -12
- package/dist/domain/index.js +28 -28
- package/dist/domain/schemas/global-users.schema.d.ts +58 -58
- package/dist/domain/schemas/global-users.schema.js +145 -145
- package/dist/domain/schemas/tenant.schema.d.ts +114 -114
- package/dist/domain/schemas/tenant.schema.js +387 -387
- package/dist/domain/shared-domain.module.d.ts +2 -2
- package/dist/domain/shared-domain.module.js +27 -27
- package/dist/index.d.ts +5 -5
- package/dist/index.js +21 -21
- package/dist/permissions/app-permissions/enroll-x-permissions.d.ts +390 -390
- package/dist/permissions/app-permissions/enroll-x-permissions.js +458 -458
- package/dist/permissions/app-permissions/enroll-x-permissions.js.map +1 -1
- package/dist/permissions/app-permissions/exams-permissions.d.ts +745 -745
- package/dist/permissions/app-permissions/exams-permissions.js +1213 -1213
- package/dist/permissions/app-permissions/hostels-permissions.d.ts +241 -241
- package/dist/permissions/app-permissions/hostels-permissions.js +251 -251
- package/dist/permissions/app-permissions/payments-permissions.d.ts +352 -352
- package/dist/permissions/app-permissions/payments-permissions.js +474 -474
- package/dist/permissions/app-permissions/square-permissions.d.ts +1123 -1123
- package/dist/permissions/app-permissions/square-permissions.js +2085 -2085
- package/dist/permissions/check-permission.guard.d.ts +52 -52
- package/dist/permissions/check-permission.guard.js +58 -58
- package/dist/permissions/index.d.ts +7 -7
- package/dist/permissions/index.js +28 -28
- package/dist/permissions/permissions.d.ts +5708 -5708
- package/dist/permissions/permissions.js +116 -116
- package/dist/shared-module/index.d.ts +2 -2
- package/dist/shared-module/index.js +7 -7
- package/dist/shared-module/shared.module.d.ts +10 -10
- package/dist/shared-module/shared.module.js +37 -37
- package/dist/shared-module/shared.service.d.ts +67 -67
- package/dist/shared-module/shared.service.d.ts.map +1 -1
- package/dist/shared-module/shared.service.js +209 -210
- package/dist/shared-module/shared.service.js.map +1 -1
- package/dist/utils/constants.d.ts +25 -25
- package/dist/utils/constants.js +28 -28
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +18 -18
- package/dist/utils/utils.d.ts +24 -24
- package/dist/utils/utils.js +234 -234
- package/package.json +46 -46
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckEvaluator = exports.CHECK_EVALUATOR = exports.CheckPermission = exports.CHECK_PERMISSION_KEY = exports.LeadJwtAuthGuard = exports.JwtAuthGuard = exports.LEAD_AUTHENTICATE = exports.AUTHENTICATE = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
exports.AUTHENTICATE = 'authenticate';
|
|
6
|
-
exports.LEAD_AUTHENTICATE = 'leadAuthenticate';
|
|
7
|
-
const JwtAuthGuard = () => {
|
|
8
|
-
return (0, common_1.SetMetadata)(exports.AUTHENTICATE, true);
|
|
9
|
-
};
|
|
10
|
-
exports.JwtAuthGuard = JwtAuthGuard;
|
|
11
|
-
const LeadJwtAuthGuard = () => {
|
|
12
|
-
return (0, common_1.SetMetadata)(exports.LEAD_AUTHENTICATE, true);
|
|
13
|
-
};
|
|
14
|
-
exports.LeadJwtAuthGuard = LeadJwtAuthGuard;
|
|
15
|
-
exports.CHECK_PERMISSION_KEY = 'checkPermissionKey';
|
|
16
|
-
const CheckPermission = (permission) => {
|
|
17
|
-
return (0, common_1.SetMetadata)(exports.CHECK_PERMISSION_KEY, permission);
|
|
18
|
-
};
|
|
19
|
-
exports.CheckPermission = CheckPermission;
|
|
20
|
-
exports.CHECK_EVALUATOR = 'checkEvaluator';
|
|
21
|
-
const CheckEvaluator = () => {
|
|
22
|
-
return (0, common_1.SetMetadata)(exports.CHECK_EVALUATOR, true);
|
|
23
|
-
};
|
|
24
|
-
exports.CheckEvaluator = CheckEvaluator;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheckEvaluator = exports.CHECK_EVALUATOR = exports.CheckPermission = exports.CHECK_PERMISSION_KEY = exports.LeadJwtAuthGuard = exports.JwtAuthGuard = exports.LEAD_AUTHENTICATE = exports.AUTHENTICATE = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.AUTHENTICATE = 'authenticate';
|
|
6
|
+
exports.LEAD_AUTHENTICATE = 'leadAuthenticate';
|
|
7
|
+
const JwtAuthGuard = () => {
|
|
8
|
+
return (0, common_1.SetMetadata)(exports.AUTHENTICATE, true);
|
|
9
|
+
};
|
|
10
|
+
exports.JwtAuthGuard = JwtAuthGuard;
|
|
11
|
+
const LeadJwtAuthGuard = () => {
|
|
12
|
+
return (0, common_1.SetMetadata)(exports.LEAD_AUTHENTICATE, true);
|
|
13
|
+
};
|
|
14
|
+
exports.LeadJwtAuthGuard = LeadJwtAuthGuard;
|
|
15
|
+
exports.CHECK_PERMISSION_KEY = 'checkPermissionKey';
|
|
16
|
+
const CheckPermission = (permission) => {
|
|
17
|
+
return (0, common_1.SetMetadata)(exports.CHECK_PERMISSION_KEY, permission);
|
|
18
|
+
};
|
|
19
|
+
exports.CheckPermission = CheckPermission;
|
|
20
|
+
exports.CHECK_EVALUATOR = 'checkEvaluator';
|
|
21
|
+
const CheckEvaluator = () => {
|
|
22
|
+
return (0, common_1.SetMetadata)(exports.CHECK_EVALUATOR, true);
|
|
23
|
+
};
|
|
24
|
+
exports.CheckEvaluator = CheckEvaluator;
|
|
25
25
|
//# sourceMappingURL=guard.js.map
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from './config/mongo.config';
|
|
2
|
-
export * from './databases/mongoose.repository';
|
|
3
|
-
export * from './decorators/request.decorators';
|
|
4
|
-
export * from './decorators/time-validation.decorator';
|
|
5
|
-
export * from './filters/unhandled-exception.filter';
|
|
6
|
-
export * from './guards/guard';
|
|
7
|
-
export * from './interceptors/request.interceptor';
|
|
8
|
-
export * from './interfaces/context.interface';
|
|
9
|
-
export * from './store/request-store';
|
|
10
|
-
export * from './store/store-config';
|
|
11
|
-
export * from './store/store.interceptor';
|
|
1
|
+
export * from './config/mongo.config';
|
|
2
|
+
export * from './databases/mongoose.repository';
|
|
3
|
+
export * from './decorators/request.decorators';
|
|
4
|
+
export * from './decorators/time-validation.decorator';
|
|
5
|
+
export * from './filters/unhandled-exception.filter';
|
|
6
|
+
export * from './guards/guard';
|
|
7
|
+
export * from './interceptors/request.interceptor';
|
|
8
|
+
export * from './interfaces/context.interface';
|
|
9
|
+
export * from './store/request-store';
|
|
10
|
+
export * from './store/store-config';
|
|
11
|
+
export * from './store/store.interceptor';
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/common/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./config/mongo.config"), exports);
|
|
18
|
-
__exportStar(require("./databases/mongoose.repository"), exports);
|
|
19
|
-
__exportStar(require("./decorators/request.decorators"), exports);
|
|
20
|
-
__exportStar(require("./decorators/time-validation.decorator"), exports);
|
|
21
|
-
__exportStar(require("./filters/unhandled-exception.filter"), exports);
|
|
22
|
-
__exportStar(require("./guards/guard"), exports);
|
|
23
|
-
__exportStar(require("./interceptors/request.interceptor"), exports);
|
|
24
|
-
__exportStar(require("./interfaces/context.interface"), exports);
|
|
25
|
-
__exportStar(require("./store/request-store"), exports);
|
|
26
|
-
__exportStar(require("./store/store-config"), exports);
|
|
27
|
-
__exportStar(require("./store/store.interceptor"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./config/mongo.config"), exports);
|
|
18
|
+
__exportStar(require("./databases/mongoose.repository"), exports);
|
|
19
|
+
__exportStar(require("./decorators/request.decorators"), exports);
|
|
20
|
+
__exportStar(require("./decorators/time-validation.decorator"), exports);
|
|
21
|
+
__exportStar(require("./filters/unhandled-exception.filter"), exports);
|
|
22
|
+
__exportStar(require("./guards/guard"), exports);
|
|
23
|
+
__exportStar(require("./interceptors/request.interceptor"), exports);
|
|
24
|
+
__exportStar(require("./interfaces/context.interface"), exports);
|
|
25
|
+
__exportStar(require("./store/request-store"), exports);
|
|
26
|
+
__exportStar(require("./store/store-config"), exports);
|
|
27
|
+
__exportStar(require("./store/store.interceptor"), exports);
|
|
28
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
-
import { Reflector } from '@nestjs/core';
|
|
3
|
-
import { SharedService } from '../../shared-module';
|
|
4
|
-
export declare class RequestInterceptor implements NestInterceptor {
|
|
5
|
-
private readonly reflector;
|
|
6
|
-
private readonly sharedService;
|
|
7
|
-
constructor(reflector: Reflector, sharedService: SharedService);
|
|
8
|
-
intercept(context: ExecutionContext, next: CallHandler<any>): Promise<import("rxjs").Observable<any>>;
|
|
9
|
-
private hasAuth;
|
|
10
|
-
private checkAuth;
|
|
11
|
-
private hasPermission;
|
|
12
|
-
private checkPermission;
|
|
13
|
-
private hasLeadAuth;
|
|
14
|
-
private checkLeadAuth;
|
|
15
|
-
private hasEvaluatorAuth;
|
|
16
|
-
private checkEvaluatorAuth;
|
|
17
|
-
}
|
|
1
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { SharedService } from '../../shared-module';
|
|
4
|
+
export declare class RequestInterceptor implements NestInterceptor {
|
|
5
|
+
private readonly reflector;
|
|
6
|
+
private readonly sharedService;
|
|
7
|
+
constructor(reflector: Reflector, sharedService: SharedService);
|
|
8
|
+
intercept(context: ExecutionContext, next: CallHandler<any>): Promise<import("rxjs").Observable<any>>;
|
|
9
|
+
private hasAuth;
|
|
10
|
+
private checkAuth;
|
|
11
|
+
private hasPermission;
|
|
12
|
+
private checkPermission;
|
|
13
|
+
private hasLeadAuth;
|
|
14
|
+
private checkLeadAuth;
|
|
15
|
+
private hasEvaluatorAuth;
|
|
16
|
+
private checkEvaluatorAuth;
|
|
17
|
+
}
|
|
18
18
|
//# sourceMappingURL=request.interceptor.d.ts.map
|
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RequestInterceptor = void 0;
|
|
13
|
-
const common_1 = require("@nestjs/common");
|
|
14
|
-
const core_1 = require("@nestjs/core");
|
|
15
|
-
const check_permission_guard_1 = require("../../permissions/check-permission.guard");
|
|
16
|
-
const shared_module_1 = require("../../shared-module");
|
|
17
|
-
const utils_1 = require("../../utils");
|
|
18
|
-
const guard_1 = require("../guards/guard");
|
|
19
|
-
const request_store_1 = require("../store/request-store");
|
|
20
|
-
let RequestInterceptor = class RequestInterceptor {
|
|
21
|
-
reflector;
|
|
22
|
-
sharedService;
|
|
23
|
-
constructor(reflector, sharedService) {
|
|
24
|
-
this.reflector = reflector;
|
|
25
|
-
this.sharedService = sharedService;
|
|
26
|
-
}
|
|
27
|
-
async intercept(context, next) {
|
|
28
|
-
const data = context.switchToRpc().getData();
|
|
29
|
-
(0, request_store_1.setRequest)(data);
|
|
30
|
-
const connection = await this.sharedService.getConnection(data);
|
|
31
|
-
(0, request_store_1.setTenantDataSource)(connection.rootDataSource);
|
|
32
|
-
(0, request_store_1.setTenantDetails)(data.tenantDetails);
|
|
33
|
-
(0, request_store_1.setUserData)(data.userData);
|
|
34
|
-
// Check if the request is authenticated
|
|
35
|
-
if (this.hasAuth(context))
|
|
36
|
-
this.checkAuth(data.isMicroservice);
|
|
37
|
-
// Check if the request is authenticated as an regular user
|
|
38
|
-
const permission = this.hasPermission(context);
|
|
39
|
-
if (permission.check) {
|
|
40
|
-
await this.checkPermission(permission.permissionSlug, data.isMicroservice);
|
|
41
|
-
}
|
|
42
|
-
// Check if the request is authenticated as lead user
|
|
43
|
-
if (this.hasLeadAuth(context))
|
|
44
|
-
this.checkLeadAuth(data);
|
|
45
|
-
// Check if the request is authenticated as an evaluator
|
|
46
|
-
if (this.hasEvaluatorAuth(context))
|
|
47
|
-
this.checkEvaluatorAuth(data);
|
|
48
|
-
return next.handle();
|
|
49
|
-
}
|
|
50
|
-
hasAuth(context) {
|
|
51
|
-
const authMethod = this.reflector.get(guard_1.AUTHENTICATE, context.getHandler());
|
|
52
|
-
const authClass = this.reflector.get(guard_1.AUTHENTICATE, context.getClass());
|
|
53
|
-
return !!authMethod || !!authClass;
|
|
54
|
-
}
|
|
55
|
-
checkAuth(isMicroService) {
|
|
56
|
-
if (isMicroService)
|
|
57
|
-
return;
|
|
58
|
-
const userData = (0, request_store_1.getUserData)();
|
|
59
|
-
const tenantDetails = (0, request_store_1.getTenantDetails)();
|
|
60
|
-
if (!userData) {
|
|
61
|
-
throw new common_1.UnauthorizedException();
|
|
62
|
-
}
|
|
63
|
-
if (!(0, utils_1.checkEqual)(userData.tenantId, tenantDetails.id)) {
|
|
64
|
-
throw new common_1.UnprocessableEntityException('Invalid Client Request');
|
|
65
|
-
}
|
|
66
|
-
if (!userData.isActive) {
|
|
67
|
-
throw new common_1.UnauthorizedException('User is not active');
|
|
68
|
-
}
|
|
69
|
-
if (!userData.id || !userData.userId) {
|
|
70
|
-
throw new common_1.UnauthorizedException('User is not active');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
hasPermission(context) {
|
|
74
|
-
const methodPermission = this.reflector.get(guard_1.CHECK_PERMISSION_KEY, context.getHandler());
|
|
75
|
-
const classPermission = this.reflector.get(guard_1.CHECK_PERMISSION_KEY, context.getClass());
|
|
76
|
-
return {
|
|
77
|
-
check: !!methodPermission || !!classPermission,
|
|
78
|
-
permissionSlug: methodPermission || classPermission,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
async checkPermission(permission, isMicroservice) {
|
|
82
|
-
if (isMicroservice)
|
|
83
|
-
return;
|
|
84
|
-
this.checkAuth();
|
|
85
|
-
const val = await (0, check_permission_guard_1.validateRequestPermission)(permission, this.sharedService.getCheckPermission());
|
|
86
|
-
if (!val) {
|
|
87
|
-
throw new common_1.ForbiddenException('You are not authorized to perform this action');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
hasLeadAuth(context) {
|
|
91
|
-
const authMethod = this.reflector.get(guard_1.LEAD_AUTHENTICATE, context.getHandler());
|
|
92
|
-
const authClass = this.reflector.get(guard_1.LEAD_AUTHENTICATE, context.getClass());
|
|
93
|
-
return !!authMethod || !!authClass;
|
|
94
|
-
}
|
|
95
|
-
checkLeadAuth(data) {
|
|
96
|
-
if (data.isMicroservice)
|
|
97
|
-
return;
|
|
98
|
-
if (!data.userData) {
|
|
99
|
-
throw new common_1.UnauthorizedException();
|
|
100
|
-
}
|
|
101
|
-
if (!(0, utils_1.checkEqual)(data.userData.tenantId, data.tenantDetails.id)) {
|
|
102
|
-
throw new common_1.UnprocessableEntityException('Invalid Client Request');
|
|
103
|
-
}
|
|
104
|
-
if (!data.userData.leadId) {
|
|
105
|
-
throw new common_1.ForbiddenException('You are not a lead user');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
hasEvaluatorAuth(context) {
|
|
109
|
-
const authMethod = this.reflector.get(guard_1.CHECK_EVALUATOR, context.getHandler());
|
|
110
|
-
const authClass = this.reflector.get(guard_1.CHECK_EVALUATOR, context.getClass());
|
|
111
|
-
return !!authMethod || !!authClass;
|
|
112
|
-
}
|
|
113
|
-
checkEvaluatorAuth(data) {
|
|
114
|
-
if (data.isMicroservice)
|
|
115
|
-
return;
|
|
116
|
-
if (!data.userData) {
|
|
117
|
-
throw new common_1.UnauthorizedException();
|
|
118
|
-
}
|
|
119
|
-
if (!(0, utils_1.checkEqual)(data.userData.tenantId, data.tenantDetails.id)) {
|
|
120
|
-
throw new common_1.UnprocessableEntityException('Invalid Client Request');
|
|
121
|
-
}
|
|
122
|
-
if (!data.userData.evaluatorId) {
|
|
123
|
-
throw new common_1.ForbiddenException('User is not evaluator');
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
RequestInterceptor = __decorate([
|
|
128
|
-
(0, common_1.Injectable)(),
|
|
129
|
-
__metadata("design:paramtypes", [core_1.Reflector,
|
|
130
|
-
shared_module_1.SharedService])
|
|
131
|
-
], RequestInterceptor);
|
|
132
|
-
exports.RequestInterceptor = RequestInterceptor;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RequestInterceptor = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const check_permission_guard_1 = require("../../permissions/check-permission.guard");
|
|
16
|
+
const shared_module_1 = require("../../shared-module");
|
|
17
|
+
const utils_1 = require("../../utils");
|
|
18
|
+
const guard_1 = require("../guards/guard");
|
|
19
|
+
const request_store_1 = require("../store/request-store");
|
|
20
|
+
let RequestInterceptor = class RequestInterceptor {
|
|
21
|
+
reflector;
|
|
22
|
+
sharedService;
|
|
23
|
+
constructor(reflector, sharedService) {
|
|
24
|
+
this.reflector = reflector;
|
|
25
|
+
this.sharedService = sharedService;
|
|
26
|
+
}
|
|
27
|
+
async intercept(context, next) {
|
|
28
|
+
const data = context.switchToRpc().getData();
|
|
29
|
+
(0, request_store_1.setRequest)(data);
|
|
30
|
+
const connection = await this.sharedService.getConnection(data);
|
|
31
|
+
(0, request_store_1.setTenantDataSource)(connection.rootDataSource);
|
|
32
|
+
(0, request_store_1.setTenantDetails)(data.tenantDetails);
|
|
33
|
+
(0, request_store_1.setUserData)(data.userData);
|
|
34
|
+
// Check if the request is authenticated
|
|
35
|
+
if (this.hasAuth(context))
|
|
36
|
+
this.checkAuth(data.isMicroservice);
|
|
37
|
+
// Check if the request is authenticated as an regular user
|
|
38
|
+
const permission = this.hasPermission(context);
|
|
39
|
+
if (permission.check) {
|
|
40
|
+
await this.checkPermission(permission.permissionSlug, data.isMicroservice);
|
|
41
|
+
}
|
|
42
|
+
// Check if the request is authenticated as lead user
|
|
43
|
+
if (this.hasLeadAuth(context))
|
|
44
|
+
this.checkLeadAuth(data);
|
|
45
|
+
// Check if the request is authenticated as an evaluator
|
|
46
|
+
if (this.hasEvaluatorAuth(context))
|
|
47
|
+
this.checkEvaluatorAuth(data);
|
|
48
|
+
return next.handle();
|
|
49
|
+
}
|
|
50
|
+
hasAuth(context) {
|
|
51
|
+
const authMethod = this.reflector.get(guard_1.AUTHENTICATE, context.getHandler());
|
|
52
|
+
const authClass = this.reflector.get(guard_1.AUTHENTICATE, context.getClass());
|
|
53
|
+
return !!authMethod || !!authClass;
|
|
54
|
+
}
|
|
55
|
+
checkAuth(isMicroService) {
|
|
56
|
+
if (isMicroService)
|
|
57
|
+
return;
|
|
58
|
+
const userData = (0, request_store_1.getUserData)();
|
|
59
|
+
const tenantDetails = (0, request_store_1.getTenantDetails)();
|
|
60
|
+
if (!userData) {
|
|
61
|
+
throw new common_1.UnauthorizedException();
|
|
62
|
+
}
|
|
63
|
+
if (!(0, utils_1.checkEqual)(userData.tenantId, tenantDetails.id)) {
|
|
64
|
+
throw new common_1.UnprocessableEntityException('Invalid Client Request');
|
|
65
|
+
}
|
|
66
|
+
if (!userData.isActive) {
|
|
67
|
+
throw new common_1.UnauthorizedException('User is not active');
|
|
68
|
+
}
|
|
69
|
+
if (!userData.id || !userData.userId) {
|
|
70
|
+
throw new common_1.UnauthorizedException('User is not active');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
hasPermission(context) {
|
|
74
|
+
const methodPermission = this.reflector.get(guard_1.CHECK_PERMISSION_KEY, context.getHandler());
|
|
75
|
+
const classPermission = this.reflector.get(guard_1.CHECK_PERMISSION_KEY, context.getClass());
|
|
76
|
+
return {
|
|
77
|
+
check: !!methodPermission || !!classPermission,
|
|
78
|
+
permissionSlug: methodPermission || classPermission,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async checkPermission(permission, isMicroservice) {
|
|
82
|
+
if (isMicroservice)
|
|
83
|
+
return;
|
|
84
|
+
this.checkAuth();
|
|
85
|
+
const val = await (0, check_permission_guard_1.validateRequestPermission)(permission, this.sharedService.getCheckPermission());
|
|
86
|
+
if (!val) {
|
|
87
|
+
throw new common_1.ForbiddenException('You are not authorized to perform this action');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
hasLeadAuth(context) {
|
|
91
|
+
const authMethod = this.reflector.get(guard_1.LEAD_AUTHENTICATE, context.getHandler());
|
|
92
|
+
const authClass = this.reflector.get(guard_1.LEAD_AUTHENTICATE, context.getClass());
|
|
93
|
+
return !!authMethod || !!authClass;
|
|
94
|
+
}
|
|
95
|
+
checkLeadAuth(data) {
|
|
96
|
+
if (data.isMicroservice)
|
|
97
|
+
return;
|
|
98
|
+
if (!data.userData) {
|
|
99
|
+
throw new common_1.UnauthorizedException();
|
|
100
|
+
}
|
|
101
|
+
if (!(0, utils_1.checkEqual)(data.userData.tenantId, data.tenantDetails.id)) {
|
|
102
|
+
throw new common_1.UnprocessableEntityException('Invalid Client Request');
|
|
103
|
+
}
|
|
104
|
+
if (!data.userData.leadId) {
|
|
105
|
+
throw new common_1.ForbiddenException('You are not a lead user');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
hasEvaluatorAuth(context) {
|
|
109
|
+
const authMethod = this.reflector.get(guard_1.CHECK_EVALUATOR, context.getHandler());
|
|
110
|
+
const authClass = this.reflector.get(guard_1.CHECK_EVALUATOR, context.getClass());
|
|
111
|
+
return !!authMethod || !!authClass;
|
|
112
|
+
}
|
|
113
|
+
checkEvaluatorAuth(data) {
|
|
114
|
+
if (data.isMicroservice)
|
|
115
|
+
return;
|
|
116
|
+
if (!data.userData) {
|
|
117
|
+
throw new common_1.UnauthorizedException();
|
|
118
|
+
}
|
|
119
|
+
if (!(0, utils_1.checkEqual)(data.userData.tenantId, data.tenantDetails.id)) {
|
|
120
|
+
throw new common_1.UnprocessableEntityException('Invalid Client Request');
|
|
121
|
+
}
|
|
122
|
+
if (!data.userData.evaluatorId) {
|
|
123
|
+
throw new common_1.ForbiddenException('User is not evaluator');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
RequestInterceptor = __decorate([
|
|
128
|
+
(0, common_1.Injectable)(),
|
|
129
|
+
__metadata("design:paramtypes", [core_1.Reflector,
|
|
130
|
+
shared_module_1.SharedService])
|
|
131
|
+
], RequestInterceptor);
|
|
132
|
+
exports.RequestInterceptor = RequestInterceptor;
|
|
133
133
|
//# sourceMappingURL=request.interceptor.js.map
|
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import * as mongoose from 'mongoose';
|
|
2
|
-
export interface IRequest {
|
|
3
|
-
cmd: {
|
|
4
|
-
cmd: string;
|
|
5
|
-
action: string;
|
|
6
|
-
version?: string;
|
|
7
|
-
service?: string;
|
|
8
|
-
};
|
|
9
|
-
body?: any;
|
|
10
|
-
param?: any;
|
|
11
|
-
query?: any;
|
|
12
|
-
file?: any;
|
|
13
|
-
files?: any;
|
|
14
|
-
request?: {
|
|
15
|
-
subDomain: string;
|
|
16
|
-
sessionId: string;
|
|
17
|
-
};
|
|
18
|
-
tenantDetails?: TenantDetails;
|
|
19
|
-
userData?: UserData;
|
|
20
|
-
isMicroservice?: boolean;
|
|
21
|
-
}
|
|
22
|
-
export interface TenantDetails {
|
|
23
|
-
_id: mongoose.Types.ObjectId;
|
|
24
|
-
id: string;
|
|
25
|
-
name: string;
|
|
26
|
-
subDomain: string;
|
|
27
|
-
host: string;
|
|
28
|
-
port: number;
|
|
29
|
-
username: string;
|
|
30
|
-
password: string;
|
|
31
|
-
database: string;
|
|
32
|
-
env: Env;
|
|
33
|
-
easyWDMSConfig: IEasyWDMSConfig;
|
|
34
|
-
smtp?: SmtpConfig;
|
|
35
|
-
}
|
|
36
|
-
export interface SmtpConfig {
|
|
37
|
-
host: string;
|
|
38
|
-
port: number;
|
|
39
|
-
secure: boolean;
|
|
40
|
-
username: string;
|
|
41
|
-
password: string;
|
|
42
|
-
from: string;
|
|
43
|
-
}
|
|
44
|
-
export interface Env {
|
|
45
|
-
s3AccessKeyId: string;
|
|
46
|
-
s3SecretAccessKey: string;
|
|
47
|
-
s3BucketName: string;
|
|
48
|
-
s3Region: string;
|
|
49
|
-
s3Endpoint: string;
|
|
50
|
-
sentryDsn: null;
|
|
51
|
-
razorpayKey: string;
|
|
52
|
-
razorpaySecret: string;
|
|
53
|
-
clientName: string;
|
|
54
|
-
_id: string;
|
|
55
|
-
}
|
|
56
|
-
export interface SendEmailInterface {
|
|
57
|
-
from: string;
|
|
58
|
-
to: string;
|
|
59
|
-
subject: string;
|
|
60
|
-
html: string;
|
|
61
|
-
smtp: {
|
|
62
|
-
host: string;
|
|
63
|
-
port: number;
|
|
64
|
-
secure: boolean;
|
|
65
|
-
username: string;
|
|
66
|
-
password: string;
|
|
67
|
-
};
|
|
68
|
-
attachments?: any;
|
|
69
|
-
}
|
|
70
|
-
export interface IEasyWDMSConfig {
|
|
71
|
-
_id: string;
|
|
72
|
-
host: string;
|
|
73
|
-
port: number;
|
|
74
|
-
username: string;
|
|
75
|
-
password: string;
|
|
76
|
-
database: string;
|
|
77
|
-
baseApiUrl: string;
|
|
78
|
-
}
|
|
79
|
-
export interface UserData {
|
|
80
|
-
id?: number;
|
|
81
|
-
userId?: string;
|
|
82
|
-
email?: string;
|
|
83
|
-
fullName?: string;
|
|
84
|
-
isSuperUser?: boolean;
|
|
85
|
-
isActive: boolean;
|
|
86
|
-
tenantId?: string;
|
|
87
|
-
evaluatorId?: number;
|
|
88
|
-
leadId?: number;
|
|
89
|
-
userAgent?: string;
|
|
90
|
-
}
|
|
91
|
-
export interface SendFcmMessageInterface {
|
|
92
|
-
tokens: string[];
|
|
93
|
-
title: string;
|
|
94
|
-
body: any;
|
|
95
|
-
senderId: string;
|
|
96
|
-
}
|
|
97
|
-
export interface SendSmsInterface {
|
|
98
|
-
to: string[];
|
|
99
|
-
message: string;
|
|
100
|
-
sender: string;
|
|
101
|
-
apiKey: string;
|
|
102
|
-
}
|
|
1
|
+
import * as mongoose from 'mongoose';
|
|
2
|
+
export interface IRequest {
|
|
3
|
+
cmd: {
|
|
4
|
+
cmd: string;
|
|
5
|
+
action: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
service?: string;
|
|
8
|
+
};
|
|
9
|
+
body?: any;
|
|
10
|
+
param?: any;
|
|
11
|
+
query?: any;
|
|
12
|
+
file?: any;
|
|
13
|
+
files?: any;
|
|
14
|
+
request?: {
|
|
15
|
+
subDomain: string;
|
|
16
|
+
sessionId: string;
|
|
17
|
+
};
|
|
18
|
+
tenantDetails?: TenantDetails;
|
|
19
|
+
userData?: UserData;
|
|
20
|
+
isMicroservice?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface TenantDetails {
|
|
23
|
+
_id: mongoose.Types.ObjectId;
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
subDomain: string;
|
|
27
|
+
host: string;
|
|
28
|
+
port: number;
|
|
29
|
+
username: string;
|
|
30
|
+
password: string;
|
|
31
|
+
database: string;
|
|
32
|
+
env: Env;
|
|
33
|
+
easyWDMSConfig: IEasyWDMSConfig;
|
|
34
|
+
smtp?: SmtpConfig;
|
|
35
|
+
}
|
|
36
|
+
export interface SmtpConfig {
|
|
37
|
+
host: string;
|
|
38
|
+
port: number;
|
|
39
|
+
secure: boolean;
|
|
40
|
+
username: string;
|
|
41
|
+
password: string;
|
|
42
|
+
from: string;
|
|
43
|
+
}
|
|
44
|
+
export interface Env {
|
|
45
|
+
s3AccessKeyId: string;
|
|
46
|
+
s3SecretAccessKey: string;
|
|
47
|
+
s3BucketName: string;
|
|
48
|
+
s3Region: string;
|
|
49
|
+
s3Endpoint: string;
|
|
50
|
+
sentryDsn: null;
|
|
51
|
+
razorpayKey: string;
|
|
52
|
+
razorpaySecret: string;
|
|
53
|
+
clientName: string;
|
|
54
|
+
_id: string;
|
|
55
|
+
}
|
|
56
|
+
export interface SendEmailInterface {
|
|
57
|
+
from: string;
|
|
58
|
+
to: string;
|
|
59
|
+
subject: string;
|
|
60
|
+
html: string;
|
|
61
|
+
smtp: {
|
|
62
|
+
host: string;
|
|
63
|
+
port: number;
|
|
64
|
+
secure: boolean;
|
|
65
|
+
username: string;
|
|
66
|
+
password: string;
|
|
67
|
+
};
|
|
68
|
+
attachments?: any;
|
|
69
|
+
}
|
|
70
|
+
export interface IEasyWDMSConfig {
|
|
71
|
+
_id: string;
|
|
72
|
+
host: string;
|
|
73
|
+
port: number;
|
|
74
|
+
username: string;
|
|
75
|
+
password: string;
|
|
76
|
+
database: string;
|
|
77
|
+
baseApiUrl: string;
|
|
78
|
+
}
|
|
79
|
+
export interface UserData {
|
|
80
|
+
id?: number;
|
|
81
|
+
userId?: string;
|
|
82
|
+
email?: string;
|
|
83
|
+
fullName?: string;
|
|
84
|
+
isSuperUser?: boolean;
|
|
85
|
+
isActive: boolean;
|
|
86
|
+
tenantId?: string;
|
|
87
|
+
evaluatorId?: number;
|
|
88
|
+
leadId?: number;
|
|
89
|
+
userAgent?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface SendFcmMessageInterface {
|
|
92
|
+
tokens: string[];
|
|
93
|
+
title: string;
|
|
94
|
+
body: any;
|
|
95
|
+
senderId: string;
|
|
96
|
+
}
|
|
97
|
+
export interface SendSmsInterface {
|
|
98
|
+
to: string[];
|
|
99
|
+
message: string;
|
|
100
|
+
sender: string;
|
|
101
|
+
apiKey: string;
|
|
102
|
+
}
|
|
103
103
|
//# sourceMappingURL=context.interface.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=context.interface.js.map
|