nestjs

NestJS Request Scoped Multitenancy for Multiple Databases

余生长醉 提交于 2020-06-11 06:15:39
问题 Looking to implement a multi-tenant NestJS solution using the new request injection scope feature of NestJS 6. For any given service I assume I could do something like this: @Injectable({scope: Scope.REQUEST}) export class ReportService implements OnModuleInit { ... } then, in the constructor, determine the tenant from the request, connect to the appropriate database, and instantiate repositories for the new connection. I'm wondering if this is the most straightforward way to go about it?

NestJS Get current user in GraphQL resolver authenticated with JWT

╄→尐↘猪︶ㄣ 提交于 2020-06-09 10:11:46
问题 I am currently implementing JWT authentication with Passport.js into a NestJS application. In some of my GraphQL resolvers I need to access the currently authenticated user. I know that passport will attach the authenticated user to the request object (at least I hope that this is correct), but I do not know how to access the request object inside a resolver. I followed the issue https://github.com/nestjs/nest/issues/1326 and the mentioned link https://github.com/ForetagInc/fullstack

Set “basedir” option for Pug in NestJS

陌路散爱 提交于 2020-06-01 09:33:08
问题 I'm trying to use pug layouts in NestJS , however when extending a layout from an absolute path, pug requires the basedir option to be set. In ExpressJS you would use app.locals.basedir = ... , what would be the equivalent in NestJS? const server = await NestFactory.create<NestExpressApplication>(AppModule); server.setViewEngine('pug'); server.setBaseViewsDir(join(__dirname, 'templates', 'views')); await server.listen(config.server.port); Using extends /layouts/index in a view would throw the

how to define location in an entity using mongodb

泪湿孤枕 提交于 2020-06-01 05:07:07
问题 I am using nest js in my sample application . I define the entity of my application .Entity means a document . But I struck at one place to define the location . using mongoose I define the schema of my document like this see link https://raw.githubusercontent.com/webmakaka/Node.js-API-Masterclass-With-Express-MongoDB/master/api/models/Bootcamp.js location: { // GeoJSON Point type: { type: String, enum: ['Point'] }, coordinates: { type: [Number], index: '2dsphere' }, formattedAddress: String,

how to unit test a class extending an abstract class reading environment variables

送分小仙女□ 提交于 2020-05-29 17:20:16
问题 I want to get into unit testing and have some configuration services for my Nest API that I want to test. When starting the application I validate the environment variables with the joi package. I have multiple configuration services for the database, the server, ... so I created a base service first. This one is able to read environment variables, parse the raw string to a desired datatype and validate the value. import { ConfigService } from '@nestjs/config'; import { AnySchema,

how to unit test a class extending an abstract class reading environment variables

北城以北 提交于 2020-05-29 17:17:11
问题 I want to get into unit testing and have some configuration services for my Nest API that I want to test. When starting the application I validate the environment variables with the joi package. I have multiple configuration services for the database, the server, ... so I created a base service first. This one is able to read environment variables, parse the raw string to a desired datatype and validate the value. import { ConfigService } from '@nestjs/config'; import { AnySchema,

Schema hasn't been registered for model “ResourceSchema”. - nest js

落爺英雄遲暮 提交于 2020-05-28 07:02:26
问题 Hello everyone i am trying to build api with Nest js and mongodb. i am trying to make relationship between schema and i get that Error when i am trying to populate resource from role [Nest] 12308 - 2019-08-09 4:22 PM [ExceptionsHandler] Schema hasn't been registered for model "ResourceSchema". Use mongoose.model(name, schema) +6998ms MissingSchemaError: Schema hasn't been registered for model "ResourceSchema". Use mongoose.model(name, schema) my RoleSchema import * as mongoose from 'mongoose'

Schema hasn't been registered for model “ResourceSchema”. - nest js

╄→尐↘猪︶ㄣ 提交于 2020-05-28 07:01:55
问题 Hello everyone i am trying to build api with Nest js and mongodb. i am trying to make relationship between schema and i get that Error when i am trying to populate resource from role [Nest] 12308 - 2019-08-09 4:22 PM [ExceptionsHandler] Schema hasn't been registered for model "ResourceSchema". Use mongoose.model(name, schema) +6998ms MissingSchemaError: Schema hasn't been registered for model "ResourceSchema". Use mongoose.model(name, schema) my RoleSchema import * as mongoose from 'mongoose'

Access raw body of Stripe webhook in Nest.js

假如想象 提交于 2020-05-27 05:34:46
问题 I need to access the raw body of the webhook request from Stripe in my Nest.js application. Following this example, I added the below to the module which has a controller method that is needing the raw body. function addRawBody(req, res, next) { req.setEncoding('utf8'); let data = ''; req.on('data', (chunk) => { data += chunk; }); req.on('end', () => { req.rawBody = data; next(); }); } export class SubscriptionModule { configure(consumer: MiddlewareConsumer) { consumer .apply(addRawBody)

Access raw body of Stripe webhook in Nest.js

允我心安 提交于 2020-05-27 05:34:11
问题 I need to access the raw body of the webhook request from Stripe in my Nest.js application. Following this example, I added the below to the module which has a controller method that is needing the raw body. function addRawBody(req, res, next) { req.setEncoding('utf8'); let data = ''; req.on('data', (chunk) => { data += chunk; }); req.on('end', () => { req.rawBody = data; next(); }); } export class SubscriptionModule { configure(consumer: MiddlewareConsumer) { consumer .apply(addRawBody)