apply limit to resulting array
All checks were successful
backend-action / build-image (push) Successful in 6m21s

This commit is contained in:
2024-06-24 00:23:42 +07:00
parent d660fd12fa
commit f6b18d3f82

View File

@@ -177,7 +177,7 @@ async function getAllUser(
}, },
}, },
}); });
const topThree = await db.query.user.findMany({ const topTen = await db.query.user.findMany({
with: { with: {
group: true, group: true,
opinions: { opinions: {
@@ -187,7 +187,7 @@ async function getAllUser(
with: { province: true }, with: { province: true },
}, },
}, },
limit: 3, limit: 10,
orderBy: user.rank, orderBy: user.rank,
where: (user, { eq, and }) => { where: (user, { eq, and }) => {
const conditions: SQL[] = []; const conditions: SQL[] = [];
@@ -247,17 +247,19 @@ async function getAllUser(
]; ];
} else { } else {
resultUser = [ resultUser = [
...topThree, ...topTen,
...users.filter((u) => topThree.filter((v) => v.id == u.id).length == 0), ...users.filter((u) => topTen.filter((v) => v.id == u.id).length == 0),
]; ];
} }
return resultUser.map((u) => ({ return resultUser
.map((u) => ({
...u, ...u,
phone: hidePhone(u.phone), phone: hidePhone(u.phone),
verified: true, verified: true,
image: u.image ? `${Config.minioPublicBucketEndpoint}${u.image}` : null, image: u.image ? `${Config.minioPublicBucketEndpoint}${u.image}` : null,
})); }))
.slice(0, limit);
} }
async function getUser(userId: number, showPhone: boolean) { async function getUser(userId: number, showPhone: boolean) {