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

fix: handle get post by originPostId #866

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/controllers/user/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
UpdatePostDto,
} from '../../models';
import {UserService} from '../../services';
import {PlatformType} from '../../enums';

@authenticate('jwt')
export class UserPostController {
Expand Down Expand Up @@ -78,8 +79,9 @@ export class UserPostController {
async findById(
@param.path.string('id') id: string,
@param.filter(Post, {exclude: 'where'}) filter?: FilterExcludingWhere<Post>,
@param.query.string('platform') platform?: PlatformType,
): Promise<Post> {
return this.userService.post(id, filter);
return this.userService.post(id, filter, platform);
}

@get('/user/posts/action')
Expand Down
23 changes: 21 additions & 2 deletions src/services/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Friend,
People,
Post,
PostRelations,
PostWithRelations,
User,
} from '../models';
Expand Down Expand Up @@ -228,11 +229,29 @@ export class PostService {

public async findById(
id: string,
filter?: Filter<Post>,
filter = {} as Filter<Post>,
withImporter = false,
userId?: string,
platform?: PlatformType,
): Promise<Post> {
const currentPost = await this.postRepository.findById(id, filter);
let currentPost: Post & PostRelations;

if (platform && platform !== PlatformType.MYRIAD) {
const post = await this.postRepository.findOne({
where: {
originPostId: id,
platform,
},
});
if (!post) {
throw new HttpErrors.NotFound('PostNotFound');
}

currentPost = post;
} else {
currentPost = await this.postRepository.findById(id, filter);
}

if (!withImporter) return currentPost;
await this.validateUnrestrictedPost(currentPost, userId);
return this.postWithImporterInfo(currentPost, userId);
Expand Down
8 changes: 7 additions & 1 deletion src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ControllerType,
FriendStatusType,
PermissionKeys,
PlatformType,
ReferenceType,
} from '../enums';
import {TokenServiceBindings} from '../keys';
Expand Down Expand Up @@ -774,12 +775,17 @@ export class UserService {
);
}

public async post(id: string, filter?: Filter<Post>): Promise<Post> {
public async post(
id: string,
filter?: Filter<Post>,
platform?: PlatformType,
): Promise<Post> {
return this.postService.findById(
id,
filter,
true,
this.currentUser[securityId],
platform,
);
}

Expand Down
Loading