From c497eae178ec7398381092817b69662af5701796 Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Thu, 5 Jul 2018 11:44:13 +0200 Subject: [PATCH] Refactor OrderBuilder Feature #13703 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- src/common/api/order-builder.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/common/api/order-builder.ts b/src/common/api/order-builder.ts index 08d17b18e9..316379145e 100644 --- a/src/common/api/order-builder.ts +++ b/src/common/api/order-builder.ts @@ -15,23 +15,18 @@ export default class OrderBuilder { private order: string[] = [], private prefix = ""){} - private getRule (direction: string, attribute: keyof T) { + private addRule (direction: string, attribute: keyof T) { const prefix = this.prefix ? this.prefix + "." : ""; - return `${prefix}${_.snakeCase(attribute.toString())} ${direction}`; + const order = [...this.order, `${prefix}${_.snakeCase(attribute.toString())} ${direction}`]; + return new OrderBuilder(order, prefix); } addAsc(attribute: keyof T) { - return new OrderBuilder( - [...this.order, this.getRule("asc", attribute)], - this.prefix - ); + return this.addRule("asc", attribute); } addDesc(attribute: keyof T) { - return new OrderBuilder( - [...this.order, this.getRule("desc", attribute)], - this.prefix - ); + return this.addRule("desc", attribute); } concat(orderBuilder: OrderBuilder){ -- 2.30.2