diff --git a/src/__tests__/helpers/database.helper.ts b/src/__tests__/helpers/database.helper.ts index 8eea94dd9..6e50a50d8 100644 --- a/src/__tests__/helpers/database.helper.ts +++ b/src/__tests__/helpers/database.helper.ts @@ -71,6 +71,7 @@ export async function givenRepositories(testdb: any) { async () => userRepository, async () => transactionRepository, async () => commentLinkRepository, + async () => voteRepository, ); const transactionRepository: TransactionRepository = new TransactionRepository( diff --git a/src/models/comment.model.ts b/src/models/comment.model.ts index d756049c5..1cd3f8b74 100644 --- a/src/models/comment.model.ts +++ b/src/models/comment.model.ts @@ -5,6 +5,7 @@ import { model, property, } from '@loopback/repository'; +import {Vote} from '.'; import {ReferenceType, SectionType} from '../enums'; import {Metric} from '../interfaces'; import {CommentLink} from './comment-link.model'; @@ -118,6 +119,9 @@ export class Comment extends Entity { }) comments: Comment[]; + @hasMany(() => Vote, {keyTo: 'referenceId'}) + votes: Vote[]; + @hasMany(() => Transaction, {keyTo: 'referenceId'}) transactions: Transaction[]; diff --git a/src/repositories/comment.repository.ts b/src/repositories/comment.repository.ts index 5dd0274e9..60811058f 100644 --- a/src/repositories/comment.repository.ts +++ b/src/repositories/comment.repository.ts @@ -6,6 +6,7 @@ import { HasManyThroughRepositoryFactory, repository, } from '@loopback/repository'; +import {VoteRepository} from '.'; import {MongoDataSource} from '../datasources'; import { Comment, @@ -13,6 +14,7 @@ import { CommentRelations, Transaction, User, + Vote, } from '../models'; import {CommentLinkRepository} from './comment-link.repository'; import {TransactionRepository} from './transaction.repository'; @@ -25,6 +27,11 @@ export class CommentRepository extends DefaultCrudRepository< > { public readonly user: BelongsToAccessor; + public readonly votes: HasManyRepositoryFactory< + Vote, + typeof Vote.prototype.id + >; + public readonly transactions: HasManyRepositoryFactory< Transaction, typeof Comment.prototype.id @@ -45,6 +52,8 @@ export class CommentRepository extends DefaultCrudRepository< protected transactionRepositoryGetter: Getter, @repository.getter('CommentLinkRepository') protected commentLinkRepositoryGetter: Getter, + @repository.getter('VoteRepository') + protected voteRepositoryGetter: Getter, ) { super(Comment, dataSource); this.comments = this.createHasManyThroughRepositoryFactoryFor( @@ -63,5 +72,10 @@ export class CommentRepository extends DefaultCrudRepository< 'transactions', this.transactions.inclusionResolver, ); + this.votes = this.createHasManyRepositoryFactoryFor( + 'votes', + voteRepositoryGetter, + ); + this.registerInclusionResolver('votes', this.votes.inclusionResolver); } }