Allow viewers to request collaboration on posts
فشلت بعض الفحوصات
Deploy To Ghaymah / deploy (push) Has been cancelled

هذا الالتزام موجود في:
boutmoun123
2026-06-10 20:30:03 +03:00
الأصل 48ea432669
التزام a3628d19a2
5 ملفات معدلة مع 274 إضافات و40 حذوفات

عرض الملف

@@ -52,30 +52,27 @@ export class CollaborationRequestsService {
dto: CreateCollaborationRequestDto,
file?: UploadedAudioFile,
) {
const targetUserId = dto.targetUserId;
if (!Types.ObjectId.isValid(postId) || !Types.ObjectId.isValid(targetUserId)) {
if (!Types.ObjectId.isValid(postId)) {
throw new BadRequestException('Invalid collaboration request');
}
if (requesterId === targetUserId) {
throw new BadRequestException('You cannot invite yourself');
}
const [post, targetUser, block] = await Promise.all([
this.postsRepository.findById(postId),
this.usersRepository.findById(targetUserId),
this.blocksRepository.findAnyBetween(requesterId, targetUserId),
]);
const post = await this.postsRepository.findById(postId);
if (!post) {
throw new NotFoundException('Post not found');
}
if (post.authorId.toString() !== requesterId) {
throw new ForbiddenException('Only the post owner can invite collaborators');
const targetUserId = post.authorId.toString();
if (requesterId === targetUserId) {
throw new BadRequestException('You cannot request collaboration on your own post');
}
const [targetUser, block] = await Promise.all([
this.usersRepository.findById(targetUserId),
this.blocksRepository.findAnyBetween(requesterId, targetUserId),
]);
if (!targetUser || targetUser.isDisabled) {
throw new NotFoundException('Target user not found');
}
@@ -302,7 +299,7 @@ export class CollaborationRequestsService {
if (request.postId) {
await this.postsRepository.updateById(request.postId.toString(), {
$addToSet: { collaboratorIds: request.targetUserId },
$addToSet: { collaboratorIds: request.requesterId },
});
}
@@ -568,4 +565,4 @@ export class CollaborationRequestsService {
deepLink: `/users/${actorId}`,
};
}
}
}