nestjs

NestJS - Injected service is undefined in the constructor

≡放荡痞女 提交于 2019-12-11 06:05:43
问题 As per the documentation, I inject a service in a controller's constructor, but it turns out as undefined . processScraped.controller.ts import { Controller, Post, Body } from '@nestjs/common'; import { ProcessScrapedService } from "./processScraped.service" console.log(`\nController - ProcessScrapedService = `, ProcessScrapedService) // logs : class ProcessScrapedService { ...... @Controller('processScraped') export class ProcessScrapedController { constructor(private readonly pss:

Observables in nestjs - Reading a file asynchronously

孤街浪徒 提交于 2019-12-11 04:40:51
问题 I am trying a use case of reading a json file asynchronously and sending it out as a response (as a rxjs observable data). Here is the service that I use import { logger } from './../../shared/utils/logger'; import { Injectable } from '@nestjs/common'; import * as fs from 'fs'; import * as path from 'path'; import { BehaviorSubject, Observable, pipe, of, from, throwError, merge} from 'rxjs'; import { map, filter, scan, take, debounce, switchMap, retry, catchError, mergeMap, delay, zip, tap,

Nest js cannot resolve dependencies. in Auth service

眉间皱痕 提交于 2019-12-11 04:25:36
问题 Nest can't resolve dependencies of the AuthService (?). Please verify whether [0] argument is available in the current context. Please find my project repository Nest-auth-test Error: Nest can't resolve dependencies of the AuthService (?). Please verify whether [0] argument is available in the current context. at Injector.lookupComponentInExports (/home/arpit/Documents/aquaapp/node_modules/@nestjs/core/injector/injector.js:129:19) at <anonymous> at process._tickCallback (internal/process/next

NestJS - Combine HTTP with RabbitMQ in microservices

て烟熏妆下的殇ゞ 提交于 2019-12-10 23:54:49
问题 I have a few microservices, which are exposed through an API-Gateway. The gateway takes care of handling authentication and routing into the system. The services behind the gateway are mostly simple CRUD-Services. Each service exposes its own API and they communicate synchronously via HTTP. All of these services, including the API-Gateway, are "default" NestJS applications. Let's stick with the Cats example. Whenever the Cat-Service updates or creates a new Cat , I want an CatCreatedEvent or

Running nest.js from VS Code

邮差的信 提交于 2019-12-10 22:53:39
问题 So, I'm playing around with this new framework http://nestjs.com/ who seems pretty awesome since it allows the usage of Typescript on Node, very likely to angular. Using the starter https://github.com/kamilmysliwiec/nest-typescript-starter, I can run it with npm run start without any problem, but since there is a .vscode on the project, I assumed I could use VS Code to run and gain some debug abilities. The problem is that when I run directly from VS Code, without changing anything in the

How to change a Database connection dynamically with Request Scope Providers in Nestjs?

你离开我真会死。 提交于 2019-12-10 20:51:31
问题 Working on a project with Nestjs 6.x, Mongoose, Mongo , etc... Regarding to the Back End, in my use case, I must change the connection of one of my databases depending of some conditions/parameters coming from some requests . Basically, I have this mongoose.createConnection('mongodb://127.0.0.1/whatever-a', { useNewUrlParser: true }) and I want to change to , for example mongoose.createConnection('mongodb://127.0.0.1/whatever-b', { useNewUrlParser: true }) Therefore, I have in Nestjs the

How to exclude entity field from returned by controller JSON. NestJS + Typeorm

此生再无相见时 提交于 2019-12-10 15:15:54
问题 I want to exclude password field from returned JSON. I am using NestJS and Typeorm. The solution provided on this question doesn't work for me or in NestJS. I can post my code if needed. Any other ideas or solutions? Thanks. 回答1: I'd suggest creating an interceptor that takes advantage of the class-transformer library: @Injectable() export class TransformInterceptor implements NestInterceptor { intercept( context: ExecutionContext, call$: Observable<any>, ): Observable<any> { return call$

Problem with multiple graphql resolver implementations in nestjs

二次信任 提交于 2019-12-09 03:52:21
问题 I just started learning NestJS and GraphQL. I started with a single resolver class UserResolver defined in UserModule . This class provides methods to read a list of users or a specific user. Methods are decorated with @Query() , a user.graphql file is provided, GraphQL is initialized in AppModule , all as described in the docs. All works well, I can get a list of users or specific user through Insomnia Tool or through Playground. I am happy! Now I have created a second module, RoleModule . I

How to handle mongoose error with nestjs

别来无恙 提交于 2019-12-08 04:57:13
问题 I followed the example from https://docs.nestjs.com/techniques/mongodb The issue is when there is a mongoose validation error (e.g i have a schema with a required field and it isn't provided): From games.service.ts: async create(createGameDto: CreateGameDto): Promise<IGame> { const createdGame = new this.gameModel(createGameDto); return await createdGame.save(); } The save() function returns a Promise. Now i have this in the game.controller.ts @Post() async create(@Body() createGameDto:

How can i setup multitenant in NESTJS

谁说胖子不能爱 提交于 2019-12-08 02:01:17
问题 I want to connect to any database based on the subdomain (multi-tenant), but i'm not sure how can i do it. My code runs when the app is started, but i don't know how to change the Datasource based on subdomain. PS: I created middleware on each request, but I don't know how to change the source. I have the following code for my DB: import { connect, createConnection } from 'mongoose'; import { SERVER_CONFIG, DB_CONNECTION_TOKEN } from '../server.constants'; const opts = { useCreateIndex: true,