Skip to content

Commit c3b7b13

Browse files
committed
hotfix: edit-ranking-order
1 parent a5d37bf commit c3b7b13

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

src/domain/couple/couple-ranking.service.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,41 @@ export class CoupleRankingService {
3030
'a',
3131
'a.cid = c.id',
3232
)
33+
/* ───────────── 기본 컬럼들 ───────────── */
3334
.addSelect('c.id', 'coupleId')
3435
.addSelect('c.name', 'name')
3536
.addSelect('c.profileImageUrl', 'profileImageUrl')
3637
.addSelect('c.cumulativeEcoLovePoints', 'cumulativeEcoLovePoints')
37-
.addSelect('COALESCE(a.ecoVerificationCount, 0)', 'ecoVerificationCount')
38-
// ecoScore = hearts + ecoVerificationCount * 10
38+
.addSelect('COALESCE(a.ecoVerificationCount,0)', 'ecoVerificationCount')
39+
/* ───────────── 평균 점수 ───────────── */
3940
.addSelect(
40-
'c.cumulativeEcoLovePoints + COALESCE(a.ecoVerificationCount, 0) * 10',
41+
`CASE
42+
WHEN COALESCE(a.ecoVerificationCount,0) = 0
43+
THEN 0
44+
ELSE c.cumulativeEcoLovePoints / a.ecoVerificationCount
45+
END`,
46+
'avgPoint',
47+
)
48+
/* ───────────── ecoScore = 누적♥ + 평균♥ ───────────── */
49+
.addSelect(
50+
`c.cumulativeEcoLovePoints
51+
+ CASE
52+
WHEN COALESCE(a.ecoVerificationCount,0) = 0
53+
THEN 0
54+
ELSE c.cumulativeEcoLovePoints / a.ecoVerificationCount
55+
END`,
4156
'ecoScore',
4257
);
4358

44-
if (IGNORE_COUPLE_IDS.length > 0) {
59+
if (IGNORE_COUPLE_IDS.length) {
4560
qb.andWhere('c.id NOT IN (:...excludeIds)', {
4661
excludeIds: IGNORE_COUPLE_IDS,
4762
});
4863
}
49-
qb.orderBy('cumulativeEcoLovePoints', 'DESC')
50-
.addOrderBy('ecoVerificationCount', 'DESC')
51-
.addOrderBy('c.id', 'ASC')
64+
65+
qb.orderBy('c.cumulativeEcoLovePoints', 'DESC')
66+
.addOrderBy('avgPoint', 'DESC')
67+
.addOrderBy('c.createdAt', 'ASC')
5268
.offset(offset)
5369
.limit(limit);
5470

0 commit comments

Comments
 (0)