@tc-libs/request 1.17.0 → 1.18.0
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/package.json +6 -6
- package/src/decorators/entity.get.decorator.d.ts +1 -0
- package/src/decorators/entity.get.decorator.js +5 -0
- package/src/decorators/entity.get.decorator.js.map +1 -1
- package/src/guards/entity.put-to-request-by-slug.guard.d.ts +8 -0
- package/src/guards/entity.put-to-request-by-slug.guard.js +51 -0
- package/src/guards/entity.put-to-request-by-slug.guard.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tc-libs/request",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@tc-libs/service": "1.
|
|
6
|
-
"@tc-libs/errors": "1.
|
|
7
|
-
"@tc-libs/helper": "1.
|
|
8
|
-
"@tc-libs/pagination": "1.
|
|
9
|
-
"@tc-libs/constant": "1.
|
|
5
|
+
"@tc-libs/service": "1.18.0",
|
|
6
|
+
"@tc-libs/errors": "1.18.0",
|
|
7
|
+
"@tc-libs/helper": "1.18.0",
|
|
8
|
+
"@tc-libs/pagination": "1.18.0",
|
|
9
|
+
"@tc-libs/constant": "1.18.0"
|
|
10
10
|
},
|
|
11
11
|
"type": "commonjs",
|
|
12
12
|
"main": "./src/index.js",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common/interfaces';
|
|
2
2
|
import { IService } from '@tc-libs/service';
|
|
3
3
|
export declare function EntityGetByIdGuard(serviceClass: Type<IService<any>>, entityName: string): MethodDecorator;
|
|
4
|
+
export declare function EntityGetBySlugGuard(serviceClass: Type<IService<any>>, entityName: string): MethodDecorator;
|
|
4
5
|
export declare function EntityGetByIdAndUserGuard(serviceClass: Type<IService<any>>, entityName: string): MethodDecorator;
|
|
5
6
|
export declare const GetEntity: (...dataOrPipes: (import("@nestjs/common").PipeTransform<any, any> | Type<import("@nestjs/common").PipeTransform<any, any>> | {
|
|
6
7
|
entity: string;
|
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GetEntity = void 0;
|
|
4
4
|
exports.EntityGetByIdGuard = EntityGetByIdGuard;
|
|
5
|
+
exports.EntityGetBySlugGuard = EntityGetBySlugGuard;
|
|
5
6
|
exports.EntityGetByIdAndUserGuard = EntityGetByIdAndUserGuard;
|
|
6
7
|
const common_1 = require("@nestjs/common");
|
|
7
8
|
const entity_constant_1 = require("../constants/entity.constant");
|
|
8
9
|
const entity_not_found_guard_1 = require("../guards/entity.not-found.guard");
|
|
9
10
|
const entity_put_to_request_by_id_guard_1 = require("../guards/entity.put-to-request-by-id.guard");
|
|
10
11
|
const guards_1 = require("../guards");
|
|
12
|
+
const entity_put_to_request_by_slug_guard_1 = require("../guards/entity.put-to-request-by-slug.guard");
|
|
11
13
|
function EntityGetByIdGuard(serviceClass, entityName) {
|
|
12
14
|
return (0, common_1.applyDecorators)((0, common_1.SetMetadata)(entity_constant_1.ENTITY_SERVICE_DECORATOR_KEY, serviceClass), (0, common_1.SetMetadata)(entity_constant_1.ENTITY_NAME_DECORATOR_KEY, entityName), (0, common_1.UseGuards)(entity_put_to_request_by_id_guard_1.EntityPutToRequestByIdGuard), (0, common_1.UseGuards)(entity_not_found_guard_1.EntityNotFoundGuard));
|
|
13
15
|
}
|
|
16
|
+
function EntityGetBySlugGuard(serviceClass, entityName) {
|
|
17
|
+
return (0, common_1.applyDecorators)((0, common_1.SetMetadata)(entity_constant_1.ENTITY_SERVICE_DECORATOR_KEY, serviceClass), (0, common_1.SetMetadata)(entity_constant_1.ENTITY_NAME_DECORATOR_KEY, entityName), (0, common_1.UseGuards)(entity_put_to_request_by_slug_guard_1.EntityPutToRequestBySlugGuard), (0, common_1.UseGuards)(entity_not_found_guard_1.EntityNotFoundGuard));
|
|
18
|
+
}
|
|
14
19
|
function EntityGetByIdAndUserGuard(serviceClass, entityName) {
|
|
15
20
|
return (0, common_1.applyDecorators)((0, common_1.SetMetadata)(entity_constant_1.ENTITY_SERVICE_DECORATOR_KEY, serviceClass), (0, common_1.SetMetadata)(entity_constant_1.ENTITY_NAME_DECORATOR_KEY, entityName), (0, common_1.UseGuards)(guards_1.EntityPutToRequestByIdAndUserGuard), (0, common_1.UseGuards)(entity_not_found_guard_1.EntityNotFoundGuard));
|
|
16
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.get.decorator.js","sourceRoot":"","sources":["../../../../../packages/request/src/decorators/entity.get.decorator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"entity.get.decorator.js","sourceRoot":"","sources":["../../../../../packages/request/src/decorators/entity.get.decorator.ts"],"names":[],"mappings":";;;AAkBA,gDAUC;AAED,oDAUC;AAED,8DAUC;AApDD,2CAKwB;AAGxB,kEAGsC;AACtC,6EAAuE;AACvE,mGAA0F;AAC1F,sCAA+D;AAE/D,uGAA8F;AAE9F,SAAgB,kBAAkB,CAChC,YAAiC,EACjC,UAAkB;IAElB,OAAO,IAAA,wBAAe,EACpB,IAAA,oBAAW,EAAC,8CAA4B,EAAE,YAAY,CAAC,EACvD,IAAA,oBAAW,EAAC,2CAAyB,EAAE,UAAU,CAAC,EAClD,IAAA,kBAAS,EAAC,+DAA2B,CAAC,EACtC,IAAA,kBAAS,EAAC,4CAAmB,CAAC,CAC/B,CAAC;AACJ,CAAC;AAED,SAAgB,oBAAoB,CAClC,YAAiC,EACjC,UAAkB;IAElB,OAAO,IAAA,wBAAe,EACpB,IAAA,oBAAW,EAAC,8CAA4B,EAAE,YAAY,CAAC,EACvD,IAAA,oBAAW,EAAC,2CAAyB,EAAE,UAAU,CAAC,EAClD,IAAA,kBAAS,EAAC,mEAA6B,CAAC,EACxC,IAAA,kBAAS,EAAC,4CAAmB,CAAC,CAC/B,CAAC;AACJ,CAAC;AAED,SAAgB,yBAAyB,CACvC,YAAiC,EACjC,UAAkB;IAElB,OAAO,IAAA,wBAAe,EACpB,IAAA,oBAAW,EAAC,8CAA4B,EAAE,YAAY,CAAC,EACvD,IAAA,oBAAW,EAAC,2CAAyB,EAAE,UAAU,CAAC,EAClD,IAAA,kBAAS,EAAC,2CAAkC,CAAC,EAC7C,IAAA,kBAAS,EAAC,4CAAmB,CAAC,CAC/B,CAAC;AACJ,CAAC;AAEY,QAAA,SAAS,GAAG,IAAA,6BAAoB,EAC3C,CACE,EACE,MAAM,EACN,KAAK,GAIN,EACD,GAAqB,EACX,EAAE;IACZ,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAChD,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;IAC7C,OAAO,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;AAC1D,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { ModuleRef, Reflector } from '@nestjs/core';
|
|
3
|
+
export declare class EntityPutToRequestBySlugGuard<T> implements CanActivate {
|
|
4
|
+
private readonly reflector;
|
|
5
|
+
private readonly moduleRef;
|
|
6
|
+
constructor(reflector: Reflector, moduleRef: ModuleRef);
|
|
7
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityPutToRequestBySlugGuard = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const core_1 = require("@nestjs/core");
|
|
7
|
+
const entity_constant_1 = require("../constants/entity.constant");
|
|
8
|
+
let EntityPutToRequestBySlugGuard = class EntityPutToRequestBySlugGuard {
|
|
9
|
+
constructor(reflector, moduleRef) {
|
|
10
|
+
this.reflector = reflector;
|
|
11
|
+
this.moduleRef = moduleRef;
|
|
12
|
+
}
|
|
13
|
+
async canActivate(context) {
|
|
14
|
+
const request = context.switchToHttp().getRequest();
|
|
15
|
+
const entityServiceClass = this.reflector.get(entity_constant_1.ENTITY_SERVICE_DECORATOR_KEY, context.getHandler());
|
|
16
|
+
const entityName = this.reflector.get(entity_constant_1.ENTITY_NAME_DECORATOR_KEY, context.getHandler());
|
|
17
|
+
const entityService = await this.moduleRef.resolve(entityServiceClass, undefined, {
|
|
18
|
+
strict: false,
|
|
19
|
+
});
|
|
20
|
+
if (!entityService) {
|
|
21
|
+
throw new Error(`Service not found for entity: ${entityName}`);
|
|
22
|
+
}
|
|
23
|
+
const slug = request.params[entityName];
|
|
24
|
+
const entity = await entityService.findOne({
|
|
25
|
+
$expr: {
|
|
26
|
+
$in: [
|
|
27
|
+
slug,
|
|
28
|
+
{
|
|
29
|
+
$map: {
|
|
30
|
+
input: { $objectToArray: '$slug' },
|
|
31
|
+
as: 'item',
|
|
32
|
+
in: '$$item.v',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
}, {
|
|
38
|
+
join: true,
|
|
39
|
+
});
|
|
40
|
+
// Assign the found entity to the request under the entity name (e.g. __article, __user)
|
|
41
|
+
request[`__${entityName}`] = entity;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.EntityPutToRequestBySlugGuard = EntityPutToRequestBySlugGuard;
|
|
46
|
+
exports.EntityPutToRequestBySlugGuard = EntityPutToRequestBySlugGuard = tslib_1.__decorate([
|
|
47
|
+
(0, common_1.Injectable)(),
|
|
48
|
+
tslib_1.__metadata("design:paramtypes", [core_1.Reflector,
|
|
49
|
+
core_1.ModuleRef])
|
|
50
|
+
], EntityPutToRequestBySlugGuard);
|
|
51
|
+
//# sourceMappingURL=entity.put-to-request-by-slug.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.put-to-request-by-slug.guard.js","sourceRoot":"","sources":["../../../../../packages/request/src/guards/entity.put-to-request-by-slug.guard.ts"],"names":[],"mappings":";;;;AAAA,2CAA2E;AAE3E,uCAAoD;AAEpD,kEAGsC;AAG/B,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IACxC,YACmB,SAAoB,EACpB,SAAoB;QADpB,cAAS,GAAT,SAAS,CAAW;QACpB,cAAS,GAAT,SAAS,CAAW;IACpC,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAEpD,MAAM,kBAAkB,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAC3C,8CAA4B,EAC5B,OAAO,CAAC,UAAU,EAAE,CACrB,CAAC;QACF,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CACnC,2CAAyB,EACzB,OAAO,CAAC,UAAU,EAAE,CACrB,CAAC;QAEF,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAChD,kBAAkB,EAClB,SAAS,EACT;YACE,MAAM,EAAE,KAAK;SACd,CACF,CAAC;QAEF,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,iCAAiC,UAAU,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAExC,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CACxC;YACE,KAAK,EAAE;gBACL,GAAG,EAAE;oBACH,IAAI;oBACJ;wBACE,IAAI,EAAE;4BACJ,KAAK,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE;4BAClC,EAAE,EAAE,MAAM;4BACV,EAAE,EAAE,UAAU;yBACf;qBACF;iBACF;aACF;SACF,EACD;YACE,IAAI,EAAE,IAAI;SACX,CACF,CAAC;QAEF,wFAAwF;QACxF,OAAO,CAAC,KAAK,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC;QAEpC,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzDY,sEAA6B;wCAA7B,6BAA6B;IADzC,IAAA,mBAAU,GAAE;6CAGmB,gBAAS;QACT,gBAAS;GAH5B,6BAA6B,CAyDzC"}
|