Last active
June 30, 2021 10:40
-
-
Save blacksheep557/f25d06a7c63e8889bac63aec96155e40 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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