nestjs

Inject class implementation into abstract controller implementation based on an interface via NestJS

筅森魡賤 提交于 2021-01-29 07:36:23
问题 I'm currently trying to work out a setup using NestJS injection, but I'm running into errors when trying to run the server. The problem that I'm running into has to do with me trying to inject a class into a controller which extends an abstract class and I'm trying to set a property of the abstract class in the constructor. Controller.ts @Controller() export class exampleController extends AbstractController { constructor(exampleClass: exampleInterface) { super(exampleClass); } @Get()

TypeORM + TypeError: Cannot set property EntityManager of #<Object> which has only a getter

点点圈 提交于 2021-01-28 13:50:22
问题 I have a Nest application which is not starting due to the following exception. I am not sure what is the cause of the problem. I created this GitHub repository to replicate the issue. The running instructions are detailed in the README. The error: TypeError: Cannot set property EntityManager of #<Object> which has only a getter at Object.<anonymous> (/Users/saulo/NodeProjects/typeorm-jest-issues/node_modules/typeorm/index.js:120:23) at Module._compile (internal/modules/cjs/loader.js:1147:30)

TypeORM + TypeError: Cannot set property EntityManager of #<Object> which has only a getter

柔情痞子 提交于 2021-01-28 13:34:44
问题 I have a Nest application which is not starting due to the following exception. I am not sure what is the cause of the problem. I created this GitHub repository to replicate the issue. The running instructions are detailed in the README. The error: TypeError: Cannot set property EntityManager of #<Object> which has only a getter at Object.<anonymous> (/Users/saulo/NodeProjects/typeorm-jest-issues/node_modules/typeorm/index.js:120:23) at Module._compile (internal/modules/cjs/loader.js:1147:30)

How to use Jest to mock and spy a `mongoose.connect` in a provider of NestJS

試著忘記壹切 提交于 2021-01-28 12:03:06
问题 I defined a custom database-specific Module to connect a MongoDB via Mongoose APIs. The complete code is here. { provide: DATABASE_CONNECTION, useFactory: (dbConfig: ConfigType<typeof mongodbConfig>): Connection => createConnection(dbConfig.uri, { useNewUrlParser: true, useUnifiedTopology: true, //see: https://mongoosejs.com/docs/deprecations.html#findandmodify useFindAndModify: false }), inject: [mongodbConfig.KEY], }, When writing tests for this provider, I want to confirm the database

NestJS custom decorator returns undefined

≡放荡痞女 提交于 2021-01-28 06:41:40
问题 Good morning, I'm trying to create a custom decorator: user.decorator.ts import { createParamDecorator, ExecutionContext } from '@nestjs/common'; export const User = createParamDecorator( (data: string, ctx: ExecutionContext) => { const request = ctx.switchToHttp().getRequest(); const user = request.user; return data ? user && user[data] : user; }, ); user.entity.ts import { Entity, PrimaryGeneratedColumn, Column, BeforeInsert } from "typeorm"; import * as bcrypt from 'bcryptjs'; import * as

Fastify & NestJS - How to set response headers in interceptor

淺唱寂寞╮ 提交于 2021-01-28 05:35:02
问题 I'm trying to set the response headers in my interceptor, and have had no luck with any method I've found yet. I've tried: const request = context.switchToHttp().getRequest(); const response = context.switchToHttp().getResponse(); <snippet of code from below> return next.handle(); request.res.headers['my-header'] = 'xyz' response.header('my-header', 'xyz') response.headers['my-header'] = 'xyz' response.header['my-header'] = 'xyz' with no luck. The first option says that res is undefined, the

Use websockets in NestJs and ReactJS

若如初见. 提交于 2021-01-28 05:07:44
问题 I want to use websockets using NestJs. According to the documentation i created: // events.gateway.ts import { MessageBody, OnGatewayInit, SubscribeMessage, WebSocketGateway } from "@nestjs/websockets"; @WebSocketGateway(81, { transports: ['websocket'] }) export class EventsGateway implements OnGatewayInit { @SubscribeMessage('events') handleEvent(@MessageBody() data: string): string { console.log(data, 'socket') return data; } afterInit(server: any): any { console.log('init') } } After that

NestJS REST API times out for long running request

爷,独闯天下 提交于 2021-01-28 02:12:45
问题 After lengthy investigations the problems seems to be that the long running request times out and the endpoint is called again in NodeJS. There is no new network request from browser. I made a few tests and after 2 mins the endpoint is invoked again. I read that the default timeout for the http requests in NodeJS in 2mins. https://nodejs.org/docs/latest-v12.x/api/http.html#http_server_timeout I am using NestJS (with express), does anyone know how to increase this timeout value using NestJS

Migrating Express application to NestJS

故事扮演 提交于 2021-01-27 20:30:13
问题 I have an existing express application, and it is large enough. I want to migrate it to NestJS application, but do it step by step. So I have created Nest app with an existed Express instance, by faced a problem - all nest handlers always add after Express handlers. But I have a root Express middleware I want to apply only for some handlers that go after it. How can I apply Nest handlers before Express handlers? For example. I created a new NestJS project, and changed main.ts import {

TypeORM problem saving entity with cascade true

本小妞迷上赌 提交于 2021-01-27 18:46:47
问题 I m using NestJS with TypeORM and I m trying to save a user conversation with messages. I set the messages field on the conversation entity to cascade: true . But When I try this code: const user3: User = { login: 'admin', createdBy: 'system', lastModifiedBy: 'system' }; const user4: User = { login: 'user', createdBy: 'system', lastModifiedBy: 'system' }; const message1: Message = { content: 'Hello How are you? ', createdBy: user3.login, lastModifiedBy: user3.login }; const conversation1: