nestjs

How to manually test input validation with NestJS and class-validator

一曲冷凌霜 提交于 2020-05-16 08:52:32
问题 TLNR: I was trying to test DTO validation in the controller spec instead of in e2e specs, which are precisely crafted for that. McDoniel's answer pointed me to the right direction. I develop a NestJS entrypoint, looking like that: @Post() async doStuff(@Body() dto: MyDto): Promise<string> { // some code... } I use class-validator so that when my API receives a request, the payload is parsed and turned into a MyDto object, and validations present as annotations in MyDto class are performed.

NestJS Authentification with JWT Passport not working

六月ゝ 毕业季﹏ 提交于 2020-05-16 03:15:33
问题 I am trying to set up a very simple login system using jwt-passport with nestjs. I followed this tutorial: https://docs.nestjs.com/techniques/authentication but I just can't get it to work. I am really new to this stuff and would appreciate if anyone can show me the way. The way I send the login to the server: this.clientAuthService.login(this.userName, this.password).then(response => { this.clientAuthService.setToken(response.access_token); this.router.navigate(['/backend']); }); My

NestJS Authentification with JWT Passport not working

余生长醉 提交于 2020-05-16 03:14:10
问题 I am trying to set up a very simple login system using jwt-passport with nestjs. I followed this tutorial: https://docs.nestjs.com/techniques/authentication but I just can't get it to work. I am really new to this stuff and would appreciate if anyone can show me the way. The way I send the login to the server: this.clientAuthService.login(this.userName, this.password).then(response => { this.clientAuthService.setToken(response.access_token); this.router.navigate(['/backend']); }); My

Nest can't resolve dependencies of the ItemsService (?). Please make sure that the argument at index [0] is available in the AppModule context

纵然是瞬间 提交于 2020-05-15 11:11:13
问题 I follwed Nest JS Crash tutorial, Youtube Link, I followed this, but when i import interface in service it shows error Nest can't resolve dependencies of the ItemsService (?). Please make sure that the argument at index [0] is available in the AppModule context. I i cloned repository given in tutorial, it is working fine, but when i copy src folder of that repository to my project it then throws error. here is my Service file import { Injectable } from '@nestjs/common'; import { Item } from '

Nest can't resolve dependencies of the ItemsService (?). Please make sure that the argument at index [0] is available in the AppModule context

岁酱吖の 提交于 2020-05-15 11:04:46
问题 I follwed Nest JS Crash tutorial, Youtube Link, I followed this, but when i import interface in service it shows error Nest can't resolve dependencies of the ItemsService (?). Please make sure that the argument at index [0] is available in the AppModule context. I i cloned repository given in tutorial, it is working fine, but when i copy src folder of that repository to my project it then throws error. here is my Service file import { Injectable } from '@nestjs/common'; import { Item } from '

Nestjs: Image uploaded even if body validation fails

北城以北 提交于 2020-05-13 09:19:09
问题 First of all, I apologize for my weak English. I have a method that accepts PUT request, and it receives a file and BlogModel. When I submit the form from frontend and the BlogModel's validation is failed the file is still uploaded. main.ts import { NestFactory } from '@nestjs/core'; import { AppModule } from './core/app.module'; import { ValidationPipe } from '@nestjs/common'; import { join } from 'path'; import { NestExpressApplication } from '@nestjs/platform-express'; async function

Is there an elegant way using TypeORM to find one record in an array of OneToMany relation and assign it to another field in the entitiy?

馋奶兔 提交于 2020-05-13 06:12:11
问题 I'm looking for a way to implement a function, using NestJS and TypeORM, that will find in OneToMany array a specific element and assign that value to another field in the object. And most important: implemented in a single place in the code. For example: The Entity profile have an array of photos , one of the photos is the profile picture. I would like to find that photo in the array and assign it to profilePicture if exist, on every select query. is there a way in typeORM to implement that

Use global nest module in decorator

て烟熏妆下的殇ゞ 提交于 2020-05-09 11:02:51
问题 I have a global logger module in nest, that logs to a cloud logging service. I am trying to create a class method decorator that adds logging functionality. But I am struggling how to inject the service of a global nest module inside a decorator, since all dependency injection mechanisms I found in the docs depend are class or class property based injection. export function logDecorator() { // I would like to inject a LoggerService that is a provider of a global logger module let logger = ???

Angular 9 http call with nestjs backend

蓝咒 提交于 2020-04-18 04:04:08
问题 I have an Angular (9) frontend with nestjs backend rest api (in nodejs) The endpoint I call in the backend does some fairly complex operations and it takes about 2 min to respond. In the frontend I use subscribe to subscribe to the response like this: this.metaService.subscribe( result => { //Handle result }, error => { this.subscription.unsubscribe(); console.error('Error: ' + error); }, () => { this.subscription.unsubscribe(); console.error('Completed'); }); The problem is that in the

Angular 9 http call with nestjs backend

♀尐吖头ヾ 提交于 2020-04-18 04:00:30
问题 I have an Angular (9) frontend with nestjs backend rest api (in nodejs) The endpoint I call in the backend does some fairly complex operations and it takes about 2 min to respond. In the frontend I use subscribe to subscribe to the response like this: this.metaService.subscribe( result => { //Handle result }, error => { this.subscription.unsubscribe(); console.error('Error: ' + error); }, () => { this.subscription.unsubscribe(); console.error('Completed'); }); The problem is that in the