Reformat code
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { TimeTrackerPredicate } from './timetracking.predicate';
|
||||
import { SeasonInfo, TimeTrackerStats, UserStatsResponse } from '../models/aliases';
|
||||
import {
|
||||
SeasonInfo,
|
||||
TimeTrackerStats,
|
||||
UserStatsResponse,
|
||||
} from '../models/aliases';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
@@ -16,8 +20,7 @@ export class DatabaseService {
|
||||
constructor(
|
||||
private readonly prismaClient: PrismaService,
|
||||
private readonly timetrackerPredicate: TimeTrackerPredicate,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public fetchSeasonInfos = async (seasonId: string): Promise<SeasonInfo> => {
|
||||
let seasons;
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
import { ranks, seasons, timetracker, user } from "@prisma/client";
|
||||
import { Predicate } from "src/api/predicate";
|
||||
import { Sort } from "src/api/sort";
|
||||
import { TimeUtil } from "src/api/timeutil";
|
||||
import { TableEntry } from "src/models/TableEntry";
|
||||
import { ranks, seasons, timetracker, user } from '@prisma/client';
|
||||
import { Predicate } from 'src/api/predicate';
|
||||
import { Sort } from 'src/api/sort';
|
||||
import { TimeUtil } from 'src/api/timeutil';
|
||||
import { TableEntry } from 'src/models/TableEntry';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
type UserStats = timetracker & { user: user, ranks: ranks; };
|
||||
type UserStats = timetracker & { user: user; ranks: ranks };
|
||||
|
||||
export class TimeTrackerPredicate implements Predicate<UserStats[], TableEntry[]> {
|
||||
|
||||
process(input: UserStats[]): TableEntry[] {
|
||||
return input.filter((userStats: UserStats) => userStats.time != null)
|
||||
.map((userStats: UserStats) => {
|
||||
return {
|
||||
name: userStats.user.name,
|
||||
rawTime: userStats.time,
|
||||
onlineTime: TimeUtil.humanize(userStats.time),
|
||||
rank: userStats.ranks.rank_name
|
||||
}
|
||||
})
|
||||
.sort((lhs, rhs) => Sort.descending(lhs.rawTime, rhs.rawTime));
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
export class TimeTrackerPredicate
|
||||
implements Predicate<UserStats[], TableEntry[]> {
|
||||
process(input: UserStats[]): TableEntry[] {
|
||||
return input
|
||||
.filter((userStats: UserStats) => userStats.time != null)
|
||||
.map((userStats: UserStats) => {
|
||||
return {
|
||||
name: userStats.user.name,
|
||||
rawTime: userStats.time,
|
||||
onlineTime: TimeUtil.humanize(userStats.time),
|
||||
rank: userStats.ranks.rank_name,
|
||||
};
|
||||
})
|
||||
.sort((lhs, rhs) => Sort.descending(lhs.rawTime, rhs.rawTime));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user