nestjs

NestJS Jest cannot find module with absolute path

余生长醉 提交于 2021-02-17 01:56:28
问题 I have a quite new NestJS application. I'm trying to run unit tests, but they keep failing due to 'cannot find module..' when using absolute paths ("src/users/..."), but works when using relative paths ("./users/.."). Is there anything wrong with my configuration here? Jest setup in package.json: "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "rootDir": "src", "testRegex": ".spec.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" }, "coverageDirectory": "../coverage", "testEnvironment

ValidationPipe() does not work on override @Query in Nestjs/Crud

穿精又带淫゛_ 提交于 2021-02-16 15:06:52
问题 I'm trying to validate the parameters that come in the query of a get request, but for some reason, the validation pipe is unable to identify the elements of the query. import { Controller, Post, Query, Body, UseInterceptors, Param, Res, Logger, } from '@nestjs/common'; import { Crud, CrudController, Override } from '@nestjsx/crud'; import { OpenScheduleDto } from './open-schedule.dto'; @Crud(Schedule) export class ScheduleController implements CrudController<ScheduleService, Schedule> {

ValidationPipe() does not work on override @Query in Nestjs/Crud

戏子无情 提交于 2021-02-16 15:05:53
问题 I'm trying to validate the parameters that come in the query of a get request, but for some reason, the validation pipe is unable to identify the elements of the query. import { Controller, Post, Query, Body, UseInterceptors, Param, Res, Logger, } from '@nestjs/common'; import { Crud, CrudController, Override } from '@nestjsx/crud'; import { OpenScheduleDto } from './open-schedule.dto'; @Crud(Schedule) export class ScheduleController implements CrudController<ScheduleService, Schedule> {

How can I change the property name of a serialized entity with toJSON?

南楼画角 提交于 2021-02-11 14:01:11
问题 I want to serialize a property with a different name than it has in the entity. @Entity() export class MyEntity { // This should be serialized with name_column in JSON @Column() name: string } When I call classToPlain I want the property name to be serialized to name_column : classToPlain(myEntity) // returns: {name: 'my name'} // should be: {name_column: 'my name'} 回答1: Is there a specific reason you are using json-typescript-mapper instead of class-transformer, which is natively supported

Nest.js can't resolve dependencies

此生再无相见时 提交于 2021-02-11 13:34:39
问题 I am trying to use ConfigService in my users.module.ts but I am getting an Error: Nest can't resolve dependencies of the UsersService (UserRepository, HttpService, ?). Please make sure that the argument ConfigService at index [2] is available in the UsersModule context. Potential solutions: If ConfigService is a provider, is it part of the current UsersModule? If ConfigService is exported from a separate @Module, is that module imported within UsersModule? I have imported the ConfigModule in

Nest.js can't resolve dependencies

人走茶凉 提交于 2021-02-11 13:34:25
问题 I am trying to use ConfigService in my users.module.ts but I am getting an Error: Nest can't resolve dependencies of the UsersService (UserRepository, HttpService, ?). Please make sure that the argument ConfigService at index [2] is available in the UsersModule context. Potential solutions: If ConfigService is a provider, is it part of the current UsersModule? If ConfigService is exported from a separate @Module, is that module imported within UsersModule? I have imported the ConfigModule in

Update a column in database in NodeJs

江枫思渺然 提交于 2021-02-11 12:40:51
问题 I want to update a column which has a relation: async update(req, res): Promise<any> { const {email, password, id} = req.body; try { await getConnection() .createQueryBuilder() .update(User) .set({ email: email, password: password, meta: [{ name: "tesst", message: "jasshd" }] }) .where("id = :id", {id: id}) .execute(); res.status(201).send({ message: 'user updated' }) } catch (e) { console.log('update', e) res.send({ message: 'update error' }) } } Meta table is in relation with User table.

Update a column in database in NodeJs

a 夏天 提交于 2021-02-11 12:40:48
问题 I want to update a column which has a relation: async update(req, res): Promise<any> { const {email, password, id} = req.body; try { await getConnection() .createQueryBuilder() .update(User) .set({ email: email, password: password, meta: [{ name: "tesst", message: "jasshd" }] }) .where("id = :id", {id: id}) .execute(); res.status(201).send({ message: 'user updated' }) } catch (e) { console.log('update', e) res.send({ message: 'update error' }) } } Meta table is in relation with User table.

Insert data in database depending by relation

徘徊边缘 提交于 2021-02-11 12:28:00
问题 I am using typeorm, Nest Js and postgresql database. I have the next entities: import {Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, JoinColumn, OneToOne} from 'typeorm'; import {User} from "./user.entity"; import {MetaImages} from "./meta-images.entity"; @Entity() export class Cars { @PrimaryGeneratedColumn({name: "carId"}) carId: number; @OneToMany(() => CarsColors, c => c.carId, { cascade: true }) carsColors: CarsColors[]; } /// Colors Entity @Entity() export class

How to configure rate-limit with fastify-adapter in nest js

情到浓时终转凉″ 提交于 2021-02-10 20:34:55
问题 I Just started implementing API's Nest js and I am using Fastify adapter. I need help to configure Rate limit using FastifyAdapter in Nest JS. async function bootstrap() { const app = await NestFactory.create<NestFastifyApplication>( AppModule, new FastifyAdapter(), ); const limiter = fastifyRateLimit(fastify(), { timeWindow: 15 * 60 * 1000, // 15 minutes max: 100 // limit each IP to 100 requests per windowMs }, (err) => { }); app.use(limiter); await app.listen(configService.getPort()); }