Skip to content

Commit 83e2e14

Browse files
committed
duckguessr,duckguessr-api: Apply lint
1 parent 6fa3391 commit 83e2e14

File tree

20 files changed

+211
-113
lines changed

20 files changed

+211
-113
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import js from "@eslint/js";
2+
import eslintConfigPrettier from "eslint-config-prettier";
3+
import eslintPluginPrettier from "eslint-plugin-prettier/recommended";
4+
import tseslint from "typescript-eslint";
5+
6+
export default tseslint.config(
7+
js.configs.recommended,
8+
...tseslint.configs.recommended,
9+
eslintConfigPrettier,
10+
eslintPluginPrettier,
11+
{
12+
ignores: ["**/node_modules", "**/dist", "prisma/client_*"],
13+
},
14+
{
15+
rules: {
16+
"@typescript-eslint/no-non-null-assertion": "off",
17+
"object-shorthand": ["error", "always"],
18+
19+
"@typescript-eslint/no-unused-vars": [
20+
"warn",
21+
{
22+
argsIgnorePattern: "^_",
23+
varsIgnorePattern: "^_",
24+
caughtErrorsIgnorePattern: "^_",
25+
},
26+
],
27+
},
28+
},
29+
);

apps/duckguessr/api/game.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { player } from "./prisma/client_duckguessr/browser";
33
export const numberOfRounds = 8;
44

55
export const getGameWithRoundsDatasetPlayers = (gameId: number) =>
6-
prisma.game.findUnique({
6+
prisma.game.findUnique({
77
include: {
88
rounds: {
99
include: {

apps/duckguessr/api/get-player.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ export const getPlayer = async (cookies?: {
1717
let player: player | null = null;
1818
if (cookies?.token) {
1919
try {
20-
const { id: ducksmanagerId, username } = (jwt.verify(
21-
cookies.token,
22-
process.env.TOKEN_SECRET as string,
23-
) as jwt.JwtPayload)?.data;
20+
const { id: ducksmanagerId, username } = (
21+
jwt.verify(
22+
cookies.token,
23+
process.env.TOKEN_SECRET as string,
24+
) as jwt.JwtPayload
25+
).data;
2426
if (!username) {
2527
throw new Error("No username provided");
2628
}

apps/duckguessr/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { server as maintenance } from "./services/maintenance";
1212
import { server as player } from "./services/player";
1313
import { server as match } from "./services/match";
1414

15-
(BigInt.prototype as any).toJSON = function () {
15+
(BigInt.prototype as unknown as { toJSON: () => number }).toJSON = function () {
1616
const int = Number.parseInt(this.toString());
1717
return int ?? this.toString();
1818
};
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { Socket } from "socket.io";
22
import { getPlayer } from "../get-player";
33

4-
export const RequiredPlayerMiddleware = ({ _socket }: { _socket: Socket }, next: (error?: Error) => void) => {
5-
getPlayer({ token: _socket.handshake.auth.token })
6-
.then((player) => {
7-
_socket.data.user = player;
8-
})
9-
.then(() => {
10-
next();
11-
})
12-
.catch((e) => {
13-
next(e);
14-
});
15-
};
4+
export const RequiredPlayerMiddleware = (
5+
{ _socket }: { _socket: Socket },
6+
next: (error?: Error) => void,
7+
) => {
8+
getPlayer({ token: _socket.handshake.auth.token })
9+
.then((player) => {
10+
_socket.data.user = player;
11+
})
12+
.then(() => {
13+
next();
14+
})
15+
.catch((e) => {
16+
next(e);
17+
});
18+
};

apps/duckguessr/api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"concurrently": "^8.2.2",
3939
"eslint": "^9.39.3",
4040
"eslint-config-prettier": "^10.1.8",
41+
"eslint-plugin-prettier": "^5.5.5",
4142
"prettier": "^3.8.1",
4243
"typescript": "^5.8.3",
4344
"typescript-eslint": "^8.56.1"

apps/duckguessr/api/pnpm-lock.yaml

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import 'dotenv/config'
2-
import type { PrismaConfig } from 'prisma/config'
1+
import "dotenv/config";
2+
import type { PrismaConfig } from "prisma/config";
33

4-
const databaseUrl = process.env.DATABASE_URL
4+
const databaseUrl = process.env.DATABASE_URL;
55
if (!databaseUrl) {
6-
throw new Error('DATABASE_URL is not set')
6+
throw new Error("DATABASE_URL is not set");
77
}
88

99
const prismaConfig: PrismaConfig = {
10-
schema: 'prisma/schema.prisma',
10+
schema: "prisma/schema.prisma",
1111
datasource: {
1212
url: databaseUrl,
1313
},
14-
}
14+
};
1515

16-
export default prismaConfig
16+
export default prismaConfig;

apps/duckguessr/api/services/datasets.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ export type DatasetsServices = NamespaceProxyTarget<
1414
>;
1515

1616
const listenEvents = () => ({
17-
getDatasets: async () => prisma.$queryRaw<{
18-
id: number;
19-
name: string;
20-
title: string;
21-
description: string;
22-
images: number;
23-
authors: number;
24-
}[]>`
17+
getDatasets: async () => prisma.$queryRaw<
18+
{
19+
id: number;
20+
name: string;
21+
title: string;
22+
description: string;
23+
images: number;
24+
authors: number;
25+
}[]
26+
>`
2527
SELECT dataset.id, name, title, description, COUNT(*) AS images, COUNT(DISTINCT personcode) AS authors
2628
FROM dataset
2729
LEFT JOIN dataset_entryurl de ON dataset.id = de.dataset_id
@@ -33,8 +35,8 @@ const listenEvents = () => ({
3335

3436
previewDataset: async ({
3537
personNationalityFilter,
36-
oldestDateFilterMin,
37-
oldestDateFilterMax,
38+
oldestDateFilterMin: _oldestDateFilterMin,
39+
oldestDateFilterMax: _oldestDateFilterMax,
3840
}: {
3941
personNationalityFilter: string[] | undefined;
4042
oldestDateFilterMin: number | undefined;

apps/duckguessr/api/services/game.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type GameServices = NamespaceProxyTarget<
4444

4545
export type ClientEmitEvents = NonNullable<
4646
Awaited<ReturnType<typeof createGameSocket>>
47-
>["client"]["emitEvents"];
47+
>["client"]["emitEvents"];
4848

4949
const checkAndAssociatePlayer = async (
5050
currentGame: CurrentGame,
@@ -178,7 +178,8 @@ const startRound = (socket: GameServices) => {
178178

179179
const finishRound = async (gameServices: GameServices) => {
180180
const { _socket, ...events } = gameServices;
181-
let { currentRound, currentGame } = _socket.data;
181+
let { currentRound } = _socket.data;
182+
const currentGame = _socket.data.currentGame;
182183
console.log(`Round ${currentRound.id} finished`);
183184
const missingScores = await getPlayersMissingRoundScore(
184185
_socket.data.currentRound,
@@ -203,8 +204,7 @@ const finishRound = async (gameServices: GameServices) => {
203204
} else {
204205
currentRound = await setRoundTimes(
205206
currentGame!.rounds.find(
206-
({ roundNumber }) =>
207-
roundNumber === currentRound.roundNumber! + 1,
207+
({ roundNumber }) => roundNumber === currentRound.roundNumber! + 1,
208208
)!,
209209
);
210210
const roundWithoutPersoncode: UnfinishedRound = {
@@ -350,7 +350,8 @@ const listenEvents = ({ _socket, ...events }: GameServices) => ({
350350
disconnect: async ({ _socket }: GameServices, reason: string) => {
351351
if (reason !== "client namespace disconnect") {
352352
if (
353-
_socket && _socket.data.currentGame.gamePlayers.findIndex(
353+
_socket &&
354+
_socket.data.currentGame.gamePlayers.findIndex(
354355
({ player }) => player.id === _socket.data.user.id,
355356
) > 0
356357
) {
@@ -363,7 +364,9 @@ const listenEvents = ({ _socket, ...events }: GameServices) => ({
363364
},
364365
});
365366

366-
const getPublicGame = async (game: Awaited<ReturnType<typeof getGameWithRoundsDatasetPlayers>>) => {
367+
const getPublicGame = async (
368+
game: Awaited<ReturnType<typeof getGameWithRoundsDatasetPlayers>>,
369+
) => {
367370
if (!game) {
368371
return null;
369372
}
@@ -408,29 +411,26 @@ export const createGameSocket = async (gameId: number) => {
408411

409412
console.log(`Creating game socket for game ${gameId}`);
410413

411-
const { server, client } = useSocketEvents<typeof listenEvents, ClientListenEvents>(
412-
namespaces.GAME.replace("{id}", gameId.toString()),
413-
{
414-
listenEvents,
415-
middlewares: [
416-
(
417-
{ _socket, sendGame: sendGameEvent },
418-
next: (error?: Error) => void,
419-
) => {
420-
getPlayer(_socket.handshake.auth).then(async (user) => {
421-
if (user) {
422-
_socket.data.user = user;
423-
_socket.data.currentGame = currentGame;
424-
sendGameEvent(await getPublicGame(currentGame));
425-
next()
426-
} else {
427-
next(new Error("User not found"));
428-
}
429-
});
430-
},
431-
],
432-
},
433-
)
414+
const { server, client } = useSocketEvents<
415+
typeof listenEvents,
416+
ClientListenEvents
417+
>(namespaces.GAME.replace("{id}", gameId.toString()), {
418+
listenEvents,
419+
middlewares: [
420+
({ _socket, sendGame: sendGameEvent }, next: (error?: Error) => void) => {
421+
getPlayer(_socket.handshake.auth).then(async (user) => {
422+
if (user) {
423+
_socket.data.user = user;
424+
_socket.data.currentGame = currentGame;
425+
sendGameEvent(await getPublicGame(currentGame));
426+
next();
427+
} else {
428+
next(new Error("User not found"));
429+
}
430+
});
431+
},
432+
],
433+
});
434434
server(io);
435435
return { client };
436436
};

0 commit comments

Comments
 (0)