Pull Request branch dev-clone to main #1

Merged
gitea merged 429 commits from dev-clone into main 2024-12-23 09:31:34 +00:00
Showing only changes of commit 4a679438be - Show all commits

View File

@ -80,9 +80,19 @@ const managementAspectRoute = new Hono<HonoEnv>()
async (c) => { async (c) => {
const { includeTrashed, page, limit, q } = c.req.valid("query"); const { includeTrashed, page, limit, q } = c.req.valid("query");
const totalCountQuery = includeTrashed const aspectCountQuery = await db
? sql<number>`(SELECT count(DISTINCT ${aspects.id}) FROM ${aspects})` .select({
: sql<number>`(SELECT count(DISTINCT ${aspects.id}) FROM ${aspects} WHERE ${aspects.deletedAt} IS NULL)`; count: sql<number>`count(*)`,
})
.from(aspects)
.where(
and(
includeTrashed ? undefined : isNull(aspects.deletedAt),
q ? or(ilike(aspects.name, q), eq(aspects.id, q)) : undefined
)
);
const totalItems = Number(aspectCountQuery[0]?.count) || 0;
const aspectIdsQuery = await db const aspectIdsQuery = await db
.select({ .select({
@ -129,7 +139,6 @@ const managementAspectRoute = new Hono<HonoEnv>()
FROM ${questions} FROM ${questions}
WHERE ${questions.subAspectId} = ${subAspects.id} WHERE ${questions.subAspectId} = ${subAspects.id}
)`.as('questionCount'), )`.as('questionCount'),
fullCount: totalCountQuery,
}) })
.from(aspects) .from(aspects)
.leftJoin(subAspects, eq(subAspects.aspectId, aspects.id)) .leftJoin(subAspects, eq(subAspects.aspectId, aspects.id))
@ -178,13 +187,13 @@ const managementAspectRoute = new Hono<HonoEnv>()
data: groupedArray, data: groupedArray,
_metadata: { _metadata: {
currentPage: page, currentPage: page,
totalPages: Math.ceil((Number(result[0]?.fullCount) ?? 0) / limit), totalPages: Math.ceil(totalItems / limit),
totalItems: Number(result[0]?.fullCount) ?? 0, totalItems,
perPage: limit, perPage: limit,
}, },
}); });
} }
) )
// Get aspect by id // Get aspect by id
.get( .get(