Skip to content

Commit

Permalink
feat: ✨ expTable 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu01 committed Sep 22, 2023
1 parent f308170 commit 1822c4f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { MongooseRootModule } from './database/mongoose/database.mongoose.module
import { DateWrapper } from './dateWrapper/dateWrapper';
import { LambdaModule } from './lambda/lambda.module';
import { LoginModule } from './login/login.module';
import { CalculatorModule } from './page/calculator/calculator.module';
import { EvalLogModule } from './page/evalLog/evalLog.module';
import { HomeModule } from './page/home/home.module';
import { LandingModule } from './page/landing/landing.module';
Expand Down Expand Up @@ -82,6 +83,7 @@ export class AppRootModule {}
LeaderboardModule,
EvalLogModule,
SettingModule,
CalculatorModule,
LambdaModule,
CacheDecoratorOnReturnModule,
],
Expand Down
11 changes: 11 additions & 0 deletions app/src/page/calculator/calculator.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { LevelModule } from 'src/api/level/level.module';
import { CalculatorResolver } from './calculator.resolver';
import { CalculatorService } from './calculator.service';

@Module({
imports: [LevelModule],
providers: [CalculatorResolver, CalculatorService],
})
// eslint-disable-next-line
export class CalculatorModule {}
18 changes: 18 additions & 0 deletions app/src/page/calculator/calculator.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { UseFilters, UseGuards } from '@nestjs/common';
import { Query, Resolver } from '@nestjs/graphql';
import { StatAuthGuard } from 'src/auth/statAuthGuard';
import { HttpExceptionFilter } from 'src/http-exception.filter';
import { CalculatorService } from './calculator.service';
import { ExpTable } from './models/calculator.model';

@UseFilters(HttpExceptionFilter)
@UseGuards(StatAuthGuard)
@Resolver((_of: unknown) => [ExpTable])
export class CalculatorResolver {
constructor(private readonly calculatorService: CalculatorService) {}

@Query((_returns) => [ExpTable])
async getExpTable(): Promise<ExpTable[]> {
return await this.calculatorService.expTable();
}
}
25 changes: 25 additions & 0 deletions app/src/page/calculator/calculator.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Injectable } from '@nestjs/common';
import { level } from 'src/api/level/db/level.database.schema';
import { LevelService } from 'src/api/level/level.service';
import { ExpTable } from './models/calculator.model';

@Injectable()
export class CalculatorService {
constructor(private readonly levelService: LevelService) {}

async expTable(): Promise<ExpTable[]> {
const expTable: Pick<level, 'lvl' | 'xp'>[] =
await this.levelService.findAllAndLean({
sort: { lvl: 1 },
select: {
lvl: 1,
xp: 1,
},
});

return expTable.map((exp) => ({
level: exp.lvl,
exp: exp.xp,
}));
}
}
10 changes: 10 additions & 0 deletions app/src/page/calculator/models/calculator.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Field, ObjectType } from '@nestjs/graphql';

@ObjectType()
export class ExpTable {
@Field()
level: number;

@Field()
exp: number;
}
6 changes: 6 additions & 0 deletions app/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type LoginSuccess {
message: String!
}

type ExpTable {
level: Int!
exp: Int!
}

type ProjectPreview {
id: Int!
name: String!
Expand Down Expand Up @@ -523,6 +528,7 @@ type Query {
getLeaderboardComment: LeaderboardComment!
getEvalLogs(after: String, first: Int! = 20, corrector: String, corrected: String, projectName: String, outstandingOnly: Boolean! = false, sortOrder: EvalLogSortOrder! = BEGIN_AT_DESC): EvalLogsPaginated!
getSetting: Setting!
getExpTable: [ExpTable!]!
}

enum EvalLogSortOrder {
Expand Down

0 comments on commit 1822c4f

Please sign in to comment.