All files / realm/blong-gateway/adapter/db gatewayCreditAdjust.ts

100% Statements 29/29
66.66% Branches 2/3
100% Functions 1/1
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 301x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import {type IMeta, handler} from '@feasibleone/blong';
 
/**
 * Adjust an application's monthly credit balance mid-month.
 *
 * Wire: `gateway.credit.adjust` — thin wrapper over the Redis
 * `gateway.limit.adjust` (HINCRBY).  External management scripts may equally
 * run `HINCRBY {app:X}:credits:YYYY-MM balance <delta>` directly.
 */
export default handler(
    ({handler: {meterLimitAdjust}}) =>
        async function gatewayCreditAdjust(
            params: {
                applicationId: string;
                delta: number;
                month?: string;
            },
            $meta: IMeta,
        ): Promise<{balance: number}> {
            return meterLimitAdjust<{balance: number}>(
                {
                    applicationId: params.applicationId,
                    delta: params.delta,
                    ...(params.month && {month: params.month}),
                },
                $meta,
            );
        },
);