fix: apply quota point conversion
This commit is contained in:
1 parent
2553e482a9
commit
ad66ae5f10
12 files changed
+205
-25
No files matched your search
@@ -0,0 +1,19 @@
|
||||
export const QUOTA_PER_POINT = 5000;
|
||||
|
||||
export function pointsToQuota(points: unknown): number {
|
||||
const value = Number(points);
|
||||
if (!Number.isSafeInteger(value) || value < 0) {
|
||||
throw new Error("积分必须是非负安全整数");
|
||||
}
|
||||
const quota = value * QUOTA_PER_POINT;
|
||||
if (!Number.isSafeInteger(quota)) {
|
||||
throw new Error("积分换算后的 quota 超出安全整数范围");
|
||||
}
|
||||
return quota;
|
||||
}
|
||||
|
||||
export function quotaToPoints(quota: unknown): number {
|
||||
const value = Number(quota ?? 0);
|
||||
if (!Number.isFinite(value)) return 0;
|
||||
return Math.ceil(value / QUOTA_PER_POINT);
|
||||
}
|
||||
Reference in new issue
Block a user