From 63c24dd1427330fd57f38b4b66dd7bec9757614f Mon Sep 17 00:00:00 2001 From: tsa96 Date: Wed, 6 Dec 2023 06:18:14 +0000 Subject: [PATCH] chore(back): remove admin XP variables endpoints --- apps/backend-e2e/src/admin.e2e-spec.ts | 180 +---------------- .../src/app/modules/admin/admin.controller.ts | 36 +--- .../src/app/modules/admin/admin.module.ts | 2 - .../modules/xp-systems/xp-systems.module.ts | 2 - libs/backend/dto/src/dtos/index.ts | 1 - .../dto/src/dtos/xp-systems/xp-systems.dto.ts | 185 ------------------ 6 files changed, 2 insertions(+), 404 deletions(-) delete mode 100644 libs/backend/dto/src/dtos/xp-systems/xp-systems.dto.ts diff --git a/apps/backend-e2e/src/admin.e2e-spec.ts b/apps/backend-e2e/src/admin.e2e-spec.ts index 0cf6d0452..69041502d 100644 --- a/apps/backend-e2e/src/admin.e2e-spec.ts +++ b/apps/backend-e2e/src/admin.e2e-spec.ts @@ -19,8 +19,7 @@ import { AdminActivityDto, MapDto, ReportDto, - UserDto, - XpSystemsDto + UserDto } from '@momentum/backend/dto'; import { ActivityType, @@ -2608,183 +2607,6 @@ describe('Admin', () => { }); }); - describe('admin/xpsys', () => { - let adminToken, modToken, u1Token; - - beforeEach(async () => { - [adminToken, modToken, u1Token] = await Promise.all([ - db.loginNewUser({ data: { roles: Role.ADMIN } }), - db.loginNewUser({ data: { roles: Role.MODERATOR } }), - db.loginNewUser() - ]); - - await prisma.xpSystems.deleteMany(); - await prisma.xpSystems.create({ - data: { - id: 1, - rankXP: { - top10: { - WRPoints: 3000, - rankPercentages: [ - 1, 0.75, 0.68, 0.61, 0.57, 0.53, 0.505, 0.48, 0.455, 0.43 - ] - }, - groups: { - maxGroups: 4, - groupMinSizes: [10, 45, 125, 250], - groupExponents: [0.5, 0.56, 0.62, 0.68], - groupPointPcts: [0.2, 0.13, 0.07, 0.03], - groupScaleFactors: [1, 1.5, 2, 2.5] - }, - formula: { A: 50000, B: 49 } - }, - - cosXP: { - levels: { - maxLevels: 500, - startingValue: 20000, - staticScaleStart: 101, - linearScaleInterval: 10, - staticScaleInterval: 25, - linearScaleBaseIncrease: 1000, - staticScaleBaseMultiplier: 1.5, - linearScaleIntervalMultiplier: 1, - staticScaleIntervalMultiplier: 0.5 - }, - completions: { - repeat: { - tierScale: { bonus: 40, linear: 20, staged: 40, stages: 5 } - }, - unique: { tierScale: { linear: 2500, staged: 2500 } } - } - } - } - }); - }); - - afterEach(() => db.cleanup('user')); - afterAll(() => db.cleanup('xpSystems')); - - describe('GET', () => { - it('should respond with the current XP System variables when the user is an admin', () => - req.get({ - url: 'admin/xpsys', - status: 200, - token: adminToken, - validate: XpSystemsDto - })); - - it('should respond with the current XP System variables when the user is a moderator', () => - req.get({ - url: 'admin/xpsys', - status: 200, - token: modToken, - validate: XpSystemsDto - })); - - it('should 403 when the user requesting is not an admin', () => - req.get({ - url: 'admin/xpsys', - status: 403, - token: u1Token - })); - - it('should 401 when no access token is provided', () => - req.unauthorizedTest('admin/xpsys', 'get')); - }); - - describe('PUT', () => { - const body = { - rankXP: { - top10: { - WRPoints: 3000, - rankPercentages: [ - 1, 0.75, 0.68, 0.61, 0.57, 0.53, 0.505, 0.48, 0.455, 0.43 - ] - }, - groups: { - maxGroups: 4, - groupMinSizes: [10, 45, 125, 250], - groupExponents: [0.5, 0.56, 0.62, 0.68], - groupPointPcts: [0.2, 0.13, 0.07, 0.03], - groupScaleFactors: [1, 1.5, 2, 2.5] - }, - formula: { A: 50000, B: 49 } - }, - - cosXP: { - levels: { - maxLevels: 600, - startingValue: 20000, - staticScaleStart: 101, - linearScaleInterval: 10, - staticScaleInterval: 25, - linearScaleBaseIncrease: 1000, - staticScaleBaseMultiplier: 1.5, - linearScaleIntervalMultiplier: 1, - staticScaleIntervalMultiplier: 0.5 - }, - completions: { - repeat: { - tierScale: { bonus: 40, linear: 20, staged: 40, stages: 5 } - }, - unique: { tierScale: { linear: 2500, staged: 2500 } } - } - } - }; - - it('should update the XP system variables', async () => { - await req.put({ - url: 'admin/xpsys', - status: 204, - body: body, - token: adminToken - }); - - const res = await req.get({ - url: 'admin/xpsys', - status: 200, - token: adminToken, - validate: XpSystemsDto - }); - - expect(res.body.cosXP.levels.maxLevels).toBe(600); - expect(res.body).toStrictEqual(body as XpSystemsDto); - }); - - it('should 400 when updating the XP system variables with missing values', async () => { - const incompleteBody = body; - delete incompleteBody.rankXP.top10.rankPercentages; - - await req.put({ - url: 'admin/xpsys', - status: 400, - body: incompleteBody, - token: adminToken - }); - }); - - it('should 403 when the user requesting is a moderator', () => - req.put({ - url: 'admin/xpsys', - status: 403, - body: body, - token: modToken - })); - - it('should 403 when the user requesting is not an admin', () => - req.put({ - url: 'admin/xpsys', - status: 403, - body: body, - token: u1Token - })); - - it('should 401 when no access token is provided', () => - req.unauthorizedTest('admin/xpsys', 'get')); - }); - }); - describe('admin/activities', () => { describe('GET', () => { let admin, adminToken, mod, u1, u1Token; diff --git a/apps/backend/src/app/modules/admin/admin.controller.ts b/apps/backend/src/app/modules/admin/admin.controller.ts index 72d89374d..d6ce86c82 100644 --- a/apps/backend/src/app/modules/admin/admin.controller.ts +++ b/apps/backend/src/app/modules/admin/admin.controller.ts @@ -8,7 +8,6 @@ import { Param, Patch, Post, - Put, Query, UseGuards } from '@nestjs/common'; @@ -28,7 +27,6 @@ import { RolesGuard } from '../auth/roles.guard'; import { NonGameAuthGuard } from '../auth/jwt/game.guard'; import { LoggedInUser, Roles } from '@momentum/backend/decorators'; import { Role as RolesEnum } from '@momentum/constants'; -import { XpSystemsService } from '../xp-systems/xp-systems.service'; import { MapsService } from '../maps/maps.service'; import { UsersService } from '../users/users.service'; import { @@ -46,9 +44,7 @@ import { ReportDto, UpdateMapAdminDto, UpdateReportDto, - UpdateXpSystemsDto, - UserDto, - XpSystemsDto + UserDto } from '@momentum/backend/dto'; import { ParseIntSafePipe } from '@momentum/backend/pipes'; import { AdminActivityService } from './admin-activity.service'; @@ -62,7 +58,6 @@ import { AdminActivityService } from './admin-activity.service'; export class AdminController { constructor( private readonly adminService: AdminService, - private readonly xpSystems: XpSystemsService, private readonly mapsService: MapsService, private readonly usersService: UsersService, private readonly adminActivityService: AdminActivityService @@ -270,35 +265,6 @@ export class AdminController { return this.adminService.updateReport(userID, reportID, body); } - @Get('/xpsys') - @Roles(RolesEnum.ADMIN, RolesEnum.MODERATOR) - @ApiOperation({ description: 'Retrives the current XP system variables' }) - @ApiOkResponse({ - type: XpSystemsDto, - description: 'The current XP system variables' - }) - getXPSystems() { - return this.xpSystems.get(); - } - - @Put('/xpsys') - @Roles(RolesEnum.ADMIN) - @ApiOperation({ - description: 'Creates or Updates the current XP System variables' - }) - @HttpCode(HttpStatus.NO_CONTENT) - @ApiNoContentResponse({ - description: 'The XP System variables were updated successfully' - }) - @ApiBody({ - type: UpdateXpSystemsDto, - description: 'The XP System variables to set', - required: true - }) - updateXPSystems(@Body() body: UpdateXpSystemsDto) { - return this.xpSystems.update(body); - } - @Get('/activities') @Roles(RolesEnum.ADMIN, RolesEnum.MODERATOR) @ApiOperation({ diff --git a/apps/backend/src/app/modules/admin/admin.module.ts b/apps/backend/src/app/modules/admin/admin.module.ts index d72401dbf..1903aabc3 100644 --- a/apps/backend/src/app/modules/admin/admin.module.ts +++ b/apps/backend/src/app/modules/admin/admin.module.ts @@ -3,7 +3,6 @@ import { AdminController } from './admin.controller'; import { AdminService } from './admin.service'; import { DbModule } from '../database/db.module'; import { MapsModule } from '../maps/maps.module'; -import { XpSystemsModule } from '../xp-systems/xp-systems.module'; import { UsersModule } from '../users/users.module'; import { AdminActivityService } from './admin-activity.service'; @@ -11,7 +10,6 @@ import { AdminActivityService } from './admin-activity.service'; imports: [ DbModule.forRoot(), forwardRef(() => MapsModule), - forwardRef(() => XpSystemsModule), forwardRef(() => UsersModule) ], controllers: [AdminController], diff --git a/apps/backend/src/app/modules/xp-systems/xp-systems.module.ts b/apps/backend/src/app/modules/xp-systems/xp-systems.module.ts index 0e97520aa..6c077aaf2 100644 --- a/apps/backend/src/app/modules/xp-systems/xp-systems.module.ts +++ b/apps/backend/src/app/modules/xp-systems/xp-systems.module.ts @@ -1,9 +1,7 @@ import { Module } from '@nestjs/common'; import { XpSystemsService } from './xp-systems.service'; -import { DbModule } from '../database/db.module'; @Module({ - imports: [DbModule.forRoot()], providers: [XpSystemsService], exports: [XpSystemsService] }) diff --git a/libs/backend/dto/src/dtos/index.ts b/libs/backend/dto/src/dtos/index.ts index b49e83582..d6ff0c1df 100644 --- a/libs/backend/dto/src/dtos/index.ts +++ b/libs/backend/dto/src/dtos/index.ts @@ -39,4 +39,3 @@ export * from './user/notification.dto'; export * from './user/user-maps-summary.dto'; export * from './user/socials.dto'; export * from './user/admin-activity-dto'; -export * from './xp-systems/xp-systems.dto'; diff --git a/libs/backend/dto/src/dtos/xp-systems/xp-systems.dto.ts b/libs/backend/dto/src/dtos/xp-systems/xp-systems.dto.ts deleted file mode 100644 index ac6fa6c4b..000000000 --- a/libs/backend/dto/src/dtos/xp-systems/xp-systems.dto.ts +++ /dev/null @@ -1,185 +0,0 @@ -import { ApiProperty, PickType } from '@nestjs/swagger'; -import { NestedProperty } from '../../decorators'; -import { IsArray, IsDefined, IsNumber } from 'class-validator'; - -// Could implement RankXpParams and CosXpParams in xp-systems.interface.ts but -// class-validator requires we give it this wacky structure. - -class CosXpTierScale { - @ApiProperty() - @IsNumber() - readonly linear: number; - - @ApiProperty() - @IsNumber() - readonly staged: number; - - @ApiProperty() - @IsNumber() - readonly stages: number; - - @ApiProperty() - @IsNumber() - readonly bonus: number; -} - -class CosXpUniqueTierScale extends PickType(CosXpTierScale, [ - 'linear', - 'staged' -] as const) {} -class CosXpRepeatTierScale extends CosXpTierScale {} -class CosXpUnique { - @NestedProperty(CosXpUniqueTierScale) - @IsDefined() - readonly tierScale: CosXpUniqueTierScale; -} -class CosXpRepeat { - @NestedProperty(CosXpRepeatTierScale) - @IsDefined() - readonly tierScale: CosXpRepeatTierScale; -} - -class CosXpCompletions { - @NestedProperty(CosXpUnique) - @IsDefined() - readonly unique: CosXpUnique; - - @NestedProperty(CosXpRepeat) - @IsDefined() - readonly repeat: CosXpRepeat; -} -class CosXpLevels { - @ApiProperty() - @IsNumber() - readonly maxLevels: number; - - @ApiProperty() - @IsNumber() - readonly startingValue: number; - - @ApiProperty() - @IsNumber() - readonly linearScaleBaseIncrease: number; - - @ApiProperty() - @IsNumber() - readonly linearScaleInterval: number; - - @ApiProperty() - @IsNumber() - readonly linearScaleIntervalMultiplier: number; - - @ApiProperty() - @IsNumber() - readonly staticScaleStart: number; - - @ApiProperty() - @IsNumber() - readonly staticScaleBaseMultiplier: number; - - @ApiProperty() - @IsNumber() - readonly staticScaleInterval: number; - - @ApiProperty() - @IsNumber() - readonly staticScaleIntervalMultiplier: number; -} - -class CosXpDto { - @NestedProperty(CosXpCompletions) - @IsDefined() - readonly completions: CosXpCompletions; - - @NestedProperty(CosXpLevels) - @IsDefined() - readonly levels: CosXpLevels; -} - -class RankXpFormula { - @ApiProperty() - @IsNumber() - readonly A: number; - - @ApiProperty() - @IsNumber() - readonly B: number; -} - -class RankXpGroups { - @ApiProperty() - @IsNumber() - readonly maxGroups: number; - - @ApiProperty({ type: Number, isArray: true, minLength: 4, maxLength: 4 }) - @IsNumber({}, { each: true }) - @IsArray() - readonly groupScaleFactors: number[]; - - @ApiProperty({ type: Number, isArray: true, minLength: 4, maxLength: 4 }) - @IsNumber({}, { each: true }) - @IsArray() - readonly groupExponents: number[]; - - @ApiProperty({ type: Number, isArray: true, minLength: 4, maxLength: 4 }) - @IsNumber({}, { each: true }) - @IsArray() - readonly groupMinSizes: number[]; - - @ApiProperty({ - type: Number, - isArray: true, - minLength: 4, - maxLength: 4 - }) - @IsNumber({}, { each: true }) - @IsArray() - readonly groupPointPcts: number[]; -} - -class RankXpTop10 { - @ApiProperty() - @IsNumber() - readonly WRPoints: number; - - @ApiProperty({ - type: Number, - isArray: true, - minLength: 10, - maxLength: 10 - }) - @IsNumber({}, { each: true }) - @IsArray() - readonly rankPercentages: number[]; -} - -class RankXpDto { - @NestedProperty(RankXpFormula) - @IsDefined() - readonly formula: RankXpFormula; - - @NestedProperty(RankXpGroups) - @IsDefined() - readonly groups: RankXpGroups; - - @NestedProperty(RankXpTop10) - @IsDefined() - readonly top10: RankXpTop10; -} - -export class XpSystemsDto { - @IsDefined() - @NestedProperty(RankXpDto) - @IsDefined() - readonly rankXP: RankXpDto; - - @IsDefined() - @NestedProperty(CosXpDto) - @IsDefined() - readonly cosXP: CosXpDto; -} - -export class UpdateXpSystemsDto extends PickType(XpSystemsDto, [ - 'cosXP', - 'rankXP' -] as const) {}