From 922d2394fd28ddb558ea0d706b242268bc109e3c Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 26 Mar 2024 02:09:28 +0100 Subject: [PATCH] Remove unnecessary withdrawl field --- api/resolvers/notifications.js | 5 +--- api/resolvers/wallet.js | 50 ++++++++++++++++------------------ api/typeDefs/notifications.js | 1 - components/notifications.js | 2 +- fragments/notifications.js | 4 --- 5 files changed, 26 insertions(+), 36 deletions(-) diff --git a/api/resolvers/notifications.js b/api/resolvers/notifications.js index 3d2e75c6..52c5f84b 100644 --- a/api/resolvers/notifications.js +++ b/api/resolvers/notifications.js @@ -1,7 +1,7 @@ import { GraphQLError } from 'graphql' import { decodeCursor, LIMIT, nextNoteCursorEncoded } from '@/lib/cursor' import { getItem, filterClause, whereClause, muteClause } from './item' -import { getInvoice, getWithdrawal } from './wallet' +import { getInvoice } from './wallet' import { pushSubscriptionSchema, ssValidate } from '@/lib/validate' import { replyToSubscription } from '@/lib/webPush' import { getSub } from './sub' @@ -443,9 +443,6 @@ export default { InvoicePaid: { invoice: async (n, args, { me, models }) => getInvoice(n, { id: n.id }, { me, models }) }, - WithdrawlPaid: { - withdrawl: async (n, args, { me, models }) => getWithdrawal(n, { id: n.id }, { me, models }) - }, Invitification: { invite: async (n, args, { models }) => { return await models.invite.findUnique({ diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index e2876d50..e10fe422 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -53,31 +53,6 @@ export async function getInvoice (parent, { id }, { me, models, lnd }) { return inv } -export async function getWithdrawal (parent, { id }, { me, models }) { - if (!me) { - throw new GraphQLError('you must be logged in', { extensions: { code: 'FORBIDDEN' } }) - } - - const wdrwl = await models.withdrawl.findUnique({ - where: { - id: Number(id) - }, - include: { - user: true - } - }) - - if (!wdrwl) { - throw new GraphQLError('withdrawal not found', { extensions: { code: 'BAD_INPUT' } }) - } - - if (wdrwl.user.id !== me.id) { - throw new GraphQLError('not ur withdrawal', { extensions: { code: 'FORBIDDEN' } }) - } - - return wdrwl -} - export function createHmac (hash) { const key = Buffer.from(process.env.INVOICE_HMAC_KEY, 'hex') return crypto.createHmac('sha256', key).update(Buffer.from(hash, 'hex')).digest('hex') @@ -122,7 +97,30 @@ export default { } }) }, - withdrawl: getWithdrawal, + withdrawl: async (parent, { id }, { me, models }) => { + if (!me) { + throw new GraphQLError('you must be logged in', { extensions: { code: 'FORBIDDEN' } }) + } + + const wdrwl = await models.withdrawl.findUnique({ + where: { + id: Number(id) + }, + include: { + user: true + } + }) + + if (!wdrwl) { + throw new GraphQLError('withdrawal not found', { extensions: { code: 'BAD_INPUT' } }) + } + + if (wdrwl.user.id !== me.id) { + throw new GraphQLError('not ur withdrawal', { extensions: { code: 'FORBIDDEN' } }) + } + + return wdrwl + }, numBolt11s: async (parent, args, { me, models, lnd }) => { if (!me) { throw new GraphQLError('you must be logged in', { extensions: { code: 'FORBIDDEN' } }) diff --git a/api/typeDefs/notifications.js b/api/typeDefs/notifications.js index 5f237767..12c58acc 100644 --- a/api/typeDefs/notifications.js +++ b/api/typeDefs/notifications.js @@ -94,7 +94,6 @@ export default gql` type WithdrawlPaid { id: ID! earnedSats: Int! - withdrawl: Withdrawl! sortTime: Date! } diff --git a/components/notifications.js b/components/notifications.js index 2a99661d..529d4bcf 100644 --- a/components/notifications.js +++ b/components/notifications.js @@ -96,7 +96,7 @@ const defaultOnClick = n => { if (type === 'SubStatus') return { href: `/~${n.sub.name}` } if (type === 'Invitification') return { href: '/invites' } if (type === 'InvoicePaid') return { href: `/invoices/${n.invoice.id}` } - if (type === 'WithdrawlPaid') return { href: `/withdrawals/${n.withdrawl.id}` } + if (type === 'WithdrawlPaid') return { href: `/withdrawals/${n.id}` } if (type === 'Referral') return { href: '/referrals/month' } if (type === 'Streak') return {} if (type === 'TerritoryTransfer') return { href: `/~${n.sub.name}` } diff --git a/fragments/notifications.js b/fragments/notifications.js index bc91ac42..38bb0bab 100644 --- a/fragments/notifications.js +++ b/fragments/notifications.js @@ -137,10 +137,6 @@ export const NOTIFICATIONS = gql` id sortTime earnedSats - withdrawl { - id - satsPaid - } } } }