Add Hatchet workflow stubs for order and referral jobs
This commit is contained in:
38
src/workflows/referral-balance-sync.js
Normal file
38
src/workflows/referral-balance-sync.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { hatchet } from '../hatchet-client.js';
|
||||
import { requestBackendGraphQL } from '../fregat-backend-client.js';
|
||||
|
||||
export const referralBalanceSync = hatchet.workflow({
|
||||
name: 'fregat-referral-balance-sync',
|
||||
});
|
||||
|
||||
referralBalanceSync.task({
|
||||
name: 'sync-referral-balance',
|
||||
fn: async (input) => {
|
||||
const userId = String(input.userId || '');
|
||||
if (!userId) {
|
||||
throw new Error('userId is required for referral sync');
|
||||
}
|
||||
|
||||
const data = await requestBackendGraphQL({
|
||||
userId,
|
||||
query: `
|
||||
query ReferralStats {
|
||||
referralStats {
|
||||
referrerId
|
||||
availableBalance
|
||||
referralsCount
|
||||
}
|
||||
}
|
||||
`,
|
||||
});
|
||||
|
||||
const stats = data.referralStats;
|
||||
console.log(`[fregat-referral-balance-sync] user=${stats.referrerId} balance=${stats.availableBalance} referrals=${stats.referralsCount}`);
|
||||
|
||||
return {
|
||||
referrerId: stats.referrerId,
|
||||
availableBalance: stats.availableBalance,
|
||||
referralsCount: stats.referralsCount,
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user