Validate sorting options.

Test a pagination API supporting sorting options.

You can validate detailed sorting options both asceding and descending orders with multiple fields. However, as it forms a complicate currying function, I recomend you to see below example code before using.

https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
  • Parameters

    • title: string

      Title of error message when sorting is invalid

    Returns <
        T extends object,
        Fields extends string,
        Sortable extends
            (`-${Fields}` | `+${Fields}`)[] = (`-${Fields}` | `+${Fields}`)[],
    >(
        getter: (sortable: Sortable) => Promise<T[]>,
    ) => (
        ...fields: Fields[],
    ) => (
        comp: (x: T, y: T) => number,
        filter?: (elem: T) => boolean,
    ) => (direction: "+" | "-", trace?: boolean) => Promise<void>

      • <
            T extends object,
            Fields extends string,
            Sortable extends
                (`-${Fields}` | `+${Fields}`)[] = (`-${Fields}` | `+${Fields}`)[],
        >(
            getter: (sortable: Sortable) => Promise<T[]>,
        ): (
            ...fields: Fields[],
        ) => (
            comp: (x: T, y: T) => number,
            filter?: (elem: T) => boolean,
        ) => (direction: "+" | "-", trace?: boolean) => Promise<void>
      • Type Parameters

        Parameters

        • getter: (sortable: Sortable) => Promise<T[]>

          A pagination API function to be called

        Returns (
            ...fields: Fields[],
        ) => (
            comp: (x: T, y: T) => number,
            filter?: (elem: T) => boolean,
        ) => (direction: "+" | "-", trace?: boolean) => Promise<void>

          • (
                ...fields: Fields[],
            ): (
                comp: (x: T, y: T) => number,
                filter?: (elem: T) => boolean,
            ) => (direction: "+" | "-", trace?: boolean) => Promise<void>
          • Parameters

            • ...fields: Fields[]

              List of fields to be sorted

            Returns (
                comp: (x: T, y: T) => number,
                filter?: (elem: T) => boolean,
            ) => (direction: "+" | "-", trace?: boolean) => Promise<void>

              • (
                    comp: (x: T, y: T) => number,
                    filter?: (elem: T) => boolean,
                ): (direction: "+" | "-", trace?: boolean) => Promise<void>
              • Parameters

                • comp: (x: T, y: T) => number

                  Comparator function for validation

                • Optionalfilter: (elem: T) => boolean

                  Filter function for data if required

                Returns (direction: "+" | "-", trace?: boolean) => Promise<void>

                  • (direction: "+" | "-", trace?: boolean): Promise<void>
                  • Parameters

                    • direction: "+" | "-"

                      "+" means ascending order, and "-" means descending order

                    • trace: boolean = false

                    Returns Promise<void>