diff --git a/backend/src/modules/ratings/rating-aggregate.service.ts b/backend/src/modules/ratings/rating-aggregate.service.ts index a4a41d9..48e49d1 100644 --- a/backend/src/modules/ratings/rating-aggregate.service.ts +++ b/backend/src/modules/ratings/rating-aggregate.service.ts @@ -55,15 +55,16 @@ export class RatingAggregateService { const k = this.key(tenantId, target, targetId); await this.seed(tenantId, target, targetId, k); - const [sumRes, countRes] = await this.redis + // exec() قد يرجع null (انقطاع/إجهاض المعاملة) — لذلك لا نفكّكه مباشرة. + const res = await this.redis .multi() .hincrbyfloat(k, 'sum', stars) .hincrby(k, 'count', 1) .expire(k, AGG_TTL_SEC) .exec(); - const sum = Number(sumRes?.[1] ?? 0); - const count = Number(countRes?.[1] ?? 0); + const sum = Number(res?.[0]?.[1] ?? 0); + const count = Number(res?.[1]?.[1] ?? 0); const avg = count > 0 ? sum / count : 0; return { avg, count, shouldFlush: await this.claimDailyFlush(k) };