{
  "version": 3,
  "sources": ["../../../src/matchmaker/driver/Query.ts"],
  "sourcesContent": ["import { QueryHelpers, SortOptions } from './interfaces';\n\nexport class Query<T> implements QueryHelpers<T> {\n  private $rooms: T[];\n  private conditions: any;\n\n  constructor(rooms: any[], conditions) {\n    this.$rooms = rooms.slice(0);\n    this.conditions = conditions;\n  }\n\n  public sort(options: SortOptions) {\n    this.$rooms = this.$rooms.sort((room1, room2) => {\n      for (const field in options) {\n        if (options.hasOwnProperty(field)) {\n          const direction = options[field];\n          const isAscending = (direction === 1 || direction === 'asc' || direction === 'ascending');\n\n          if (isAscending) {\n            if (room1[field] > room2[field]) { return 1; }\n            if (room1[field] < room2[field]) { return -1; }\n\n          } else {\n            if (room1[field] > room2[field]) { return -1; }\n            if (room1[field] < room2[field]) { return 1; }\n          }\n        }\n      }\n    });\n  }\n\n  public then(resolve, reject) {\n    const result: any = this.$rooms.find(((room) => {\n      for (const field in this.conditions) {\n        if (\n          this.conditions.hasOwnProperty(field) &&\n          room[field] !== this.conditions[field]\n        ) {\n          return false;\n        }\n      }\n      return true;\n    }));\n    return resolve(result);\n  }\n}\n"],
  "mappings": "AAEO,MAAM,MAAoC;AAAA,EAI/C,YAAY,OAAc,YAAY;AACpC,SAAK,SAAS,MAAM,MAAM,CAAC;AAC3B,SAAK,aAAa;AAAA,EACpB;AAAA,EAEO,KAAK,SAAsB;AAChC,SAAK,SAAS,KAAK,OAAO,KAAK,CAAC,OAAO,UAAU;AAC/C,iBAAW,SAAS,SAAS;AAC3B,YAAI,QAAQ,eAAe,KAAK,GAAG;AACjC,gBAAM,YAAY,QAAQ;AAC1B,gBAAM,cAAe,cAAc,KAAK,cAAc,SAAS,cAAc;AAE7E,cAAI,aAAa;AACf,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAG;AAC7C,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAI;AAAA,UAEhD,OAAO;AACL,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAI;AAC9C,gBAAI,MAAM,SAAS,MAAM,QAAQ;AAAE,qBAAO;AAAA,YAAG;AAAA,UAC/C;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,KAAK,SAAS,QAAQ;AAC3B,UAAM,SAAc,KAAK,OAAO,KAAM,CAAC,SAAS;AAC9C,iBAAW,SAAS,KAAK,YAAY;AACnC,YACE,KAAK,WAAW,eAAe,KAAK,KACpC,KAAK,WAAW,KAAK,WAAW,QAChC;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,CAAE;AACF,WAAO,QAAQ,MAAM;AAAA,EACvB;AACF;",
  "names": []
}
