nestjs

NestJS + TypeORM: Use two or more databases?

两盒软妹~` 提交于 2019-12-22 04:56:21
问题 I'm trying since 2 days to solve this, perhaps I'm simply missing the point here. My goal was to write a NestJS app (with TypeORM included) which serves a RestAPI for 2 or 3 of my little projects, instead of writing a NestJS-App for every single one of them. So far so good, the app is ready, works well with the single projects (which resides in subfolders with their entities, controllers, services, modules), but I can't get it to run with all of them. The point seems to be the configuration,

NestJS: Adding verification options to AuthGuard with JWT

ぐ巨炮叔叔 提交于 2019-12-21 05:41:31
问题 I am trying to make use of the AuthGuard decorator, and the passport JWT strategy, following the documentation. Everything in the documentation works great. But I now want to protect a route with a scope contained in the JWT. So here is a basic jwt payload generated by my application: { "user": { "id": "20189c4f-1183-4216-8b48-333ddb825de8", "username": "user.test@gmail.com" }, "scope": [ "manage_server" ], "iat": 1534766258, "exp": 1534771258, "iss": "15f2463d-8810-44f9-a908-801872ded159",

How to apply both ValidationPipe() and ParseIntPipe() to params?

送分小仙女□ 提交于 2019-12-20 04:28:10
问题 I'm trying to apply both the ValidationPipe() and ParseIntPipe() to the params in my NestJs controller. The intention is to apply ParseIntPipe() only on @Param('id') but ValidationPipe() for all params in CreateDataParams and Body DTO. However, I can't seem to apply both pipes the way I wanted. Here's what I have: @Post(':id') @UsePipes(new ValidationPipe()) async create( @Param('id', new ParseIntPipe()) id: number, //this doesn't work @Param() params: CreateDataParams, @Body() createDto:

Optional authentication in Nest.js with @nestjs/passport

被刻印的时光 ゝ 提交于 2019-12-18 05:04:07
问题 I have a route that needs to be used by authenticated and unauthenticated users. I use @UseGuards(AuthGuard('jwt')) to enable authentication but it prevents any unauthenticated user to access the route (normal). How can I allow unauthenticated users to also access the route ? It seems that there's no options that I can pass to AuthGuard in order to retrieve them in my passport strategy. 回答1: You can just create your own AuthGuard for example by extending the existing one: export class

Inject TypeORM repository into NestJS service for mock data testing

冷暖自知 提交于 2019-12-17 07:39:11
问题 There's a longish discussion about how to do this in this issue. I've experimented with a number of the proposed solutions but I'm not having much luck. Could anyone provide a concrete example of how to test a service with an injected repository and mock data? 回答1: Let's assume we have a very simple service that finds a user entity by id: export class UserService { constructor(@InjectRepository(UserEntity) private userRepository: Repository<UserEntity>) { } async findUser(userId: string):

How to integrate Neo4j database, NestJS framework and GraphQL?

匆匆过客 提交于 2019-12-13 07:53:58
问题 I'm trying to integrate my REST API (NestJS) with new Neo4j database with GraphQL queries. Anybody succeed? Thanks in advance EDIT 1: (I added my code) import { Resolver } from "@nestjs/graphql"; import { Query, forwardRef, Inject, Logger } from "@nestjs/common"; import { Neo4jService } from "src/shared/neo4j/neoj4.service"; import { GraphModelService } from "./models/model.service"; import { Movie } from "src/graphql.schema"; @Resolver('Movie') export class GraphService { constructor(private

NestJS - A method handler is interfering into another handler with same name in another controller

感情迁移 提交于 2019-12-13 04:19:19
问题 I had two controllers into two differnt folders into two different modules, Both of them has a method with same create name. /admin/entity.controller.ts @Controller("admin") export class EntityController{ @Post() public async create(@Request() request: any): Promise<List> { console.log("request", request) // Logs the Body {"name": "test"} instead of request. } } /user/entity.ontroller.ts @Controller("user") export class EntityController{ @Post() public async create(@Body() entity: Entity) {

Serving multiple static files in nestjs for different locations and prefixes?

岁酱吖の 提交于 2019-12-13 03:51:23
问题 I am currently serving static files for some developer static docs I have created, I am currently using app.useStaticAssets(docsLocation, { prefix: "/docs/" }) My question is that I have another directory that I would like to serve, it also has static content, is it possible to serve from different locations and using a different prefix for each location? Any ideas, this is not covered in the documentation. Thanks 回答1: You can just register static assets multiple times: app.useStaticAssets

Nest.js deployment to now.sh

馋奶兔 提交于 2019-12-12 12:07:08
问题 I am currently trying to deploy my demo application to zeit now.sh. In documentation I have found how I can deploy Node.js and Express.js application. But example that I am referring expects as parameter js file with server initialization, and by default Nest.js project has as entry point ts file. Whole application is written in typescript. If I try to use main.ts as entry point, I am getting this error: 11/28 08:05 PM (1m) { Error: Cannot find module './app.module' at Function.Module.

Decorator to return a 404 in a Nest controller

萝らか妹 提交于 2019-12-12 11:11:52
问题 I'm working on a backend using NestJS, (which is amazing btw). I have a 'standard get a single instance of an entity situation' similar to this example below. @Controller('user') export class UserController { constructor(private readonly userService: UserService) {} .. .. .. @Get(':id') async findOneById(@Param() params): Promise<User> { return userService.findOneById(params.id); } This is incredibly simple and works - however, if the user does not exist, the service returns undefined and the