Skip to content

Instantly share code, notes, and snippets.

@blacksheep557
Last active June 30, 2021 10:40
Show Gist options
  • Select an option

  • Save blacksheep557/f25d06a7c63e8889bac63aec96155e40 to your computer and use it in GitHub Desktop.

Select an option

Save blacksheep557/f25d06a7c63e8889bac63aec96155e40 to your computer and use it in GitHub Desktop.
async function createFreeTrialReimbursements(studentIds, courseId, userId) {
return Promise.all(studentIds.map(async (studentId) => {
const purchaseHistory = await courseApi.getPurchasesForAStudentInACourse(studentId, courseId);
// no purchases
if (purchaseHistory.length === 0)
return
// we already have a paid purchase
if (purchaseHistory.filter(p => p.price > 0).length !== 0)
return
// we dont have a paid purchase
if (purchaseHistory.filter(p => p.numHours === -1 && p.price === 0).length === 0 && purchaseHistory.filter(p => p.numHours === 1 && p.price === 0).length !== 0)
return courseApi.createPurchase({
pkgId: 'FREE_TRIAL_REIMBURSEMENT',
userId,
studentIds: [studentId],
price: 0,
numHours: -1
});
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment