From d1db13ed6d55acc0ea73804698ecf3b88f51cd71 Mon Sep 17 00:00:00 2001 From: scffs Date: Tue, 12 Dec 2023 19:59:32 +0700 Subject: [PATCH] chore: lint --- apps/api/__tests__/i.test.ts | 2 +- apps/api/__tests__/services/auth/auth.test.ts | 84 ++++++++--------- apps/api/__tests__/services/user/user.test.ts | 70 +++++++------- .../__tests__/utils/handleErrors/i.test.ts | 78 ++++++++-------- .../__tests__/utils/hashPassword/i.test.ts | 10 +- apps/api/biome.json | 14 +-- apps/api/src/handlers/auth/authHandler.ts | 92 +++++++++---------- apps/api/src/handlers/user/userHandler.ts | 24 ++--- apps/api/src/index.ts | 2 +- apps/api/src/middlewares/auth.ts | 18 ++-- apps/api/src/routes/auth/authRoutes.ts | 16 ++-- apps/api/src/routes/auth/authSchema.ts | 6 +- apps/api/src/routes/user/userRoutes.ts | 10 +- apps/api/src/services/authService.ts | 20 ++-- apps/api/src/services/userService.ts | 28 +++--- apps/api/src/types/index.ts | 32 +++---- apps/api/src/utils/auth/comparePassword.ts | 10 +- apps/api/src/utils/auth/hashPassword.ts | 16 ++-- apps/api/src/utils/auth/pbkdf2Hash.ts | 20 ++-- apps/api/src/utils/getRandomNumber.ts | 8 +- apps/api/src/utils/getTestUser.ts | 10 +- apps/api/src/utils/handleErrors.ts | 44 ++++----- biome.json | 6 +- 23 files changed, 308 insertions(+), 312 deletions(-) diff --git a/apps/api/__tests__/i.test.ts b/apps/api/__tests__/i.test.ts index 293c5a4..f1a31d8 100644 --- a/apps/api/__tests__/i.test.ts +++ b/apps/api/__tests__/i.test.ts @@ -1,5 +1,5 @@ import { expect, test } from 'bun:test' test('2 + 2', () => { - expect(2 + 2).toBe(4) + expect(2 + 2).toBe(4) }) diff --git a/apps/api/__tests__/services/auth/auth.test.ts b/apps/api/__tests__/services/auth/auth.test.ts index bf65623..cb33e2b 100644 --- a/apps/api/__tests__/services/auth/auth.test.ts +++ b/apps/api/__tests__/services/auth/auth.test.ts @@ -6,46 +6,46 @@ import { getTestUser } from '@utils' const testDb = new PrismaClient() describe('authenticationService', () => { - afterAll(async () => { - await testDb.$disconnect() - }) - - beforeEach(async () => { - await testDb.user.deleteMany() - }) - - it('should fail authentication for a non-existent user', async () => { - const user = await isUserExist(1, 'nonexistent@example.com') - - expect(user).toBe(null) - }) - - it('should fail authentication for an invalid password', async () => { - const id = 1 - const testUser = await getTestUser(id) - await testDb.user.create({ - data: testUser - }) - - const result = await authenticateUser( - testUser, - testUser.email, - 'wrongpassword' - ) - expect(result).toBe(false) - }) - - it('should authenticate a user with valid credentials', async () => { - const id = 1 - const testUser = await getTestUser(id) - await testDb.user.create({ - data: testUser - }) - - /** - * В getTestUser пароль хешируется, но по задумке authenticateUser мы передаем туда пароль в чистом виде. - */ - const result = await authenticateUser(testUser, testUser.email, 'password') - expect(result).toBe(true) - }) + afterAll(async () => { + await testDb.$disconnect() + }) + + beforeEach(async () => { + await testDb.user.deleteMany() + }) + + it('should fail authentication for a non-existent user', async () => { + const user = await isUserExist(1, 'nonexistent@example.com') + + expect(user).toBe(null) + }) + + it('should fail authentication for an invalid password', async () => { + const id = 1 + const testUser = await getTestUser(id) + await testDb.user.create({ + data: testUser + }) + + const result = await authenticateUser( + testUser, + testUser.email, + 'wrongpassword' + ) + expect(result).toBe(false) + }) + + it('should authenticate a user with valid credentials', async () => { + const id = 1 + const testUser = await getTestUser(id) + await testDb.user.create({ + data: testUser + }) + + /** + * В getTestUser пароль хешируется, но по задумке authenticateUser мы передаем туда пароль в чистом виде. + */ + const result = await authenticateUser(testUser, testUser.email, 'password') + expect(result).toBe(true) + }) }) diff --git a/apps/api/__tests__/services/user/user.test.ts b/apps/api/__tests__/services/user/user.test.ts index 811199c..379802e 100644 --- a/apps/api/__tests__/services/user/user.test.ts +++ b/apps/api/__tests__/services/user/user.test.ts @@ -6,39 +6,39 @@ import { getRandomID, getTestUser } from '@utils' const testDb = new PrismaClient() describe('userService', () => { - afterAll(async () => { - await testDb.$disconnect() - }) - - beforeEach(async () => { - await testDb.user.deleteMany() - }) - - it('getAllUsers should return an array of users', async () => { - const firstID = getRandomID() - const secondID = getRandomID() - - await testDb.user.createMany({ - data: [await getTestUser(firstID), await getTestUser(secondID)], - skipDuplicates: true - }) - - const users = await getAllUsers() - expect(users).toHaveLength(2) - expect(users[0].name).toBe(`Test User ${firstID}`) - expect(users[1].name).toBe(`Test User ${secondID}`) - }) - - it('getUserById should return a user by ID', async () => { - const id = getRandomID() - const data = await getTestUser(id) - - await testDb.user.create({ - data - }) - - const user = await getUserById(id) - expect(user).not.toBeNull() - expect(user?.name).toBe(`Test User ${id}`) - }) + afterAll(async () => { + await testDb.$disconnect() + }) + + beforeEach(async () => { + await testDb.user.deleteMany() + }) + + it('getAllUsers should return an array of users', async () => { + const firstID = getRandomID() + const secondID = getRandomID() + + await testDb.user.createMany({ + data: [await getTestUser(firstID), await getTestUser(secondID)], + skipDuplicates: true + }) + + const users = await getAllUsers() + expect(users).toHaveLength(2) + expect(users[0].name).toBe(`Test User ${firstID}`) + expect(users[1].name).toBe(`Test User ${secondID}`) + }) + + it('getUserById should return a user by ID', async () => { + const id = getRandomID() + const data = await getTestUser(id) + + await testDb.user.create({ + data + }) + + const user = await getUserById(id) + expect(user).not.toBeNull() + expect(user?.name).toBe(`Test User ${id}`) + }) }) diff --git a/apps/api/__tests__/utils/handleErrors/i.test.ts b/apps/api/__tests__/utils/handleErrors/i.test.ts index 2f67f76..245abc1 100644 --- a/apps/api/__tests__/utils/handleErrors/i.test.ts +++ b/apps/api/__tests__/utils/handleErrors/i.test.ts @@ -3,43 +3,43 @@ import { describe, expect, it } from 'bun:test' import { handleErrors } from '@utils' describe('handleErrors', () => { - it('should handle VALIDATION error', () => { - const result = handleErrors({ - code: 'VALIDATION', - error: new Error('Validation failed') - }) - - expect(result.message).toBe('Validation error') - expect(result.error).toBeInstanceOf(Error) - }) - - it('should handle INTERNAL_SERVER_ERROR', () => { - const result = handleErrors({ - code: 'INTERNAL_SERVER_ERROR', - error: new Error('Server error') - }) - - expect(result.message).toBe('Internal Server Error') - expect(result.error).toBeInstanceOf(Error) - }) - - it('should handle NOT_FOUND error', () => { - const result = handleErrors({ - code: 'NOT_FOUND', - error: new Error('Resource not found') - }) - - expect(result.message).toBe('Not found') - expect(result.error).toBeInstanceOf(Error) - }) - - it('should handle unknown error', () => { - const result = handleErrors({ - code: 'UNKNOWN_ERROR', - error: new Error('Unknown error occurred') - }) - - expect(result.message).toBe('Unknown error') - expect(result.error).toBeInstanceOf(Error) - }) + it('should handle VALIDATION error', () => { + const result = handleErrors({ + code: 'VALIDATION', + error: new Error('Validation failed') + }) + + expect(result.message).toBe('Validation error') + expect(result.error).toBeInstanceOf(Error) + }) + + it('should handle INTERNAL_SERVER_ERROR', () => { + const result = handleErrors({ + code: 'INTERNAL_SERVER_ERROR', + error: new Error('Server error') + }) + + expect(result.message).toBe('Internal Server Error') + expect(result.error).toBeInstanceOf(Error) + }) + + it('should handle NOT_FOUND error', () => { + const result = handleErrors({ + code: 'NOT_FOUND', + error: new Error('Resource not found') + }) + + expect(result.message).toBe('Not found') + expect(result.error).toBeInstanceOf(Error) + }) + + it('should handle unknown error', () => { + const result = handleErrors({ + code: 'UNKNOWN_ERROR', + error: new Error('Unknown error occurred') + }) + + expect(result.message).toBe('Unknown error') + expect(result.error).toBeInstanceOf(Error) + }) }) diff --git a/apps/api/__tests__/utils/hashPassword/i.test.ts b/apps/api/__tests__/utils/hashPassword/i.test.ts index fd5f75a..8d5cd04 100644 --- a/apps/api/__tests__/utils/hashPassword/i.test.ts +++ b/apps/api/__tests__/utils/hashPassword/i.test.ts @@ -2,10 +2,10 @@ import { describe, expect, it } from 'bun:test' import { hashPassword, pbkdf2Hash } from '@utils' describe('hashPassword', () => { - it('should hash password with random salt', async () => { - const result = await hashPassword('password') - const expectedHash = await pbkdf2Hash('password', result.salt) + it('should hash password with random salt', async () => { + const result = await hashPassword('password') + const expectedHash = await pbkdf2Hash('password', result.salt) - expect(result.hash).toMatch(expectedHash) - }) + expect(result.hash).toMatch(expectedHash) + }) }) diff --git a/apps/api/biome.json b/apps/api/biome.json index 2d7e785..24b6c24 100644 --- a/apps/api/biome.json +++ b/apps/api/biome.json @@ -1,9 +1,9 @@ { - "formatter": { - "ignore": ["./dist"] - }, - "linter": { - "ignore": ["./dist"] - }, - "extends": ["../../biome.json"] + "formatter": { + "ignore": ["./dist"] + }, + "linter": { + "ignore": ["./dist"] + }, + "extends": ["../../biome.json"] } diff --git a/apps/api/src/handlers/auth/authHandler.ts b/apps/api/src/handlers/auth/authHandler.ts index 54fae23..42b263d 100644 --- a/apps/api/src/handlers/auth/authHandler.ts +++ b/apps/api/src/handlers/auth/authHandler.ts @@ -2,54 +2,54 @@ import { authenticateUser, isUserExist } from '@services' import { ApiResponse, ContextWith } from '@types' interface Body { - password: string - login: string - id: number + password: string + login: string + id: number } export const postAuth = async ({ - body, - jwt, - set + body, + jwt, + set }: ContextWith): Promise> => { - const { login, password, id } = body - - const user = await isUserExist(id, login) - - if (!user) { - set.status = 'Bad Request' - - return { - success: false, - data: 'Bad Request' - } - } - - const isAuth = await authenticateUser(user, login, password) - - if (!isAuth || !jwt) { - set.status = 'Bad Request' - - return { - success: false - } - } - - /** - * jwt.sign() будет возвращать одну и ту же куку в течении даты ее жизни - * - * Если хочется генерировать новую на каждую авторизацию (например), то можно использовать такой код - * - * setCookie('auth', await jwt.sign(body), { - * httpOnly: true, - * maxAge: 7 * 86400, - * }) - * - * @see https://elysiajs.com/plugins/jwt.html#jwt-plugin - */ - await jwt.sign(body) - - return { - success: true - } + const { login, password, id } = body + + const user = await isUserExist(id, login) + + if (!user) { + set.status = 'Bad Request' + + return { + success: false, + data: 'Bad Request' + } + } + + const isAuth = await authenticateUser(user, login, password) + + if (!isAuth || !jwt) { + set.status = 'Bad Request' + + return { + success: false + } + } + + /** + * jwt.sign() будет возвращать одну и ту же куку в течении даты ее жизни + * + * Если хочется генерировать новую на каждую авторизацию (например), то можно использовать такой код + * + * setCookie('auth', await jwt.sign(body), { + * httpOnly: true, + * maxAge: 7 * 86400, + * }) + * + * @see https://elysiajs.com/plugins/jwt.html#jwt-plugin + */ + await jwt.sign(body) + + return { + success: true + } } diff --git a/apps/api/src/handlers/user/userHandler.ts b/apps/api/src/handlers/user/userHandler.ts index 508302b..1a3c83d 100644 --- a/apps/api/src/handlers/user/userHandler.ts +++ b/apps/api/src/handlers/user/userHandler.ts @@ -5,22 +5,22 @@ import { User } from 'shared' type Params = { id: string } export const getAllUsersHandler = async (): Promise> => { - const users = await getAllUsers() + const users = await getAllUsers() - return { - success: true, - data: users - } + return { + success: true, + data: users + } } export const getUserByIdHandler = async ({ - params + params }: ContextWith): Promise> => { - const userId = parseInt(params.id, 10) - const user = await getUserById(userId) + const userId = parseInt(params.id, 10) + const user = await getUserById(userId) - return { - success: true, - data: user - } + return { + success: true, + data: user + } } diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 5443a1c..70e06b9 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -6,5 +6,5 @@ import users from './routes/user/userRoutes' const app = new Elysia().use(users).use(auth).listen(3000).onError(handleErrors) console.log( - `🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}` + `🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}` ) diff --git a/apps/api/src/middlewares/auth.ts b/apps/api/src/middlewares/auth.ts index 5861616..bddb0e7 100644 --- a/apps/api/src/middlewares/auth.ts +++ b/apps/api/src/middlewares/auth.ts @@ -13,15 +13,15 @@ import { ContextWith } from '@types' */ export const auth = async ({ set, jwt, cookie }: ContextWith) => { - if (!jwt || !cookie.auth) { - set.status = 'Internal Server Error' - return - } + if (!jwt || !cookie.auth) { + set.status = 'Internal Server Error' + return + } - const isCookieValid = await jwt.verify(cookie.auth) + const isCookieValid = await jwt.verify(cookie.auth) - if (!isCookieValid) { - set.status = 'Unauthorized' - return - } + if (!isCookieValid) { + set.status = 'Unauthorized' + return + } } diff --git a/apps/api/src/routes/auth/authRoutes.ts b/apps/api/src/routes/auth/authRoutes.ts index 038b8d5..81439ac 100644 --- a/apps/api/src/routes/auth/authRoutes.ts +++ b/apps/api/src/routes/auth/authRoutes.ts @@ -5,16 +5,16 @@ import Elysia, { t } from 'elysia' import { authBody } from './authSchema' const authConfig: JWTOption = { - name: 'jwt', - secret: Bun.env.JWT_SECRET ?? 'secret', - exp: '7d' + name: 'jwt', + secret: Bun.env.JWT_SECRET ?? 'secret', + exp: '7d' } const app = new Elysia() - .use(cookie()) - .use(jwt(authConfig)) - .post('/auth', postAuth, { - body: t.Object(authBody) - }) + .use(cookie()) + .use(jwt(authConfig)) + .post('/auth', postAuth, { + body: t.Object(authBody) + }) export default app diff --git a/apps/api/src/routes/auth/authSchema.ts b/apps/api/src/routes/auth/authSchema.ts index 5e289ae..794e011 100644 --- a/apps/api/src/routes/auth/authSchema.ts +++ b/apps/api/src/routes/auth/authSchema.ts @@ -1,7 +1,7 @@ import { t } from 'elysia' export const authBody = { - id: t.Number(), - password: t.String(), - login: t.String() + id: t.Number(), + password: t.String(), + login: t.String() } diff --git a/apps/api/src/routes/user/userRoutes.ts b/apps/api/src/routes/user/userRoutes.ts index b246d79..52456cf 100644 --- a/apps/api/src/routes/user/userRoutes.ts +++ b/apps/api/src/routes/user/userRoutes.ts @@ -4,10 +4,10 @@ import Elysia, { t } from 'elysia' import { userByIdParams } from './userSchema' const app = new Elysia() - .onBeforeHandle(auth) - .get('/user', getAllUsersHandler) - .get('/user/:id', getUserByIdHandler, { - params: t.Object(userByIdParams) - }) + .onBeforeHandle(auth) + .get('/user', getAllUsersHandler) + .get('/user/:id', getUserByIdHandler, { + params: t.Object(userByIdParams) + }) export default app diff --git a/apps/api/src/services/authService.ts b/apps/api/src/services/authService.ts index 90072d8..1970e8b 100644 --- a/apps/api/src/services/authService.ts +++ b/apps/api/src/services/authService.ts @@ -8,17 +8,17 @@ import { User } from 'shared' * @param password переданный пароль (email) юзером (не зашифрованный) */ export const authenticateUser = async ( - user: User, - login: string, - password: string + user: User, + login: string, + password: string ): Promise => { - const isValidPassword = await comparePassword( - password, - user.salt, - user.password - ) + const isValidPassword = await comparePassword( + password, + user.salt, + user.password + ) - const isValidLogin = login === user.email + const isValidLogin = login === user.email - return isValidPassword && isValidLogin + return isValidPassword && isValidLogin } diff --git a/apps/api/src/services/userService.ts b/apps/api/src/services/userService.ts index 6ba9491..5a32377 100644 --- a/apps/api/src/services/userService.ts +++ b/apps/api/src/services/userService.ts @@ -4,25 +4,25 @@ import { User } from 'shared' const db = new PrismaClient() export const getAllUsers = async (): Promise => { - return db.user.findMany() + return db.user.findMany() } export const getUserById = async (id: number): Promise => { - return db.user.findUnique({ - where: { - id - } - }) + return db.user.findUnique({ + where: { + id + } + }) } export const isUserExist = async ( - id: number, - email: string + id: number, + email: string ): Promise => { - return db.user.findUnique({ - where: { - id, - email - } - }) + return db.user.findUnique({ + where: { + id, + email + } + }) } diff --git a/apps/api/src/types/index.ts b/apps/api/src/types/index.ts index aa44050..d137fd3 100644 --- a/apps/api/src/types/index.ts +++ b/apps/api/src/types/index.ts @@ -6,8 +6,8 @@ import { Context as ElysiaContext } from 'elysia' * Standardizes the API response: a `success` flag and data with custom type T */ export interface ApiResponse { - success: boolean - data?: T + success: boolean + data?: T } /** @@ -15,18 +15,18 @@ export interface ApiResponse { * Extends the Elysia context with a strongly-typed `params` object */ export interface ContextWith - extends Omit { - params: T - body: U - /** - * @warning Необходимо для типизации методов jwt в хендлерах, т.к. Элизия их не передает - * @warning Necessary for typing jwt methods in handlers since Elysia doesn't pass them - * - * @see https://elysiajs.com/plugins/jwt.html#jwt-sign - * @see https://elysiajs.com/plugins/jwt.html#jwt-verify - */ - jwt?: { - sign: (payload: unknown) => Promise - verify: (payload: unknown) => Promise - } + extends Omit { + params: T + body: U + /** + * @warning Необходимо для типизации методов jwt в хендлерах, т.к. Элизия их не передает + * @warning Necessary for typing jwt methods in handlers since Elysia doesn't pass them + * + * @see https://elysiajs.com/plugins/jwt.html#jwt-sign + * @see https://elysiajs.com/plugins/jwt.html#jwt-verify + */ + jwt?: { + sign: (payload: unknown) => Promise + verify: (payload: unknown) => Promise + } } diff --git a/apps/api/src/utils/auth/comparePassword.ts b/apps/api/src/utils/auth/comparePassword.ts index 92ad7cb..8fb1bd8 100644 --- a/apps/api/src/utils/auth/comparePassword.ts +++ b/apps/api/src/utils/auth/comparePassword.ts @@ -8,10 +8,10 @@ import { pbkdf2Hash } from './pbkdf2Hash' * @returns Промис, который резолвится булевым значением, указывающим соответствие пароля хешу. */ export const comparePassword = async ( - password: string, - salt: string, - hash: string + password: string, + salt: string, + hash: string ): Promise => { - const derivedKey = await pbkdf2Hash(password, salt) - return hash === derivedKey + const derivedKey = await pbkdf2Hash(password, salt) + return hash === derivedKey } diff --git a/apps/api/src/utils/auth/hashPassword.ts b/apps/api/src/utils/auth/hashPassword.ts index 8bc667f..2fc536c 100644 --- a/apps/api/src/utils/auth/hashPassword.ts +++ b/apps/api/src/utils/auth/hashPassword.ts @@ -9,14 +9,14 @@ import { pbkdf2Hash } from './pbkdf2Hash' * @returns Промис, который ресолвится объектом с хешем и солью. */ export const hashPassword = async ( - password: string, - testSalt?: string + password: string, + testSalt?: string ): Promise<{ hash: string; salt: string }> => { - if (testSalt && POSTGRES_PASSWORD !== '12345678') { - throw new Error('The testSalt parameter can only be used in testing.') - } + if (testSalt && POSTGRES_PASSWORD !== '12345678') { + throw new Error('The testSalt parameter can only be used in testing.') + } - const salt = randomBytes(16).toString('hex') - const hash = await pbkdf2Hash(password, testSalt ? testSalt : salt) - return { hash, salt } + const salt = randomBytes(16).toString('hex') + const hash = await pbkdf2Hash(password, testSalt ? testSalt : salt) + return { hash, salt } } diff --git a/apps/api/src/utils/auth/pbkdf2Hash.ts b/apps/api/src/utils/auth/pbkdf2Hash.ts index 3a9b545..cf6e568 100644 --- a/apps/api/src/utils/auth/pbkdf2Hash.ts +++ b/apps/api/src/utils/auth/pbkdf2Hash.ts @@ -7,16 +7,16 @@ import { pbkdf2 } from 'crypto' * @returns Промис, который разрешается строкой с хешем. */ export const pbkdf2Hash = async ( - password: string, - salt: string + password: string, + salt: string ): Promise => { - return new Promise((resolve, reject) => { - pbkdf2(password, salt, 1000, 64, 'sha512', (error, derivedKey) => { - if (error) { - return reject(error) - } + return new Promise((resolve, reject) => { + pbkdf2(password, salt, 1000, 64, 'sha512', (error, derivedKey) => { + if (error) { + return reject(error) + } - return resolve(derivedKey.toString('hex')) - }) - }) + return resolve(derivedKey.toString('hex')) + }) + }) } diff --git a/apps/api/src/utils/getRandomNumber.ts b/apps/api/src/utils/getRandomNumber.ts index 84ac69b..332b573 100644 --- a/apps/api/src/utils/getRandomNumber.ts +++ b/apps/api/src/utils/getRandomNumber.ts @@ -1,7 +1,7 @@ export const getRandomID = () => { - const array = new Uint32Array(1) - crypto.getRandomValues(array) + const array = new Uint32Array(1) + crypto.getRandomValues(array) - const maxIntValue = 2147483647 - return array[0] % maxIntValue + const maxIntValue = 2147483647 + return array[0] % maxIntValue } diff --git a/apps/api/src/utils/getTestUser.ts b/apps/api/src/utils/getTestUser.ts index cc47b93..adf030c 100644 --- a/apps/api/src/utils/getTestUser.ts +++ b/apps/api/src/utils/getTestUser.ts @@ -1,9 +1,9 @@ import { hashPassword } from './auth/hashPassword' export const getTestUser = async (id: number) => ({ - id, - name: `Test User ${id}`, - email: `testUser${id}@example.com`, - password: await hashPassword('password', 'salt').then((r) => r.hash), - salt: 'salt' + id, + name: `Test User ${id}`, + email: `testUser${id}@example.com`, + password: await hashPassword('password', 'salt').then((r) => r.hash), + salt: 'salt' }) diff --git a/apps/api/src/utils/handleErrors.ts b/apps/api/src/utils/handleErrors.ts index ff6016d..7976d7b 100644 --- a/apps/api/src/utils/handleErrors.ts +++ b/apps/api/src/utils/handleErrors.ts @@ -5,26 +5,26 @@ import { ErrorHandler } from 'elysia' в зависимости от кода ошибки, включая описание message и объект ошибки error. */ export const handleErrors: ErrorHandler = ({ code, error }) => { - switch (code) { - case 'VALIDATION': - return { - message: 'Validation error', - error - } - case 'INTERNAL_SERVER_ERROR': - return { - message: 'Internal Server Error', - error - } - case 'NOT_FOUND': - return { - message: 'Not found', - error - } - default: - return { - message: 'Unknown error', - error - } - } + switch (code) { + case 'VALIDATION': + return { + message: 'Validation error', + error + } + case 'INTERNAL_SERVER_ERROR': + return { + message: 'Internal Server Error', + error + } + case 'NOT_FOUND': + return { + message: 'Not found', + error + } + default: + return { + message: 'Unknown error', + error + } + } } diff --git a/biome.json b/biome.json index 9317146..0610285 100644 --- a/biome.json +++ b/biome.json @@ -3,11 +3,7 @@ "formatter": { "indentStyle": "space", "indentWidth": 2, - "ignore": [ - "./apps/api/dist", - "./apps/web/dist", - "node_modules" - ] + "ignore": ["./apps/api/dist", "./apps/web/dist", "node_modules"] }, "javascript": { "formatter": {