mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-22 23:22:27 -04:00
Fix after when sorting with remmapped keys
This commit is contained in:
@@ -49,6 +49,9 @@ export const keysetPaginate = <
|
||||
};
|
||||
|
||||
export const generateAfter = (cursor: any, sort: Sort<any, any>) => {
|
||||
const ret = [...sort.map((by) => cursor[by.key]), cursor.pk];
|
||||
const ret = [
|
||||
...sort.map((by) => cursor[by.remmapedKey ?? by.key]),
|
||||
cursor.pk,
|
||||
];
|
||||
return Buffer.from(JSON.stringify(ret), "utf-8").toString("base64url");
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ export type Sort<
|
||||
Remap extends Partial<Record<T[number], string>>,
|
||||
> = {
|
||||
key: Exclude<T[number], keyof Remap> | NonNullable<Remap[keyof Remap]>;
|
||||
remmapedKey?: keyof Remap;
|
||||
desc: boolean;
|
||||
}[];
|
||||
|
||||
@@ -44,7 +45,7 @@ export const Sort = <
|
||||
return sort.map((x) => {
|
||||
const desc = x[0] === "-";
|
||||
const key = (desc ? x.substring(1) : x) as T[number];
|
||||
if (key in remap) return { key: remap[key]!, desc };
|
||||
if (key in remap) return { key: remap[key]!, remmapedKey: key, desc };
|
||||
return { key: key as Exclude<typeof key, keyof Remap>, desc };
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user