refactor: whitelist public match responses
This commit is contained in:
1 parent
874d785381
commit
28e9ac1529
4 files changed
+248
-40
No files matched your search
@@ -18,11 +18,7 @@ import { CurrentUser } from '../auth/current-user.decorator';
|
||||
import { Roles } from '../auth/roles.decorator';
|
||||
import { RolesGuard } from '../auth/roles.guard';
|
||||
import { ParseObjectIdPipe } from '../common/parse-object-id.pipe';
|
||||
import type {
|
||||
MatchDocument,
|
||||
MatchStatus,
|
||||
UserDocument,
|
||||
} from '../global/database/schema';
|
||||
import type { MatchStatus, UserDocument } from '../global/database/schema';
|
||||
import {
|
||||
AddParticipantDto,
|
||||
ApplyDoubleEliminationWalkoverDto,
|
||||
@@ -95,11 +91,19 @@ export class MatchController {
|
||||
scheduledTo: this.toOptionalDate(scheduledTo),
|
||||
sort,
|
||||
});
|
||||
if (!currentUser) return result;
|
||||
const myId = currentUser._id;
|
||||
return {
|
||||
...result,
|
||||
matches: result.matches.map((m) => this.annotateJoined(m, myId)),
|
||||
matches: result.matches.map((match) =>
|
||||
this.matchService.serialize(match, {
|
||||
...(currentUser
|
||||
? {
|
||||
joined: match.participants.some((participant) =>
|
||||
participant.userId.equals(currentUser._id),
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
}),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -344,15 +348,6 @@ export class MatchController {
|
||||
return new mongoose.Types.ObjectId(bodyUserId);
|
||||
}
|
||||
|
||||
private annotateJoined(
|
||||
match: MatchDocument,
|
||||
userId: mongoose.Types.ObjectId,
|
||||
) {
|
||||
const obj = match.toObject();
|
||||
const joined = match.participants.some((p) => p.userId.equals(userId));
|
||||
return { ...obj, joined };
|
||||
}
|
||||
|
||||
private assertSameCommunity(
|
||||
user: UserDocument,
|
||||
communityId: mongoose.Types.ObjectId,
|
||||
|
||||
Reference in new issue
Block a user