(params: {
userId: string
now: Date
conn?: DbConn
})
| 83 | * Added optional `conn` param so callers inside a transaction can supply their TX object. |
| 84 | */ |
| 85 | export async function getOrderedActiveGrants(params: { |
| 86 | userId: string |
| 87 | now: Date |
| 88 | conn?: DbConn |
| 89 | }) { |
| 90 | const { userId, now, conn = db } = params |
| 91 | const activeGrantsFilter = buildActiveGrantsFilter(userId, now) |
| 92 | return conn |
| 93 | .select() |
| 94 | .from(schema.creditLedger) |
| 95 | .where(activeGrantsFilter) |
| 96 | .orderBy( |
| 97 | // Use grants based on priority, then expiration date, then creation date |
| 98 | asc(schema.creditLedger.priority), |
| 99 | asc(schema.creditLedger.expires_at), |
| 100 | asc(schema.creditLedger.created_at), |
| 101 | ) |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Gets active grants ordered for credit consumption, ensuring the "last grant" is always |
no test coverage detected