Skip to content

Commit 130f0d6

Browse files
committed
fix(lint): resolve ESLint errors in PR-changed files
- event.ts: move type imports to 'type' group (last), alphabetize parent group (slug.js before validations); wrap app.authenticate calls in arrow functions to satisfy unbound-method rule - event.test.ts: reorder external/type imports alphabetically; add required braces around single-statement if bodies - slug.ts: replace .substring() with .slice() per unicorn rule
1 parent 7ca786f commit 130f0d6

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

apps/backend/src/__tests__/event.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import Fastify from 'fastify';
12
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
2-
import Fastify, { FastifyInstance } from 'fastify';
3-
import { PrismaClient } from '@prisma/client';
3+
44
import { eventRoutes } from '../routes/event.js';
55

6+
import type { PrismaClient } from '@prisma/client';
7+
import type { FastifyInstance } from 'fastify';
8+
69
// ─── Shared mock data ────────────────────────────────────────────────────────
710

811
const MOCK_USER_ID = 'user-uuid-001';
@@ -320,7 +323,7 @@ describe('Events API', () => {
320323
let callCount = 0;
321324
prismaMock.event.create.mockImplementation(async (args: any) => {
322325
callCount++;
323-
if (callCount % 2 === 1) throw conflictError; // odd calls fail
326+
if (callCount % 2 === 1) { throw conflictError; } // odd calls fail
324327
return { ...MOCK_EVENT, slug: args.data.slug };
325328
});
326329

@@ -800,7 +803,7 @@ describe('Events API', () => {
800803
let callCount = 0;
801804
prismaMock.event.create.mockImplementation(async (args: any) => {
802805
callCount++;
803-
if (callCount === 1) throw conflictError;
806+
if (callCount === 1) { throw conflictError; }
804807
return { ...MOCK_EVENT, slug: args.data.slug };
805808
});
806809

apps/backend/src/routes/event.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
2-
import { createEventSchema } from '../validations/event.validation.js';
31
import { generateUniqueSlug } from '../utils/slug.js';
2+
import { createEventSchema } from '../validations/event.validation.js';
3+
4+
import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
45

56
const MAX_CREATE_ATTEMPTS = 5;
67

@@ -59,7 +60,7 @@ type EventWithAttendees = {
5960
export async function eventRoutes(app: FastifyInstance) {
6061
app.post(
6162
'/',
62-
{ preHandler: [app.authenticate] },
63+
{ preHandler: [(req, reply) => app.authenticate(req, reply)] },
6364
async (
6465
request: FastifyRequest<{
6566
Body: {
@@ -166,7 +167,7 @@ export async function eventRoutes(app: FastifyInstance) {
166167

167168
app.post(
168169
'/:slug/join',
169-
{ preHandler: [app.authenticate] },
170+
{ preHandler: [(req, reply) => app.authenticate(req, reply)] },
170171
async (request: FastifyRequest<{ Params: { slug: string } }>, reply: FastifyReply) => {
171172
const userId = (request.user as { id: string }).id;
172173
const paramsSlug = request.params.slug;
@@ -197,7 +198,7 @@ export async function eventRoutes(app: FastifyInstance) {
197198

198199
app.delete(
199200
'/:slug/leave',
200-
{ preHandler: [app.authenticate] },
201+
{ preHandler: [(req, reply) => app.authenticate(req, reply)] },
201202
async (request: FastifyRequest<{ Params: { slug: string } }>, reply: FastifyReply) => {
202203
const userId = (request.user as { id: string }).id;
203204
const paramsSlug = request.params.slug;

apps/backend/src/utils/slug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ export async function generateUniqueSlug(
3030
if (!(await slugExists(candidate))) {
3131
return candidate;
3232
}
33-
const suffix = Math.random().toString(36).substring(2, 6);
33+
const suffix = Math.random().toString(36).slice(2, 6);
3434
candidate = `${cleanSlug}-${suffix}`;
3535
}
3636

3737
// Last-ditch: append a longer random suffix to maximise the chance of a
3838
// unique value while keeping a deterministic upper bound on retries.
39-
const fallback = `${cleanSlug}-${Math.random().toString(36).substring(2, 10)}`;
39+
const fallback = `${cleanSlug}-${Math.random().toString(36).slice(2, 10)}`;
4040
if (!(await slugExists(fallback))) {
4141
return fallback;
4242
}

0 commit comments

Comments
 (0)