From ac88b278eace0c907619ab024f4b3eb68a4aa331 Mon Sep 17 00:00:00 2001 From: Dustin Do Date: Sun, 9 Jun 2024 02:23:37 +0700 Subject: [PATCH] fix(api): chain hono apps to fix type infer (#47) --- apps/api/index.ts | 12 +- apps/api/v1/index.ts | 12 +- apps/api/v1/routes/auth.ts | 4 +- apps/api/v1/routes/budgets.ts | 367 ++++++++++++++--------------- apps/api/v1/routes/transactions.ts | 231 +++++++++--------- apps/api/v1/routes/users.ts | 34 +-- apps/api/v1/routes/wallets.ts | 128 +++++----- 7 files changed, 395 insertions(+), 393 deletions(-) diff --git a/apps/api/index.ts b/apps/api/index.ts index dd989a0d..e9c72ed6 100644 --- a/apps/api/index.ts +++ b/apps/api/index.ts @@ -7,13 +7,13 @@ import { hono as appV1 } from '@/v1' const app = new Hono({ strict: true }) -// * Global middlewares -app.use(trimTrailingSlash()) -app.use(prettyJSON({ space: 2 })) -app.use(logger()) + // * Global middlewares + .use(trimTrailingSlash()) + .use(prettyJSON({ space: 2 })) + .use(logger()) -// * Mounting versioned APIs -app.route('/api/v1', appV1) + // * Mounting versioned APIs + .route('/api/v1', appV1) export * from '@/v1/validation' export * from './prisma/generated/zod' diff --git a/apps/api/v1/index.ts b/apps/api/v1/index.ts index 9153d78b..293b81b7 100644 --- a/apps/api/v1/index.ts +++ b/apps/api/v1/index.ts @@ -8,10 +8,10 @@ import walletsApp from './routes/wallets' export const hono = new Hono() -hono.use('*', authMiddleware) + .use('*', authMiddleware) -hono.route('/auth', authApp) -hono.route('/budgets', budgetsApp) -hono.route('/users', usersApp) -hono.route('/transactions', transactionsApp) -hono.route('/wallets', walletsApp) + .route('/auth', authApp) + .route('/budgets', budgetsApp) + .route('/users', usersApp) + .route('/transactions', transactionsApp) + .route('/wallets', walletsApp) diff --git a/apps/api/v1/routes/auth.ts b/apps/api/v1/routes/auth.ts index a3f11ed8..eb338396 100644 --- a/apps/api/v1/routes/auth.ts +++ b/apps/api/v1/routes/auth.ts @@ -2,9 +2,7 @@ import { getAuth } from '@hono/clerk-auth' import { Hono } from 'hono' import { findUserById } from '../services/user.service' -const router = new Hono() - -router.get('/me', async (c) => { +const router = new Hono().get('/me', async (c) => { const auth = getAuth(c) if (!auth?.userId) { diff --git a/apps/api/v1/routes/budgets.ts b/apps/api/v1/routes/budgets.ts index 6d8dc2e8..2d9351d2 100644 --- a/apps/api/v1/routes/budgets.ts +++ b/apps/api/v1/routes/budgets.ts @@ -27,8 +27,6 @@ import { } from '../services/budget.service' import { zCreateBudget, zCreateUser, zUpdateBudget } from '../validation' -const router = new Hono() - const zBudgetParamValidator = zValidator( 'param', z.object({ @@ -44,56 +42,41 @@ const zInvitationParamValidator = zValidator( }), ) -router.get( - '/', - zValidator( - 'query', - z.object({ - permission: BudgetUserPermissionSchema.optional(), - }), - ), - async (c) => { - const user = getAuthUserStrict(c) - const { permission } = c.req.valid('query') - - const budgets = await findBudgetsOfUser({ user, permission }) - - return c.json(budgets) - }, -) - -router.post('/', zValidator('json', zCreateBudget), async (c) => { - const user = getAuthUserStrict(c) - - if (!(await canUserCreateBudget({ user }))) { - return c.json({ message: 'user cannot create budget' }, 403) - } - - const createBudgetData = c.req.valid('json') - - const budget = await createBudget({ user, data: createBudgetData }) +const router = new Hono() - return c.json(budget, 201) -}) + .get( + '/', + zValidator( + 'query', + z.object({ + permission: BudgetUserPermissionSchema.optional(), + }), + ), + async (c) => { + const user = getAuthUserStrict(c) + const { permission } = c.req.valid('query') + + const budgets = await findBudgetsOfUser({ user, permission }) + + return c.json(budgets) + }, + ) + + .post('/', zValidator('json', zCreateBudget), async (c) => { + const user = getAuthUserStrict(c) -router.get('/:budgetId', zBudgetParamValidator, async (c) => { - const user = getAuthUserStrict(c) - const { budgetId } = c.req.valid('param') + if (!(await canUserCreateBudget({ user }))) { + return c.json({ message: 'user cannot create budget' }, 403) + } - const budget = await findBudget({ budgetId }) + const createBudgetData = c.req.valid('json') - if (!(budget && (await canUserReadBudget({ user, budget })))) { - return c.json({ message: 'budget not found' }, 404) - } + const budget = await createBudget({ user, data: createBudgetData }) - return c.json(budget) -}) + return c.json(budget, 201) + }) -router.put( - '/:budgetId', - zBudgetParamValidator, - zValidator('json', zUpdateBudget), - async (c) => { + .get('/:budgetId', zBudgetParamValidator, async (c) => { const user = getAuthUserStrict(c) const { budgetId } = c.req.valid('param') @@ -103,45 +86,39 @@ router.put( return c.json({ message: 'budget not found' }, 404) } - if (!(await canUserUpdateBudget({ user, budget }))) { - return c.json({ message: 'user cannot update budget' }, 403) - } + return c.json(budget) + }) - const updateBudgetData = c.req.valid('json') + .put( + '/:budgetId', + zBudgetParamValidator, + zValidator('json', zUpdateBudget), + async (c) => { + const user = getAuthUserStrict(c) + const { budgetId } = c.req.valid('param') - const updatedBudget = await updateBudget({ - budgetId, - data: updateBudgetData, - }) + const budget = await findBudget({ budgetId }) - return c.json(updatedBudget) - }, -) + if (!(budget && (await canUserReadBudget({ user, budget })))) { + return c.json({ message: 'budget not found' }, 404) + } -router.delete('/:budgetId', zBudgetParamValidator, async (c) => { - const user = getAuthUserStrict(c) - const { budgetId } = c.req.valid('param') + if (!(await canUserUpdateBudget({ user, budget }))) { + return c.json({ message: 'user cannot update budget' }, 403) + } - const budget = await findBudget({ budgetId }) + const updateBudgetData = c.req.valid('json') - if (!(budget && (await canUserReadBudget({ user, budget })))) { - return c.json({ message: 'budget not found' }, 404) - } + const updatedBudget = await updateBudget({ + budgetId, + data: updateBudgetData, + }) - if (!(await canUserDeleteBudget({ user, budget }))) { - return c.json({ message: 'user cannot delete budget' }, 403) - } + return c.json(updatedBudget) + }, + ) - await deleteBudget({ budgetId }) - - return c.json(budget) -}) - -/** Generate sharable invitation link */ -router.post( - '/:budgetId/invitations/generate', - zBudgetParamValidator, - async (c) => { + .delete('/:budgetId', zBudgetParamValidator, async (c) => { const user = getAuthUserStrict(c) const { budgetId } = c.req.valid('param') @@ -151,34 +128,17 @@ router.post( return c.json({ message: 'budget not found' }, 404) } - if (!(await canUserGenerateBudgetInvitation({ user, budget }))) { - return c.json( - { message: 'user cannot generate invite link to budget' }, - 403, - ) + if (!(await canUserDeleteBudget({ user, budget }))) { + return c.json({ message: 'user cannot delete budget' }, 403) } - const invitation = await generateBudgetInvitation({ - budgetId, - userId: user.id, - }) + await deleteBudget({ budgetId }) - return c.json(invitation) - }, -) + return c.json(budget) + }) -/** Invite user to budget by email */ -router.post( - '/:budgetId/invitations', - zBudgetParamValidator, - zValidator( - 'json', - z.object({ - email: z.string().email(), - permission: BudgetUserPermissionSchema.optional(), - }), - ), - async (c) => { + /** Generate sharable invitation link */ + .post('/:budgetId/invitations/generate', zBudgetParamValidator, async (c) => { const user = getAuthUserStrict(c) const { budgetId } = c.req.valid('param') @@ -188,95 +148,134 @@ router.post( return c.json({ message: 'budget not found' }, 404) } - if (!(await canUserInviteUserToBudget({ user, budget }))) { - return c.json({ message: 'user cannot invite users to this budget' }, 403) + if (!(await canUserGenerateBudgetInvitation({ user, budget }))) { + return c.json( + { message: 'user cannot generate invite link to budget' }, + 403, + ) } - const { email, permission } = c.req.valid('json') - - const invitation = await inviteUserToBudget({ - inviter: user, - budget, - email, - permission, + const invitation = await generateBudgetInvitation({ + budgetId, + userId: user.id, }) - return c.json(invitation, 201) - }, -) - -/** Delete/revoke invitation */ -router.delete( - '/:budgetId/invitations/:invitationId', - zInvitationParamValidator, - async (c) => { - const user = getAuthUserStrict(c) - const { budgetId, invitationId } = c.req.valid('param') - - const budget = await findBudget({ budgetId }) - - if (!(budget && (await canUserReadBudget({ user, budget })))) { - return c.json({ message: 'budget not found' }, 404) - } - - const invitation = await findBudgetInvitation({ invitationId }) - - if (!invitation) { - return c.json({ message: 'invitation not found' }, 404) - } - - if (!(await canUserDeleteBudgetInvitation({ user, invitation }))) { - return c.json({ message: 'user cannot delete this invitation' }, 403) - } - - await deleteBudgetInvitation({ invitationId }) - return c.json(invitation) - }, -) - -/** Join budget with token */ -router.post( - '/response-invitation', - zValidator( - 'json', - z.object({ - token: z.string(), - userData: zCreateUser.optional(), - accept: z.boolean(), - }), - ), - async (c) => { - const user = getAuthUser(c) - const { token, userData, accept } = c.req.valid('json') - - if (!user && !userData) { - return c.json({ message: 'user data is required' }, 400) - } - - const invitation = await verifyBudgetInvitationToken({ token }) - - if (!invitation) { - return c.json( - { - message: 'invalid or expired invitation token', + }) + + /** Invite user to budget by email */ + .post( + '/:budgetId/invitations', + zBudgetParamValidator, + zValidator( + 'json', + z.object({ + email: z.string().email(), + permission: BudgetUserPermissionSchema.optional(), + }), + ), + async (c) => { + const user = getAuthUserStrict(c) + const { budgetId } = c.req.valid('param') + + const budget = await findBudget({ budgetId }) + + if (!(budget && (await canUserReadBudget({ user, budget })))) { + return c.json({ message: 'budget not found' }, 404) + } + + if (!(await canUserInviteUserToBudget({ user, budget }))) { + return c.json( + { message: 'user cannot invite users to this budget' }, + 403, + ) + } + + const { email, permission } = c.req.valid('json') + + const invitation = await inviteUserToBudget({ + inviter: user, + budget, + email, + permission, + }) + + return c.json(invitation, 201) + }, + ) + + /** Delete/revoke invitation */ + .delete( + '/:budgetId/invitations/:invitationId', + zInvitationParamValidator, + async (c) => { + const user = getAuthUserStrict(c) + const { budgetId, invitationId } = c.req.valid('param') + + const budget = await findBudget({ budgetId }) + + if (!(budget && (await canUserReadBudget({ user, budget })))) { + return c.json({ message: 'budget not found' }, 404) + } + + const invitation = await findBudgetInvitation({ invitationId }) + + if (!invitation) { + return c.json({ message: 'invitation not found' }, 404) + } + + if (!(await canUserDeleteBudgetInvitation({ user, invitation }))) { + return c.json({ message: 'user cannot delete this invitation' }, 403) + } + + await deleteBudgetInvitation({ invitationId }) + + return c.json(invitation) + }, + ) + + /** Join budget with token */ + .post( + '/response-invitation', + zValidator( + 'json', + z.object({ + token: z.string(), + userData: zCreateUser.optional(), + accept: z.boolean(), + }), + ), + async (c) => { + const user = getAuthUser(c) + const { token, userData, accept } = c.req.valid('json') + + if (!user && !userData) { + return c.json({ message: 'user data is required' }, 400) + } + + const invitation = await verifyBudgetInvitationToken({ token }) + + if (!invitation) { + return c.json( + { + message: 'invalid or expired invitation token', + }, + 404, + ) + } + + const response = await respondToBudgetInvitation({ + invitation, + accept, + userData: { + id: user?.id, + email: (invitation.email ?? user?.email ?? userData?.email)!, + name: (user?.name ?? userData?.name)!, }, - 404, - ) - } - - const response = await respondToBudgetInvitation({ - invitation, - accept, - userData: { - id: user?.id, - email: (invitation.email ?? user?.email ?? userData?.email)!, - name: (user?.name ?? userData?.name)!, - }, - }) + }) - return c.json(response) - }, -) + return c.json(response) + }, + ) export default router diff --git a/apps/api/v1/routes/transactions.ts b/apps/api/v1/routes/transactions.ts index 8a1956ac..729bb11b 100644 --- a/apps/api/v1/routes/transactions.ts +++ b/apps/api/v1/routes/transactions.ts @@ -21,136 +21,139 @@ import { const router = new Hono() -router.get( - '/', - zValidator( - 'query', - z.object({ - order_by: z.enum(['date']).optional(), - order: z.enum(['asc', 'desc']).optional(), - wallet_id: z.string().optional(), - budget_id: z.string().optional(), - from_date: z.string().optional(), - to_date: z.string().optional(), - take: z.number().optional(), - skip: z.number().optional(), - cursor: z.string().optional(), - }), - ), - async (c) => { - return c.json([]) - }, -) - -router.post('/', zValidator('json', zCreateTransaction), async (c) => { - const user = getAuthUserStrict(c) - const data = c.req.valid('json') - const { budgetId, walletAccountId: walletId } = data - - const budget = budgetId ? await findBudget({ budgetId }) : null - if (budgetId && (!budget || !(await canUserReadBudget({ user, budget })))) { - return c.json({ message: 'budget not found' }, 404) - } - - const wallet = await findUserWallet({ user, walletId }) - if (!wallet) { - return c.json({ message: 'wallet not found' }, 404) - } - - if ( - !(await canUserCreateTransaction({ user, budget, walletAccount: wallet })) - ) { - return c.json({ message: 'user cannot create transaction' }, 403) - } - - const transaction = await createTransaction({ - user, - data, - }) - - return c.json(transaction, 201) -}) - -router.put( - '/:transactionId', - zValidator( - 'param', - z.object({ - transactionId: z.string(), - }), - ), - zValidator('json', zUpdateTransaction), - async (c) => { - const { transactionId } = c.req.valid('param') + .get( + '/', + zValidator( + 'query', + z.object({ + order_by: z.enum(['date']).optional(), + order: z.enum(['asc', 'desc']).optional(), + wallet_id: z.string().optional(), + budget_id: z.string().optional(), + from_date: z.string().optional(), + to_date: z.string().optional(), + take: z.number().optional(), + skip: z.number().optional(), + cursor: z.string().optional(), + }), + ), + async (c) => { + return c.json([]) + }, + ) + + .post('/', zValidator('json', zCreateTransaction), async (c) => { const user = getAuthUserStrict(c) const data = c.req.valid('json') const { budgetId, walletAccountId: walletId } = data - const transaction = await findTransaction({ transactionId }) - - if ( - !(transaction && (await canUserReadTransaction({ user, transaction }))) - ) { - return c.json({ message: 'transaction not found' }, 404) + const budget = budgetId ? await findBudget({ budgetId }) : null + if (budgetId && (!budget || !(await canUserReadBudget({ user, budget })))) { + return c.json({ message: 'budget not found' }, 404) } - const wallet = walletId ? await findUserWallet({ user, walletId }) : null - if (walletId && !wallet) { + const wallet = await findUserWallet({ user, walletId }) + if (!wallet) { return c.json({ message: 'wallet not found' }, 404) } if ( - !(await canUserUpdateTransaction({ - user, - transaction, - walletAccount: wallet, - })) + !(await canUserCreateTransaction({ user, budget, walletAccount: wallet })) ) { - return c.json({ message: 'user cannot update transaction' }, 403) + return c.json({ message: 'user cannot create transaction' }, 403) } - const budget = budgetId ? await findBudget({ budgetId }) : null - if (budgetId && (!budget || !(await canUserReadBudget({ user, budget })))) { - return c.json({ message: 'budget not found' }, 404) - } - - const updatedTransaction = await updateTransaction({ - transactionId, + const transaction = await createTransaction({ + user, data, }) - return c.json(updatedTransaction) - }, -) - -router.delete( - '/:transactionId', - zValidator( - 'param', - z.object({ - transactionId: z.string(), - }), - ), - async (c) => { - const { transactionId } = c.req.valid('param') - const user = getAuthUserStrict(c) - - const transaction = await findTransaction({ transactionId }) - - if ( - !(transaction && (await canUserReadTransaction({ user, transaction }))) - ) { - return c.json({ message: 'transaction not found' }, 404) - } - - if (!(await canUserDeleteTransaction({ user, transaction }))) { - return c.json({ message: 'user cannot delete transaction' }, 403) - } - - await deleteTransaction({ transactionId }) + return c.json(transaction, 201) + }) - return c.json(transaction) - }, -) + .put( + '/:transactionId', + zValidator( + 'param', + z.object({ + transactionId: z.string(), + }), + ), + zValidator('json', zUpdateTransaction), + async (c) => { + const { transactionId } = c.req.valid('param') + const user = getAuthUserStrict(c) + const data = c.req.valid('json') + const { budgetId, walletAccountId: walletId } = data + + const transaction = await findTransaction({ transactionId }) + + if ( + !(transaction && (await canUserReadTransaction({ user, transaction }))) + ) { + return c.json({ message: 'transaction not found' }, 404) + } + + const wallet = walletId ? await findUserWallet({ user, walletId }) : null + if (walletId && !wallet) { + return c.json({ message: 'wallet not found' }, 404) + } + + if ( + !(await canUserUpdateTransaction({ + user, + transaction, + walletAccount: wallet, + })) + ) { + return c.json({ message: 'user cannot update transaction' }, 403) + } + + const budget = budgetId ? await findBudget({ budgetId }) : null + if ( + budgetId && + (!budget || !(await canUserReadBudget({ user, budget }))) + ) { + return c.json({ message: 'budget not found' }, 404) + } + + const updatedTransaction = await updateTransaction({ + transactionId, + data, + }) + + return c.json(updatedTransaction) + }, + ) + + .delete( + '/:transactionId', + zValidator( + 'param', + z.object({ + transactionId: z.string(), + }), + ), + async (c) => { + const { transactionId } = c.req.valid('param') + const user = getAuthUserStrict(c) + + const transaction = await findTransaction({ transactionId }) + + if ( + !(transaction && (await canUserReadTransaction({ user, transaction }))) + ) { + return c.json({ message: 'transaction not found' }, 404) + } + + if (!(await canUserDeleteTransaction({ user, transaction }))) { + return c.json({ message: 'user cannot delete transaction' }, 403) + } + + await deleteTransaction({ transactionId }) + + return c.json(transaction) + }, + ) export default router diff --git a/apps/api/v1/routes/users.ts b/apps/api/v1/routes/users.ts index b7f18ea0..78953f3d 100644 --- a/apps/api/v1/routes/users.ts +++ b/apps/api/v1/routes/users.ts @@ -4,24 +4,26 @@ import { getAuthUser } from '../middlewares/auth' import { createUser } from '../services/user.service' import { zCreateUser } from '../validation' -const router = new Hono() +const router = new Hono().post( + '/', + zValidator('json', zCreateUser), + async (c) => { + const existingUser = getAuthUser(c) -router.post('/', zValidator('json', zCreateUser), async (c) => { - const existingUser = getAuthUser(c) + if (existingUser) { + return c.json({ message: 'user already exists' }, 409) + } - if (existingUser) { - return c.json({ message: 'user already exists' }, 409) - } + const userId = c.get('userId')! + const data = c.req.valid('json') - const userId = c.get('userId')! - const data = c.req.valid('json') - - try { - const user = await createUser({ ...data, id: userId }) - return c.json(user, 201) - } catch (e) { - return c.json({ userId, message: 'failed to create user', cause: e }, 500) - } -}) + try { + const user = await createUser({ ...data, id: userId }) + return c.json(user, 201) + } catch (e) { + return c.json({ userId, message: 'failed to create user', cause: e }, 500) + } + }, +) export default router diff --git a/apps/api/v1/routes/wallets.ts b/apps/api/v1/routes/wallets.ts index 53ba7851..d71f5105 100644 --- a/apps/api/v1/routes/wallets.ts +++ b/apps/api/v1/routes/wallets.ts @@ -18,94 +18,94 @@ import { zCreateWallet, zUpdateWallet } from '../validation' const router = new Hono() -router.get('/wallets', async (c) => { - const user = getAuthUserStrict(c) + .get('/wallets', async (c) => { + const user = getAuthUserStrict(c) - const wallets = (await findUserWallets({ user })).map(walletWithBalance) + const wallets = (await findUserWallets({ user })).map(walletWithBalance) - return c.json(wallets, 200) -}) + return c.json(wallets, 200) + }) -router.post('/wallets', zValidator('json', zCreateWallet), async (c) => { - const user = getAuthUserStrict(c) + .post('/wallets', zValidator('json', zCreateWallet), async (c) => { + const user = getAuthUserStrict(c) - if (!(await canUserCreateWallet({ user }))) { - return c.json({ message: 'forbidden' }, 403) - } + if (!(await canUserCreateWallet({ user }))) { + return c.json({ message: 'forbidden' }, 403) + } - const data = c.req.valid('json') + const data = c.req.valid('json') - const wallet = await createWallet({ user, data }) + const wallet = await createWallet({ user, data }) - return c.json(walletWithBalance(wallet), 201) -}) + return c.json(walletWithBalance(wallet), 201) + }) -router.put( - '/wallets/:walletId', - zValidator('param', object({ walletId: string() })), - zValidator('json', zUpdateWallet), - async (c) => { - const user = getAuthUserStrict(c) - const { walletId } = c.req.valid('param') + .put( + '/wallets/:walletId', + zValidator('param', object({ walletId: string() })), + zValidator('json', zUpdateWallet), + async (c) => { + const user = getAuthUserStrict(c) + const { walletId } = c.req.valid('param') - const wallet = await findUserWallet({ user, walletId }) + const wallet = await findUserWallet({ user, walletId }) - if (!wallet) { - return c.json({ message: 'wallet not found' }, 404) - } + if (!wallet) { + return c.json({ message: 'wallet not found' }, 404) + } - if (!(await canUserUpdateWallet({ user, walletId }))) { - return c.json({ message: 'forbidden' }, 403) - } + if (!(await canUserUpdateWallet({ user, walletId }))) { + return c.json({ message: 'forbidden' }, 403) + } - const data = c.req.valid('json') + const data = c.req.valid('json') - const updatedWallet = await updateWallet({ walletId, data }) + const updatedWallet = await updateWallet({ walletId, data }) - return c.json(walletWithBalance(updatedWallet), 200) - }, -) + return c.json(walletWithBalance(updatedWallet), 200) + }, + ) -router.delete( - '/wallets/:walletId', - zValidator('param', object({ walletId: string() })), - async (c) => { - const user = getAuthUserStrict(c) - const { walletId } = c.req.valid('param') + .delete( + '/wallets/:walletId', + zValidator('param', object({ walletId: string() })), + async (c) => { + const user = getAuthUserStrict(c) + const { walletId } = c.req.valid('param') - const wallet = await findUserWallet({ user, walletId }) + const wallet = await findUserWallet({ user, walletId }) - if (!wallet) { - return c.json({ message: 'wallet not found' }, 404) - } + if (!wallet) { + return c.json({ message: 'wallet not found' }, 404) + } - if (!(await canUserDeleteWallet({ user, walletId }))) { - return c.json({ message: 'forbidden' }, 403) - } + if (!(await canUserDeleteWallet({ user, walletId }))) { + return c.json({ message: 'forbidden' }, 403) + } - await deleteWallet({ walletId }) + await deleteWallet({ walletId }) - return c.json(wallet, 200) - }, -) + return c.json(wallet, 200) + }, + ) -router.get( - '/wallets/:walletId/balance', - zValidator('param', object({ walletId: string() })), - async (c) => { - const user = getAuthUserStrict(c) - const { walletId } = c.req.valid('param') + .get( + '/wallets/:walletId/balance', + zValidator('param', object({ walletId: string() })), + async (c) => { + const user = getAuthUserStrict(c) + const { walletId } = c.req.valid('param') - const wallet = await findUserWallet({ user, walletId }) + const wallet = await findUserWallet({ user, walletId }) - if (!wallet) { - return c.json({ message: 'wallet not found' }, 404) - } + if (!wallet) { + return c.json({ message: 'wallet not found' }, 404) + } - const balance = await getWalletBalance({ wallet }) + const balance = await getWalletBalance({ wallet }) - return c.json({ wallet, balance }, 200) - }, -) + return c.json({ wallet, balance }, 200) + }, + ) export default router