Monorepo skeleton, Prisma schema, core domain and services with tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
45d7512d2b
64 files changed
+9483
No files matched your search
@@ -0,0 +1,26 @@
|
||||
export interface PromoLike {
|
||||
kind: 'AGENCY_GIFT' | 'DISCOUNT';
|
||||
active: boolean;
|
||||
maxUses: number | null;
|
||||
usedCount: number;
|
||||
validFrom: Date | null;
|
||||
validUntil: Date | null;
|
||||
}
|
||||
|
||||
export type PromoCheck =
|
||||
| { ok: true }
|
||||
| { ok: false; reason: 'INACTIVE' | 'NOT_STARTED' | 'EXPIRED' | 'EXHAUSTED' | 'ALREADY_USED_BY_CLIENT' };
|
||||
|
||||
export function checkPromo(promo: PromoLike, now: Date, usedByClient: boolean): PromoCheck {
|
||||
if (!promo.active) return { ok: false, reason: 'INACTIVE' };
|
||||
if (promo.validFrom && now < promo.validFrom) return { ok: false, reason: 'NOT_STARTED' };
|
||||
if (promo.validUntil && now > promo.validUntil) return { ok: false, reason: 'EXPIRED' };
|
||||
if (promo.maxUses !== null && promo.usedCount >= promo.maxUses) return { ok: false, reason: 'EXHAUSTED' };
|
||||
if (usedByClient) return { ok: false, reason: 'ALREADY_USED_BY_CLIENT' };
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
/** Промокод-скидка не суммируется с Barev+: берётся большая из двух */
|
||||
export function combineDiscounts(barevPlusPct: number, promoPct: number | null): number {
|
||||
return Math.max(barevPlusPct, promoPct ?? 0);
|
||||
}
|
||||
Reference in new issue
Block a user