Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add find profile post #885

Merged
merged 13 commits into from
Jun 15, 2023
21 changes: 21 additions & 0 deletions src/controllers/user/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@ export class UserPostController {
return this.userService.posts(filter);
}

@intercept(PaginationInterceptor.BINDING_KEY)
@get('/user/profile/{id}/posts')
@response(200, {
description: 'Array of Post model instances',
content: {
'application/json': {
schema: {
type: 'array',
items: getModelSchemaRef(Post, {includeRelations: true}),
},
},
},
})
async findByProfile(
@param.path.string('id') id: string,
@param.filter(Post, {exclude: ['limit', 'skip', 'offset', 'where']})
filter?: Filter<Post>,
): Promise<Post[]> {
return this.userService.profilePosts(id, filter);
}

@intercept(FindByIdInterceptor.BINDING_KEY)
@get('/user/posts/{id}')
@response(200, {
Expand Down
16 changes: 16 additions & 0 deletions src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,22 @@ export class UserService {
);
}

public async profilePosts(
id: string,
filter?: Filter<Post>,
): Promise<Post[]> {
const newFilter: Filter<Post> = {
...filter,
where: {createdBy: id},
};
return this.postService.find(
newFilter,
undefined,
true,
this.currentUser[securityId],
);
}

public async draftPost(): Promise<DraftPost | null> {
return this.postService.draft(this.currentUser[securityId]);
}
Expand Down