-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add sync user subscriptions crob job (#359)
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"crons": [ | ||
{ | ||
"path": "/api/cron/users/sync-subscriptions", | ||
"schedule": "0 * * * *" | ||
} | ||
] | ||
} |