Skip to content

Commit

Permalink
feat: ✨ leaderboard metadata 에 coalitionList 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jpham005 committed Oct 29, 2023
1 parent 0df2ed2 commit eee9b1d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
11 changes: 11 additions & 0 deletions app/src/api/coalition/coalition.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { InjectModel } from '@nestjs/mongoose';
import type { Aggregate, Model } from 'mongoose';
import { API_CONFIG } from 'src/config/api';
import { CDN_CONFIG } from 'src/config/cdn';
import { findAllAndLean } from 'src/database/mongoose/database.mongoose.query';
import type { Coalition } from '../../page/common/models/coalition.model';
import { coalition } from './db/coalition.database.schema';

Expand Down Expand Up @@ -59,4 +60,14 @@ export class CoalitionService {
getSeoulCoalitionIds(): readonly number[] {
return this.apiConfig.SEOUL_COALITION_ID;
}

async getSeoulCoalitions(): Promise<Coalition[]> {
const coalitions = await findAllAndLean<coalition>(this.coalitionModel, {
filter: {
id: { $in: this.getSeoulCoalitionIds() },
},
});

return coalitions.map((coalition) => this.daoToDto(coalition));
}
}
3 changes: 1 addition & 2 deletions app/src/page/leaderboard/common/models/leaderboard.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Field, InterfaceType, ObjectType } from '@nestjs/graphql';
import { Field, ObjectType } from '@nestjs/graphql';
import {
UserRank,
UserRankingIndexPaginated,
} from 'src/common/models/common.user.model';
import { DateRanged } from 'src/dateRange/models/dateRange.model';
import { Promo } from 'src/page/common/models/promo.model';

@ObjectType()
export class LeaderboardElement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Module } from '@nestjs/common';
import { CoalitionModule } from 'src/api/coalition/coalition.module';
import { PromoModule } from 'src/api/promo/promo.module';
import { LeaderboardMetadataService } from './leaderboard.metadata.service';
import { LeaderboardMetadataResolver } from './leaderboard.metadata.resolver';
import { LeaderboardMetadataService } from './leaderboard.metadata.service';

@Module({
imports: [PromoModule],
imports: [PromoModule, CoalitionModule],
providers: [LeaderboardMetadataService, LeaderboardMetadataResolver],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Query, ResolveField, Resolver } from '@nestjs/graphql';
import { LeaderboardMetadata } from './models/leaderboard.metadata.model';
import { LeaderboardMetadataService } from './leaderboard.metadata.service';
import { Promo } from 'src/page/common/models/promo.model';
import { Coalition } from 'src/page/common/models/coalition.model';

@Resolver((_of: unknown) => LeaderboardMetadata)
export class LeaderboardMetadataResolver {
Expand All @@ -11,7 +12,7 @@ export class LeaderboardMetadataResolver {

@Query((_returns) => LeaderboardMetadata)
async getLeaderboardMetadata(): Promise<
Omit<LeaderboardMetadata, 'promoList'>
Omit<LeaderboardMetadata, 'promoList' | 'coalitionList'>
> {
return {};
}
Expand All @@ -20,4 +21,9 @@ export class LeaderboardMetadataResolver {
async promoList(): Promise<Promo[]> {
return await this.leaderboardMetadataService.promoList();
}

@ResolveField((_returns) => [Coalition])
async coalitionList(): Promise<Coalition[]> {
return await this.leaderboardMetadataService.coalitionList();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { Injectable } from '@nestjs/common';
import { CoalitionService } from 'src/api/coalition/coalition.service';
import { PromoService } from 'src/api/promo/promo.service';
import type { Coalition } from 'src/page/common/models/coalition.model';
import type { Promo } from 'src/page/common/models/promo.model';

@Injectable()
export class LeaderboardMetadataService {
constructor(private readonly promoService: PromoService) {}
constructor(
private readonly promoService: PromoService,
private readonly coalitionService: CoalitionService,
) {}

async promoList(): Promise<Promo[]> {
return await this.promoService.promoList();
}

async coalitionList(): Promise<Coalition[]> {
return await this.coalitionService.getSeoulCoalitions();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Field, ObjectType } from '@nestjs/graphql';
import { Coalition } from 'src/page/common/models/coalition.model';
import { Promo } from 'src/page/common/models/promo.model';

@ObjectType()
export class LeaderboardMetadata {
@Field((_type) => [Promo])
promoList: Promo[];

@Field((_type) => [Coalition])
coalitionList: Coalition[];
}
1 change: 1 addition & 0 deletions app/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ type Promo {

type LeaderboardMetadata {
promoList: [Promo!]!
coalitionList: [Coalition!]!
}

type LeaderboardScore {
Expand Down

0 comments on commit eee9b1d

Please sign in to comment.