Skip to content

Commit

Permalink
refactor: get referral stats
Browse files Browse the repository at this point in the history
  • Loading branch information
lui7henrique committed Oct 16, 2024
1 parent 00937e9 commit 27ddd37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
10 changes: 2 additions & 8 deletions src/app/functions/get-referral-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@ import { ReferralNotFound } from '../errors/referral-not-found'

type GetReferralInput = {
token: string
eventId: string
}

type TotalSubscriptions = {
click_count: string
subscription_count: string
}

export async function getReferralStats({ eventId, token }: GetReferralInput) {
export async function getReferralStats({ token }: GetReferralInput) {
try {
const [referral] = await db
.select()
.from(schema.referral)
.where(
and(
eq(schema.referral.token, token),
eq(schema.referral.eventId, eventId)
)
)
.where(eq(schema.referral.token, token))

if (!referral) {
return makeLeft(new ReferralNotFound())
Expand Down
5 changes: 2 additions & 3 deletions src/http/routes/get-referral-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { z } from 'zod'

const querySchema = z.object({
token: z.string().min(1, 'Token is required'),
eventId: z.string().min(1, 'Event ID is required'),
})

const successResponseSchema = z.object({
Expand Down Expand Up @@ -44,8 +43,8 @@ export async function getReferralStatsRoute(app: FastifyInstance) {
response: responseSchema,
},
handler: async (request, reply) => {
const { token, eventId } = querySchema.parse(request.query)
const result = await getReferralStats({ token, eventId })
const { token } = querySchema.parse(request.query)
const result = await getReferralStats({ token })

if (isLeft(result)) {
const error = result.left
Expand Down

0 comments on commit 27ddd37

Please sign in to comment.