mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 11:29:02 +00:00
refactor: enhance folder sorting logic to use conditional ordering based on direction
This commit is contained in:
@@ -423,7 +423,10 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
),
|
),
|
||||||
db.ref("slug").withSchema(TableName.Environment).as("environment")
|
db.ref("slug").withSchema(TableName.Environment).as("environment")
|
||||||
)
|
)
|
||||||
.orderByRaw(`${TableName.SecretFolder}.?? COLLATE "en-x-icu" ${orderDirection}`, [orderBy]);
|
.orderByRaw(
|
||||||
|
`${TableName.SecretFolder}.?? COLLATE "en-x-icu" ${orderDirection === OrderByDirection.ASC ? "ASC" : "DESC"}`,
|
||||||
|
[orderBy]
|
||||||
|
);
|
||||||
|
|
||||||
if (limit) {
|
if (limit) {
|
||||||
const rankOffset = offset + 1; // ranks start from 1
|
const rankOffset = offset + 1; // ranks start from 1
|
||||||
@@ -433,7 +436,9 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
.from<Awaited<typeof query>[number]>("w")
|
.from<Awaited<typeof query>[number]>("w")
|
||||||
.where("w.rank", ">=", rankOffset)
|
.where("w.rank", ">=", rankOffset)
|
||||||
.andWhere("w.rank", "<", rankOffset + limit)
|
.andWhere("w.rank", "<", rankOffset + limit)
|
||||||
.orderByRaw(`"w".?? COLLATE "en-x-icu" ${orderDirection}`, [orderBy]);
|
.orderByRaw(`"w".?? COLLATE "en-x-icu" ${orderDirection === OrderByDirection.ASC ? "ASC" : "DESC"}`, [
|
||||||
|
orderBy
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const folders = await query;
|
const folders = await query;
|
||||||
@@ -482,7 +487,9 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
.select<(TSecretFolders & { path: string; depth: number; environment: string })[]>("*")
|
.select<(TSecretFolders & { path: string; depth: number; environment: string })[]>("*")
|
||||||
.from("parents")
|
.from("parents")
|
||||||
.orderBy("depth")
|
.orderBy("depth")
|
||||||
.orderByRaw(`"parents".?? COLLATE "en-x-icu" ${orderDirection}`, [orderBy]);
|
.orderByRaw(`"parents".?? COLLATE "en-x-icu" ${orderDirection === OrderByDirection.ASC ? "ASC" : "DESC"}`, [
|
||||||
|
orderBy
|
||||||
|
]);
|
||||||
|
|
||||||
return folders;
|
return folders;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user