feat(api): sort db entries by createdAt date

This commit is contained in:
Lars Hampe 2024-11-09 21:31:30 +01:00
parent a73d99afcd
commit e98709d854
2 changed files with 4 additions and 2 deletions

View File

@ -1,7 +1,7 @@
import { changelog, db } from '@boring.tools/database'
import { AccessTokenListOutput } from '@boring.tools/schema'
import { createRoute } from '@hono/zod-openapi'
import { eq } from 'drizzle-orm'
import { desc, eq } from 'drizzle-orm'
import { HTTPException } from 'hono/http-exception'
import type { accessTokenApi } from '.'
@ -31,6 +31,7 @@ export const registerAccessTokenList = (api: typeof accessTokenApi) => {
const userId = await verifyAuthentication(c)
const result = await db.query.access_token.findMany({
where: eq(changelog.userId, userId),
orderBy: () => desc(changelog.createdAt),
})
if (!result) {

View File

@ -1,7 +1,7 @@
import { db, page } from '@boring.tools/database'
import { PageListOutput } from '@boring.tools/schema'
import { createRoute } from '@hono/zod-openapi'
import { and, eq } from 'drizzle-orm'
import { and, desc, eq } from 'drizzle-orm'
import { HTTPException } from 'hono/http-exception'
import { verifyAuthentication } from '../utils/authentication'
@ -33,6 +33,7 @@ export const registerPageList = (api: typeof pageApi) => {
const result = await db.query.page.findMany({
where: and(eq(page.userId, userId)),
orderBy: () => desc(page.createdAt),
})
if (!result) {