#
Comment Plugin
#
Installation
@Module({
imports: [
TypeOrmModule.forRootAsync({
name: DataSourceSupport.MONGODB,
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
name: DataSourceSupport.MONGODB,
type: DataSourceSupport.MONGODB,
url: configService.get('database.mongodb.url'),
logging: true,
synchronize: true,
autoLoadEntities: true,
entities: [Comment],
}),
inject: [ConfigService],
}),
CommentModule.forRoot({
dataSourceName: DataSourceSupport.MONGODB,
userPoolName: AuthGuardSupport.USER,
controllers: [
{
prefix: 'posts',
provider: {
provide: 'POST_PROVIDER',
useClass: PostCommentProvider,
},
},
],
}),
]
})
#
Usage
@Injectable()
export class PostCommentProvider {
constructor(
@InjectDataSource('mongodb')
private dataSource: DataSource,
) { }
async getTarget(targetId: string) {
return this.dataSource
.getRepository(Post)
.findOne({ where: { _id: parseObjectId(targetId) } });
}
async getAuthor(authorId: string) {
return this.dataSource
.getRepository(Account)
.findOne({ where: { _id: parseObjectId(authorId) } });
}
}