I am looking to create a filter that can retrieve subscription records
Entity 'Subscription'
export class Subscription {
@PrimaryColumn()
id: string;
@Column('uuid')
userId: string;
@Column('uuid')
targetUserId: string;
@CreateDateColumn()
createdAt: Date;
}
Filter
applyFilter(query: QueryArticle, qb: SelectQueryBuilder<Article>, userId?: string) {
if (query.filter) {
switch (query.filter) {
....
case 'subscriptions':
qb.select(
`article.authorId WHERE targetUserId IN (SELECT targetUserId FROM Subscription WHERE userId=${userId})`,
);
break;
}
}
return qb;
}
SQL code
Select * FROM article WHERE authorId=targetUserId IN (SELECT targetUserId FROM Subscription WHERE userId=userId)
Error
syntax error at or near "f5779e5" +3974ms
QueryFailedError: syntax error at or near "f5779e5"
Is there a way to fetch all posts from users followed by another user using TypeORM?
Thank you in advance for your help!