我正在尝试连接到数据库,似乎设置是正确的,但由于某种原因,它说它不可用。
app.module.ts
import { Module } from "@nestjs/common"
import { MongooseModule } from "@nestjs/mongoose";
import { ConfigModule } from "../config";
import { CreatorModule } from "./creator.module";
@Module({
imports: [
MongooseModule.forRoot('mongodb://localhost:27017/snaptoon', {
useCreateIndex: true,
useUnifiedTopology: true,
useNewUrlParser: true,
}),
CreatorModule,
],
controllers: [],
providers: []
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
错误是:ERROR [MongooseModule] Unable to connect to the database. Retrying (9)...
我在用着'@nestjs/mongoose': '9.0.2'
我正在研究如何避免在每个 dto 中指定 @ApiProperty() 的方法。
我知道存在一种创建 file 的方法nest-cli.json,如果您Promise<DTO>在 Nest-swagger 的控制器中指定,它将从路由生成输出 dto 。
结构如下:
nest-cli.json
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"plugins": [
{
"name": "@nestjs/swagger",
"options": {
"introspectComments": true
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
controller.ts
@Get()
async getMonitors (): Promise<OutputMonitorsDto> { // <-- Here is my outputDto
return this.monitorsService.getMonitors()
}
Run Code Online (Sandbox Code Playgroud)
但是,有没有办法将 NestJs 设置为与 inputDTO 具有相同的内容,而不是在每个 dto 中写入@ApiProperty?
如下例所示:
ExampleDto.ts
export class GetListUsersDto {
@ApiProperty()
@IsString()
name: string
@ApiProperty()
@IsString()
email: string
@ApiProperty() …Run Code Online (Sandbox Code Playgroud) 我在 Nest.js 框架中编写了 3 年,我通过后端应用程序收到了消息:
WARN [DependenciesScanner] In the next major version, Nest will not allow classes annotated with @Injectable(), @Catch(), and @Controller() decorators to appear in the "imports" array of a module.
Please remove "ExternalOrAdmin" (including forwarded occurrences, if any) from all of the "imports" arrays.
Scope [BackendAdminModule -> LicenseModule -> AuthModule]
Run Code Online (Sandbox Code Playgroud)
我研究了 Nest.js github,并发现问题是什么以及为什么它说一些可用装饰器的弃用。
有谁知道如何解决这个问题或者 Nest.js 框架的下一个主要版本将会有什么
提前致谢!
我的系统有这样的自定义错误:
import { ExtendableError } from './extandable.error'
export const customError = {
EMAIL_EXIST: () => new ExtendableError({
message: 'USER WITH SUCH EMAIL ALREADY EXIST',
code: 403
}),
INVALID_EMAIL: () => new ExtendableError({
message: 'INVALID EMAIL',
code: 400
}),
INVALID_PASSWORD: () => new ExtendableError({
message: 'INVALID EMAIL OR PASSWORD',
code: 403
}),
EMAIL_DOES_NOT_EXIST: () => new ExtendableError({
message: 'EMAIL DOES NOT EXIST',
code: 404
}),
TOKEN_DOES_NOT_EXIST: () => new ExtendableError({
message: 'TOKEN DOES NOT EXIST',
code: 404
}),
DIFFERENT_PASSWORDS: () => …Run Code Online (Sandbox Code Playgroud)