我遵循了Nest JS Crash 教程,Youtube Link,我遵循了这个,但是当我在服务中导入接口时,它显示错误
Nest 无法解析 ItemsService (?) 的依赖项。请确保索引 [0] 处的参数在 AppModule 上下文中可用。
我克隆了教程中给出的存储库,它工作正常,但是当我将该存储库的 src 文件夹复制到我的项目时,它会引发错误。这是我的服务文件
import { Injectable } from '@nestjs/common';
import { Item } from './interfaces/item.interface';
import { Model } from 'mongoose';
import { ItemsModule } from './items.module'
import { InjectModel } from '@nestjs/mongoose';
@Injectable()
export class ItemsService {
constructor(@InjectModel('Item') private readonly itemModel: Model<Item>) {}
});
}
Run Code Online (Sandbox Code Playgroud)
当我评论构造函数行时,它工作正常,我认为问题出在这一行上,
从'猫鼬'导入{模型};
因为当我将鼠标悬停在这一行时,它显示找不到此模块的声明。我什至尝试复制工作代码的 package.json 文件进行测试,但仍然错误保持不变
我的模块项目包含控制器文件、服务文件、模块文件、dto 文件、接口文件、架构文件、
我正在 Angular 8 中工作,我有一个组件,我有大约 6 个或更多模板。用户将从界面或某种逻辑中选择使用哪一个,比方说,
if(a==2) use template 'ddd.html'
else user template 'sss.html'
Run Code Online (Sandbox Code Playgroud)
我不想在这里使用它
@Component({
selector: 'app-maindisplay',
templateUrl: './maindisplay.component.html',
styleUrls: ['./maindisplay.component.css']
})
Run Code Online (Sandbox Code Playgroud)
我希望它出现在任何函数中,无论是构造函数还是任何其他函数。如果它使用任何子组件或指令类型的逻辑来解决就可以了,我唯一需要的是在该逻辑上选择模板。我通常会将相同的数据传递给所有模板,只有它们的设计会改变。
我正在 NestJS 中开发 api 和微服务,这是我的控制器功能
@Post()
@MessagePattern({ service: TRANSACTION_SERVICE, msg: 'create' })
create( @Body() createTransactionDto: TransactionDto_create ) : Promise<Transaction>{
return this.transactionsService.create(createTransactionDto)
}
Run Code Online (Sandbox Code Playgroud)
当我调用 post api 时,dto 验证工作正常,但是当我使用微服务调用此验证时,验证不起作用,它会传递到服务而不会因错误而拒绝。这是我的 DTO
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
export class TransactionDto_create{
@IsNotEmpty()
action: string;
// @IsString()
readonly rec_id : string;
@IsNotEmpty()
readonly data : Object;
extras : Object;
// readonly extras2 : Object;
}
Run Code Online (Sandbox Code Playgroud)
当我调用没有操作参数的 api 时,它会显示所需的错误操作,但是当我使用微服务调用它时
const 模式 = { 服务: TRANSACTION_SERVICE, msg: '创建' }; const data = {id: '5d1de5d787db5151903c80b9', extras:{'asdf':'dsf'}}; …
我在 nodejs 中使用 mongoDB 更改流,一切正常,但如果数据库关闭需要超过 10 5 秒才能启动更改流会引发超时错误,这是我的更改流观察器代码
Service.prototype.watcher = function( db ){
let collection = db.collection('tokens');
let changeStream = collection.watch({ fullDocument: 'updateLookup' });
let resumeToken, newChangeStream;
changeStream.on('change', next => {
resumeToken = next._id;
console.log('data is ', JSON.stringify(next))
changeStream.close();
// console.log('resumeToken is ', JSON.stringify(resumeToken))
newChangeStream = collection.watch({ resumeAfter : resumeToken });
newChangeStream.on('change', next => {
console.log('insert called ', JSON.stringify( next ))
});
});
Run Code Online (Sandbox Code Playgroud)
但是在数据库端我已经处理了它,即如果数据库关闭或使用此代码重新连接
this.db.on('reconnected', function () {
console.info('MongoDB reconnected!');
});
this.db.on('disconnected', function() {
console.warn('MongoDB disconnected!');
});
Run Code Online (Sandbox Code Playgroud)
但我无法处理更改流观察程序以在数据库关闭时停止它并在重新连接数据库时重新启动它,或者是否有其他更好的方法来做到这一点?