Skip to content

Commit

Permalink
feat(api): add sync user subscriptions crob job (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev authored Sep 22, 2024
1 parent 4fa30e6 commit 7906ced
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/api/pages/api/cron/users/sync-subscriptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import { syncAllUsersSubscription } from '../../../../v1/services/user.service'

export const dynamic = 'force-dynamic' // static by default, unless reading the request

export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const authHeader = req.headers.authorization

if (
!process.env.CRON_SECRET ||
authHeader !== `Bearer ${process.env.CRON_SECRET}`
) {
return res.status(401).json({ success: false, message: 'unauthorized' })
}

res.status(200).json(await syncAllUsersSubscription())
}
8 changes: 8 additions & 0 deletions apps/api/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"crons": [
{
"path": "/api/cron/users/sync-subscriptions",
"schedule": "0 * * * *"
}
]
}

0 comments on commit 7906ced

Please sign in to comment.