From 1822c4f82fcfd42114da69a0ca6ddd2ec01e0d5b Mon Sep 17 00:00:00 2001 From: niamu01 Date: Sun, 17 Sep 2023 18:44:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20expTable=20=EB=B0=98?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - #326 --- app/src/app.module.ts | 2 ++ app/src/page/calculator/calculator.module.ts | 11 ++++++++ .../page/calculator/calculator.resolver.ts | 18 +++++++++++++ app/src/page/calculator/calculator.service.ts | 25 +++++++++++++++++++ .../calculator/models/calculator.model.ts | 10 ++++++++ app/src/schema.gql | 6 +++++ 6 files changed, 72 insertions(+) create mode 100644 app/src/page/calculator/calculator.module.ts create mode 100644 app/src/page/calculator/calculator.resolver.ts create mode 100644 app/src/page/calculator/calculator.service.ts create mode 100644 app/src/page/calculator/models/calculator.model.ts diff --git a/app/src/app.module.ts b/app/src/app.module.ts index 244c8415..d0858edb 100644 --- a/app/src/app.module.ts +++ b/app/src/app.module.ts @@ -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'; @@ -82,6 +83,7 @@ export class AppRootModule {} LeaderboardModule, EvalLogModule, SettingModule, + CalculatorModule, LambdaModule, CacheDecoratorOnReturnModule, ], diff --git a/app/src/page/calculator/calculator.module.ts b/app/src/page/calculator/calculator.module.ts new file mode 100644 index 00000000..22cd85df --- /dev/null +++ b/app/src/page/calculator/calculator.module.ts @@ -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 {} diff --git a/app/src/page/calculator/calculator.resolver.ts b/app/src/page/calculator/calculator.resolver.ts new file mode 100644 index 00000000..373fb5ab --- /dev/null +++ b/app/src/page/calculator/calculator.resolver.ts @@ -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 { + return await this.calculatorService.expTable(); + } +} diff --git a/app/src/page/calculator/calculator.service.ts b/app/src/page/calculator/calculator.service.ts new file mode 100644 index 00000000..1edbef81 --- /dev/null +++ b/app/src/page/calculator/calculator.service.ts @@ -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 { + const expTable: Pick[] = + await this.levelService.findAllAndLean({ + sort: { lvl: 1 }, + select: { + lvl: 1, + xp: 1, + }, + }); + + return expTable.map((exp) => ({ + level: exp.lvl, + exp: exp.xp, + })); + } +} diff --git a/app/src/page/calculator/models/calculator.model.ts b/app/src/page/calculator/models/calculator.model.ts new file mode 100644 index 00000000..3dd31c7e --- /dev/null +++ b/app/src/page/calculator/models/calculator.model.ts @@ -0,0 +1,10 @@ +import { Field, ObjectType } from '@nestjs/graphql'; + +@ObjectType() +export class ExpTable { + @Field() + level: number; + + @Field() + exp: number; +} diff --git a/app/src/schema.gql b/app/src/schema.gql index fbc72898..634045d4 100644 --- a/app/src/schema.gql +++ b/app/src/schema.gql @@ -26,6 +26,11 @@ type LoginSuccess { message: String! } +type ExpTable { + level: Int! + exp: Int! +} + type ProjectPreview { id: Int! name: String! @@ -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 {