diff --git a/apps/service-auth/src/clans/clans.service.ts b/apps/service-auth/src/clans/clans.service.ts index 46ac0e4..9532928 100644 --- a/apps/service-auth/src/clans/clans.service.ts +++ b/apps/service-auth/src/clans/clans.service.ts @@ -241,10 +241,23 @@ export class ClansService { ); if (!body) throw new NotFoundException('Clan war league group not found'); - const members: Record = {}; + const membersMap: Record = {}; const wars = await this.clanWarsCollection - .find({ warTag: { $in: body.warTags[clanTag] } }) + .find( + { warTag: { $in: body.warTags[clanTag] } }, + { + projection: { + _id: 0, + id: 0, + uid: 0, + leagueGroupId: 0, + warType: 0, + updatedAt: 0, + season: 0, + }, + }, + ) .toArray(); for (const data of wars) { @@ -258,13 +271,13 @@ export class ClansService { const __attacks = clan.members.flatMap((m) => m.attacks ?? []); for (const m of clan.members) { - members[m.tag] ??= { + membersMap[m.tag] ??= { name: m.name, tag: m.tag, participated: 0, attacks: 0, stars: 0, - trueStars: 0, + newStars: 0, destruction: 0, threeStars: 0, twoStars: 0, @@ -276,14 +289,14 @@ export class ClansService { defenseCount: 0, }; - const member = members[m.tag]!; + const member = membersMap[m.tag]!; member.participated += 1; for (const atk of m.attacks ?? []) { const previousBestAttack = this.getPreviousBestAttack(__attacks, opponent, atk); member.attacks += 1; member.stars += atk.stars; - member.trueStars += previousBestAttack + member.newStars += previousBestAttack ? Math.max(0, atk.stars - previousBestAttack.stars) : atk.stars; member.destruction += atk.destructionPercentage; @@ -303,10 +316,16 @@ export class ClansService { } } + const members = Object.values(membersMap); + members.sort((a, b) => b.stars - a.stars); + return { season: body.season, clans: body.clans, - members: Object.values(members), + rounds: body.rounds, + warTags: body.warTags[clanTag] ?? [], + members, + wars, }; } diff --git a/apps/service-auth/src/clans/dto/cwl-stats.dto.ts b/apps/service-auth/src/clans/dto/cwl-stats.dto.ts index 89394cd..46c130f 100644 --- a/apps/service-auth/src/clans/dto/cwl-stats.dto.ts +++ b/apps/service-auth/src/clans/dto/cwl-stats.dto.ts @@ -1,3 +1,4 @@ +import { ClanWarsEntity } from '@app/entities'; import { ApiProperty } from '@nestjs/swagger'; export class CWLMemberStatsOutput { @@ -6,8 +7,8 @@ export class CWLMemberStatsOutput { participated: number; attacks: number; stars: number; + newStars: number; destruction: number; - trueStars: number; threeStars: number; twoStars: number; oneStar: number; @@ -32,4 +33,12 @@ export class CWLStatsOutput { @ApiProperty({ isArray: true, type: CWLMemberStatsOutput }) members: CWLMemberStatsOutput[]; + + warTags: string[]; + + @ApiProperty({ isArray: true }) + rounds: { warTags: string[] }[]; + + @ApiProperty({ isArray: true }) + wars: ClanWarsEntity[]; } diff --git a/apps/service-auth/src/clans/dto/index.ts b/apps/service-auth/src/clans/dto/index.ts index cb0ff5c..d12fa62 100644 --- a/apps/service-auth/src/clans/dto/index.ts +++ b/apps/service-auth/src/clans/dto/index.ts @@ -1 +1,2 @@ -export {}; +export * from './cwl-stats.dto'; +export * from './pagination.dto'; diff --git a/apps/service-auth/src/links/links.controller.ts b/apps/service-auth/src/links/links.controller.ts index 587adca..f15b043 100644 --- a/apps/service-auth/src/links/links.controller.ts +++ b/apps/service-auth/src/links/links.controller.ts @@ -33,7 +33,7 @@ export class LinksController { } @Post('/') - @Roles(Role.USER) + @Roles(Role.USER, Role.MANAGE_LINKS) @ApiOperation({ summary: '(Internal)' }) async createLink(@Body() body: CreateLinkInput) { return this.linksService.createLink(body); diff --git a/libs/auth/src/decorators/roles.decorator.ts b/libs/auth/src/decorators/roles.decorator.ts index 7d71da6..3bafb57 100644 --- a/libs/auth/src/decorators/roles.decorator.ts +++ b/libs/auth/src/decorators/roles.decorator.ts @@ -4,6 +4,7 @@ export enum Role { USER = 'user', ADMIN = 'admin', VIEWER = 'viewer', + MANAGE_LINKS = 'manage_links', } export const ROLES_KEY = 'roles'; diff --git a/package-lock.json b/package-lock.json index 33287d2..f37a4f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,7 @@ "mongodb": "^6.1.0", "morgan": "^1.10.0", "passport-jwt": "^4.0.1", + "radash": "^12.1.0", "redis": "^4.6.8", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1", @@ -7657,6 +7658,14 @@ } ] }, + "node_modules/radash": { + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/radash/-/radash-12.1.0.tgz", + "integrity": "sha512-b0Zcf09AhqKS83btmUeYBS8tFK7XL2e3RvLmZcm0sTdF1/UUlHSsjXdCcWNxe7yfmAlPve5ym0DmKGtTzP6kVQ==", + "engines": { + "node": ">=14.18.0" + } + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", diff --git a/package.json b/package.json index 7d5346e..2897347 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "mongodb": "^6.1.0", "morgan": "^1.10.0", "passport-jwt": "^4.0.1", + "radash": "^12.1.0", "redis": "^4.6.8", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1", diff --git a/scripts/make-index.ts b/scripts/make-index.ts index d5f233e..9b51574 100644 --- a/scripts/make-index.ts +++ b/scripts/make-index.ts @@ -32,6 +32,8 @@ const paths = [ 'apps/service-auth/src/clans/dto', 'apps/service-auth/src/links/dto', 'apps/service-auth/src/players/dto', + + 'apps/service-clans/src/dto', ]; (async () => {