1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as _ from "lodash";
6 import { Resource } from "src/models/resource";
8 export enum OrderDirection { ASC, DESC }
10 export class OrderBuilder<T extends Resource = Resource> {
12 constructor(private order: string[] = []) {}
14 addOrder(direction: OrderDirection, attribute: keyof T, prefix?: string) {
15 this.order.push(`${prefix ? prefix + "." : ""}${_.snakeCase(attribute.toString())} ${direction === OrderDirection.ASC ? "asc" : "desc"}`);
19 addAsc(attribute: keyof T, prefix?: string) {
20 return this.addOrder(OrderDirection.ASC, attribute, prefix);
23 addDesc(attribute: keyof T, prefix?: string) {
24 return this.addOrder(OrderDirection.DESC, attribute, prefix);
28 return this.order.join(",");