-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathauth.signupCapacity.js
More file actions
15 lines (15 loc) · 916 Bytes
/
auth.signupCapacity.js
File metadata and controls
15 lines (15 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
* @desc Compute the public beta-capacity view for the auth config endpoint:
* the configured cap and how many seats remain. Skips the (collection-wide)
* count entirely when uncapped or when cap ≤ 0 (remaining is deterministically 0).
* @param {number|string|null|undefined} rawCap - config.sign.cap (null/undefined/non-numeric/blank = uncapped; 0 = fully closed, 0 seats)
* @param {() => Promise<number>} countFn - async total-account counter (UserService.count)
* @returns {Promise<{cap: number|null, remaining: number|null}>}
*/
export const computeSignupCapacity = async (rawCap, countFn) => {
const cap = rawCap != null && String(rawCap).trim() !== '' ? Number(rawCap) : null;
if (cap == null || !Number.isFinite(cap)) return { cap: null, remaining: null };
if (cap <= 0) return { cap, remaining: 0 };
const remaining = Math.max(0, cap - (await countFn()));
return { cap, remaining };
};