Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
feat(posts): add possibility to search for posts that are liked by ce…
Browse files Browse the repository at this point in the history
…rtain users (#8)

Signed-off-by: Christoph Bühler <[email protected]>
  • Loading branch information
buehler authored Mar 15, 2023
1 parent bd9ca05 commit 9a483da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/data/data.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type SearchParams = {
tags?: string[];
mentions?: string[];
isReply?: boolean;
likedBy?: string[];
};

export type CreateParams = {
Expand Down
6 changes: 5 additions & 1 deletion src/data/posts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class PostsService {
* Results are paginated. Does not find deleted posts.
*/
async search(
{ isReply, text, mentions, tags }: SearchParams,
{ isReply, text, mentions, tags, likedBy }: SearchParams,
offset: number,
limit: number,
) {
Expand Down Expand Up @@ -108,6 +108,10 @@ export class PostsService {
);
}

if (likedBy !== undefined && likedBy.length > 0) {
query = query.andWhere(`p.likers && :likedBy`, { likedBy });
}

const [posts, count] = await query.getManyAndCount();
return { posts, count };
}
Expand Down
11 changes: 11 additions & 0 deletions src/rest/rest.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ export const searchParamsSchema: Record<
example: 'newpost',
},
},
likedBy: {
type: 'array',
items: {
uniqueItems: true,
type: 'string',
nullable: false,
description:
'Search for posts that were liked by specific user(s). If multiple user ids are provided, they are "or"-ed (if a post is liked by user A OR B).',
example: '179944860378202369',
},
},
mentions: {
type: 'array',
items: {
Expand Down

0 comments on commit 9a483da

Please sign in to comment.