nestjs

Auto Increment Sequence in NestJs/Mongoose

陌路散爱 提交于 2021-01-27 14:40:47
问题 I'm migrating a NodeJs project to NestJs, this project uses MongoDB as back-end database and Mongoose as ODM. I was using the mongoose-sequence plugin to handle autoincrement sequences, however I'm facing troubles requiring the library under NestJs. The mongoose-sequence documentation explains how to import the library using CommonJS syntax as follows: const mongoose = require('mongoose') const AutoIncrementFactory = require('mongoose-sequence'); const connection = await mongoose

NestJS Global Modules in tests

断了今生、忘了曾经 提交于 2021-01-27 06:48:21
问题 Is there a way to automatically provide all @Global modules into a TestModule ? (i.e without having to import them, the same way the main application works) So far, I had to make sure to insert any global modules into the import list of my call: await Test.createTestingModule({ imports: [ GlobalModule1, GlobalModule2 回答1: Global modules always have to be imported once for their providers to be available globally. This holds true for tests and the main application, see the docs. Global modules

NestJS Global Modules in tests

孤街醉人 提交于 2021-01-27 06:45:48
问题 Is there a way to automatically provide all @Global modules into a TestModule ? (i.e without having to import them, the same way the main application works) So far, I had to make sure to insert any global modules into the import list of my call: await Test.createTestingModule({ imports: [ GlobalModule1, GlobalModule2 回答1: Global modules always have to be imported once for their providers to be available globally. This holds true for tests and the main application, see the docs. Global modules

How can I get all the routes (from all the modules and controllers available on each module) in Nestjs?

自作多情 提交于 2021-01-22 10:35:12
问题 Using Nestjs I'd like to get a list of all the available routes (controller methods) with http verbs, like this: API: POST /api/v1/user GET /api/v1/user PUT /api/v1/user It seems that access to express router is required, but I haven found a way to do this in Nestjs. For express there are some libraries like "express-list-routes" or "express-list-endpoints". Thanks in advance! 回答1: I just found that Nestjs app has a "getHttpServer()" method, with this I was able to access the "router stack",

How can I get all the routes (from all the modules and controllers available on each module) in Nestjs?

江枫思渺然 提交于 2021-01-22 10:32:24
问题 Using Nestjs I'd like to get a list of all the available routes (controller methods) with http verbs, like this: API: POST /api/v1/user GET /api/v1/user PUT /api/v1/user It seems that access to express router is required, but I haven found a way to do this in Nestjs. For express there are some libraries like "express-list-routes" or "express-list-endpoints". Thanks in advance! 回答1: I just found that Nestjs app has a "getHttpServer()" method, with this I was able to access the "router stack",

Nest JS - Issue writing Jest Test Case for a function returning Observable Axios Response

十年热恋 提交于 2021-01-05 06:19:46
问题 I am fairly new to NestJS + Typescript + RxJs tech stack. I am trying to write a unit test case using Jest for one of my functions but not sure if doing it correctly. component.service.ts public fetchComponents(queryParams) { const url = this.prepareUrl(queryParams); const data$ = this.httpService.get(url); return data$ .pipe(map(({ data }) => data)); } component.sevice.spec.ts Test case works and passes describe('fetchComponents', () => { const query = { limit: 10, offset: 0 }; const result:

Nest JS - Issue writing Jest Test Case for a function returning Observable Axios Response

只愿长相守 提交于 2021-01-05 06:18:04
问题 I am fairly new to NestJS + Typescript + RxJs tech stack. I am trying to write a unit test case using Jest for one of my functions but not sure if doing it correctly. component.service.ts public fetchComponents(queryParams) { const url = this.prepareUrl(queryParams); const data$ = this.httpService.get(url); return data$ .pipe(map(({ data }) => data)); } component.sevice.spec.ts Test case works and passes describe('fetchComponents', () => { const query = { limit: 10, offset: 0 }; const result:

What is the purpose of a Data Transfer Object in NestJS?

久未见 提交于 2021-01-02 18:06:12
问题 Im struggling with a problem. Im following the documentation of NestJS. The back-end framework for NodeJS. The documentation mentions a DTO (Data Transfer Object). I created a DTO for creating a user: export class CreateUserDto { readonly email: string; readonly password: string; } In combination with this: @Post('create') createUser(@Body() userData: CreateUserDto): User { return this.usersService.createUser(userData); } For some reason, I am able to make a post request to this route with

What is the purpose of a Data Transfer Object in NestJS?

让人想犯罪 __ 提交于 2021-01-02 18:05:14
问题 Im struggling with a problem. Im following the documentation of NestJS. The back-end framework for NodeJS. The documentation mentions a DTO (Data Transfer Object). I created a DTO for creating a user: export class CreateUserDto { readonly email: string; readonly password: string; } In combination with this: @Post('create') createUser(@Body() userData: CreateUserDto): User { return this.usersService.createUser(userData); } For some reason, I am able to make a post request to this route with

Angular/Rxjs pipe async does not work with ssr?

三世轮回 提交于 2020-12-30 17:35:52
问题 I have an issue with the async pipe running on SSR. there are no errors, only an infinite loop (it seems that the server is waiting for the observable to be resolved). I am using: @nestjs/ng-universal Angular 9 Firebase Rxjs A simple case like this works: <p>{{ observable | async }}</p> But using structural directives do not work: ngIf <p *ngIf="(observable$ | async) > 5">{{ observable$ | async }}</p> Ngfor <p *ngFor="let item of items | async">{{ item }}</p> Using async is a good practice