import { IOrder, IOrderCollection } from "@shared/contexts";

export class SequelizeParseOrder {
  static parseOrder(orderCollection: IOrderCollection): any {
    if (orderCollection.totalCount === 0) {
      return null;
    }

    return orderCollection.items.map((item: IOrder) => {
      if (!item.field) {
        return [];
      }

      const [model, field] = String(item.field).split(".");

      return [
        //field ? model : undefined,
        field ? field : model,
        item.type === "-" ? "DESC" : "ASC",
      ];
    });
  }
}

/*
// https://github.com/Hodor9898/sequelize-query-builder/blob/master/index.ts
*/
