openpanel/packages/appwrite/src/utils/getAppwriteSorting.ts
Stefan Pejcic 09f9f9502d packages
2024-11-07 19:03:37 +01:00

22 lines
540 B
TypeScript

import type { CrudSorting } from "@refinedev/core";
import { Query } from "appwrite";
type GetAppwriteSortingType = (sorts?: CrudSorting) => string[];
export const getAppwriteSorting: GetAppwriteSortingType = (sorters) => {
const sorts: string[] = [];
if (sorters) {
sorters.map((item) => {
const field = item.field === "id" ? "$id" : item.field;
if (item.order === "asc") {
sorts.push(Query.orderAsc(field));
} else {
sorts.push(Query.orderDesc(field));
}
});
}
return sorts;
};