fix: multi().exec() قد يرجع null فلا يُفكَّك مباشرة (TS2488)

كسر بناء السيرفر. ioredis يعرّف exec() كـ [error, result][] | null،
فتفكيكه إلى [sumRes, countRes] خطأ نوع. صار يُقرأ بالفهرسة مع ??.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hamza-Ayed
2026-07-17 02:52:30 +03:00
co-authored by Claude Opus 4.8
parent 0ed3a3160a
commit 17c111a8f9
@@ -55,15 +55,16 @@ export class RatingAggregateService {
const k = this.key(tenantId, target, targetId); const k = this.key(tenantId, target, targetId);
await this.seed(tenantId, target, targetId, k); await this.seed(tenantId, target, targetId, k);
const [sumRes, countRes] = await this.redis // exec() قد يرجع null (انقطاع/إجهاض المعاملة) — لذلك لا نفكّكه مباشرة.
const res = await this.redis
.multi() .multi()
.hincrbyfloat(k, 'sum', stars) .hincrbyfloat(k, 'sum', stars)
.hincrby(k, 'count', 1) .hincrby(k, 'count', 1)
.expire(k, AGG_TTL_SEC) .expire(k, AGG_TTL_SEC)
.exec(); .exec();
const sum = Number(sumRes?.[1] ?? 0); const sum = Number(res?.[0]?.[1] ?? 0);
const count = Number(countRes?.[1] ?? 0); const count = Number(res?.[1]?.[1] ?? 0);
const avg = count > 0 ? sum / count : 0; const avg = count > 0 ? sum / count : 0;
return { avg, count, shouldFlush: await this.claimDailyFlush(k) }; return { avg, count, shouldFlush: await this.claimDailyFlush(k) };