Skip to content

Commit fadbbc0

Browse files
committed
feat: add getPublicLiveContest
1 parent 860b1ab commit fadbbc0

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/common/modules/live-contest/live-contest.dto.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ export class UserDTO {
158158
public markers?: string[];
159159
}
160160

161+
export class AdminUserDTO extends UserDTO {
162+
@IsOptional()
163+
@IsBoolean()
164+
public banned?: boolean;
165+
166+
@IsOptional()
167+
@IsString()
168+
public broadcasterToken?: string;
169+
}
170+
161171
export class MarkerDTO {
162172
@IsString()
163173
@IsNotEmpty()
@@ -302,6 +312,26 @@ export class GetLiveContestReqDTO {
302312
}
303313

304314
export class GetLiveContestRespDTO {
315+
public _id: string;
316+
public alias: string;
317+
public name: string;
318+
public contest: ContestDTO;
319+
public problems: ProblemDTO[];
320+
public members: AdminUserDTO[];
321+
public markers: srk.Marker[];
322+
public series: srk.RankSeries[];
323+
public sorter?: srk.Sorter;
324+
public contributors?: string[];
325+
}
326+
327+
export class GetPublicLiveContestReqDTO {
328+
@FromQuery()
329+
@IsString()
330+
@IsNotEmpty()
331+
public alias: string;
332+
}
333+
334+
export class GetPublicLiveContestRespDTO {
305335
public _id: string;
306336
public alias: string;
307337
public name: string;

src/server/modules/live-contest/live-contest.controller.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
CreateLiveContestRespDTO,
88
GetLiveContestReqDTO,
99
GetLiveContestRespDTO,
10+
GetPublicLiveContestReqDTO,
11+
GetPublicLiveContestRespDTO,
1012
UpdateLiveContestReqDTO,
1113
DropLiveContestEventsReqDTO,
1214
GetPublicContestMembersReqDTO,
@@ -85,6 +87,7 @@ export default class LiveContestController {
8587
}
8688

8789
@Get()
90+
@UseGuards(AuthGuard)
8891
@Contract(GetLiveContestReqDTO, GetLiveContestRespDTO)
8992
public async getLiveContest(@Data() data: GetLiveContestReqDTO): Promise<GetLiveContestRespDTO> {
9093
const contest = await LiveContestModel.findOne({ alias: data.alias });
@@ -93,9 +96,20 @@ export default class LiveContestController {
9396
}
9497

9598
const plain = contest.toObject() as GetLiveContestRespDTO;
96-
// const members = await LiveContestMemberModel.find({
97-
// contestId: contest._id.toString(),
98-
// }).sort({ index: 1 });
99+
const members = await this.service.findContestMembers(data.alias);
100+
(plain as any).members = members.map((member) => this.service.filterMemberForAdmin(member));
101+
return plain;
102+
}
103+
104+
@Get()
105+
@Contract(GetPublicLiveContestReqDTO, GetPublicLiveContestRespDTO)
106+
public async getPublicLiveContest(@Data() data: GetPublicLiveContestReqDTO): Promise<GetPublicLiveContestRespDTO> {
107+
const contest = await LiveContestModel.findOne({ alias: data.alias });
108+
if (!contest) {
109+
throw new LogicException(ErrCode.LiveContestNotFound);
110+
}
111+
112+
const plain = contest.toObject() as GetPublicLiveContestRespDTO;
99113
const members = await this.service.findContestMembers(data.alias);
100114
(plain as any).members = members.map((member) => this.service.filterMemberForPublic(member));
101115
return plain;

0 commit comments

Comments
 (0)