nestjs

Testing Passport in NestJS

╄→尐↘猪︶ㄣ 提交于 2019-12-12 01:03:27
问题 I'm trying to do a e2e testing to a route that has an AuthGuard from nestjs passport module and I don't really know how to approach it. When I run the tests it says: [ExceptionHandler] Unknown authentication strategy "bearer" I haven't mock it yet so I suppose it's because of that but I don't know how to do it. This is what I have so far: player.e2e-spec.ts import { Test } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; import * as request from 'supertest'; import {

Overloaded routes in NestJS controller?

丶灬走出姿态 提交于 2019-12-11 19:32:26
问题 Is there a nice-looking way to create overloaded routes in NestJS application? I have some thoughts, but maybe I'm inventing a wheel. I couldn't find any ready approach though... What I'm talking about is something like this (lets take https://github.com/nestjs/nest/blob/master/sample/01-cats-app/src/cats/cats.controller.ts as start point): @Get() async findAll(): Promise<Cat[]> { return this.catsService.findAll(); } @Get() @Roles('admin') async findAllAdmin(): Promise<Cat[]> { return this

Nest JS GraphQL “Cannot return null for non-nullable” [duplicate]

我只是一个虾纸丫 提交于 2019-12-11 19:10:01
问题 This question already has an answer here : Why does a GraphQL query return null? (1 answer) Closed 2 months ago . I tried to resolve one error in my study code, but failed. Then I just try to launch this code... https://github.com/nestjs/nest/tree/master/sample/23-type-graphql and the same situation... Error looks like { "errors": [ { "message": "Cannot return null for non-nullable field Recipe.id.", "locations": [ { "line": 3, "column": 5 } ], "path": [ "recipe", "id" ], "extensions": {

Error implementing Querying after populate in Mongoose [duplicate]

[亡魂溺海] 提交于 2019-12-11 18:48:27
问题 This question already has answers here : Querying after populate in Mongoose (6 answers) How can i find documents by populated field? [duplicate] Closed 2 months ago . Hello recently i asked a question: How can i find documents by populated field? What is a which turned out to be a duplicate: Querying after populate in Mongoose Im got already PolicySchema.statics.lookup = async function({path, query}) { const rel = mongoose.model(this.schema.path(path).options.ref); const pipeline = [ { '

Why Nest.js throw a error when run main.js?

馋奶兔 提交于 2019-12-11 17:12:16
问题 I am using Nest.js to develop a web backend. When I use npm run build , the cmd shows success. But when I use node dist/main.js , the cmd shows error. But I'm sure this file exist and in develop mode (npm run start) , everything's ok. This is github address. https://github.com/Eve-1995/Oreo/tree/master/oreo-back-end What should I do next? 回答1: entities: [__dirname + '/../**/**/!(*.d).entity.{ts,js}'], is doing the trick for me both in production and dev envs. 回答2: I think the reason is in

Unable to create a new project with the Nest CLI

不羁的心 提交于 2019-12-11 16:19:00
问题 I am following this tutorial to create a nest project. I have installed Nest CLI using this command: npm i -g @nestjs/cli I have checked the list of packages installed locally using the following command and found that it was successfully installed: npm list -g --depth 0 but when I tried to create a new project using following command it gave me an error: nest new project-name Error: nest : The term 'nest' is not recognized as the name of a cmdlet, function, script file, or operable program.

NestJS Cannot resolve dependencies of the UsersModule

两盒软妹~` 提交于 2019-12-11 15:57:34
问题 NestJS Cannot resolve dependencies of the UsersModule. Error: Error: Nest can't resolve dependencies of the UsersModule (?). Please verify whether [0] argument is available in the current context. app.module.ts: @Module({ imports: [ ConfigModule, DatabaseModule, GraphQLModule, UsersModule, ], providers: [ ErrorService, ], exports: [ DatabaseModule, ErrorService, ], }) export class AppModule implements NestModule {} users.module.ts: @Module({ imports: [ DatabaseModule, ErrorService, ],

NestJS return a fie from GridFS

断了今生、忘了曾经 提交于 2019-12-11 15:19:24
问题 I am trying to return a file from GridFS using my Nest controller. As far as I can tell nest is not respecting my custom content-type header which i set to application/zip , as I am receiving a text content type upon return (see screenshot). response data image, wrong content-type header My nest controller looks like this @Get(':owner/:name/v/:version/download') @Header('Content-Type', 'application/zip') async downloadByVersion(@Param('owner') owner: string, @Param('name') name: string,

NestJS can't resolve dependencies of the JWT_MODULE_OPTIONS

徘徊边缘 提交于 2019-12-11 14:31:28
问题 I'm failed to compile with this error: Nest can't resolve dependencies of the JWT_MODULE_OPTIONS (?). Please make sure that the argument at index [0] is available in the JwtModule context. +52ms I saw similar dependencies problems with modules & services, but they didn't work for me. Using JwtModule in my auth.module.ts : import { JwtModule } from '@nestjs/jwt'; @Module({ imports: [ TypeOrmModule.forFeature([User, Role]), ConfigModule, PassportModule.register({ defaultStrategy: 'jwt' }),

How to test Nestjs interceptor?

懵懂的女人 提交于 2019-12-11 06:57:33
问题 I can't find any explanation on how to test interceptors in NestJS This simple example intercepts a POST query to add an attribute to an Example Model provided in the body. @Injectable() export class SubscriberInterceptor implements NestInterceptor { async intercept( context: ExecutionContext, next: CallHandler, ): Promise<Observable<ExampleModel>> { let body: ExampleModel = context.switchToHttp().getRequest().body; body = { ...body, addedAttribute: 'example', }; context.switchToHttp()