From 9345c103016d44bf92a910badc3f7b402a5a9458 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Tue, 13 Dec 2022 12:25:08 +0800 Subject: [PATCH] refactor(core): sort users data by `createdAt` (#2643) --- packages/core/src/queries/user.test.ts | 3 +++ packages/core/src/queries/user.ts | 1 + 2 files changed, 4 insertions(+) diff --git a/packages/core/src/queries/user.test.ts b/packages/core/src/queries/user.test.ts index 523c514ca..98db64fd1 100644 --- a/packages/core/src/queries/user.test.ts +++ b/packages/core/src/queries/user.test.ts @@ -307,6 +307,7 @@ describe('user query', () => { where ${fields.primaryEmail} ilike $1 or ${fields.primaryPhone} ilike $2 or ${ fields.username } ilike $3 or ${fields.name} ilike $4 + order by "created_at" desc limit $5 offset $6 `; @@ -339,6 +340,7 @@ describe('user query', () => { and (${fields.primaryEmail} ilike $2 or ${fields.primaryPhone} ilike $3 or ${ fields.username } ilike $4 or ${fields.name} ilike $5) + order by "created_at" desc limit $6 offset $7 `; @@ -371,6 +373,7 @@ describe('user query', () => { where ${fields.primaryEmail} like $1 or ${fields.primaryPhone} like $2 or ${ fields.username } like $3 or ${fields.name} like $4 + order by "created_at" desc limit $5 offset $6 `; diff --git a/packages/core/src/queries/user.ts b/packages/core/src/queries/user.ts index 3f099f56a..a53fb165b 100644 --- a/packages/core/src/queries/user.ts +++ b/packages/core/src/queries/user.ts @@ -145,6 +145,7 @@ export const findUsers = async ( select ${sql.join(Object.values(fields), sql`,`)} from ${table} ${buildUserConditions(search, hideAdminUser, isCaseSensitive)} + order by ${fields.createdAt} desc limit ${limit} offset ${offset} `