{"size": 969, "ext": "js", "max_stars_repo_path": "src/mixins/ordering-mixin.js", "max_stars_repo_name": "amoshydra/postgrest-syntax-builder", "max_stars_repo_stars_event_min_datetime": "2018-12-02T17:48:12.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-17T13:36:01.000Z", "max_issues_repo_path": "src/mixins/ordering-mixin.js", "max_issues_repo_name": "amoshydra/postgrest-syntax-builder", "max_issues_repo_issues_event_min_datetime": "2018-11-02T02:06:30.000Z", "max_issues_repo_issues_event_max_datetime": "2019-02-01T04:17:58.000Z", "max_forks_repo_path": "src/mixins/ordering-mixin.js", "max_forks_repo_name": "amoshydra/postgrest-syntax-builder", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 26.1891891892, "max_line_length": 96, "alphanum_fraction": 0.5510835913}
import PostresqlSyntaxBuilder from '../postresql-syntax-builder';
import {
  joinParam,
  withCondition,
} from '../utilities';

export default {
  order: Object.assign(
    function(params) {
      switch (true) {
        case Array.isArray(params): {
          return new PostresqlSyntaxBuilder('order', withCondition(params, '', joinParam));
        }
        case (typeof params === 'object'): {
          const paramsPairs = Object.entries(params)
            .map(([key, {
              direction,
              nullsSort,
            }]) => [key, nullsSort, direction].filter(x => x).join('.'))
          ;

          return new PostresqlSyntaxBuilder('order', withCondition(paramsPairs, '', joinParam));
        }
        default: {
          return new PostresqlSyntaxBuilder('order', withCondition(params));
        }
      }
    },
    { // Additional Constants
      direction: {
        ascending: 'asc',
        descending: 'desc',
      },
    }
  ),
};
