Skip to content

Commit

Permalink
Change Place filter 'maturity' to take a comma separated string
Browse files Browse the repository at this point in the history
    of maturity classes to match.
  • Loading branch information
Misterblue committed Nov 28, 2020
1 parent e95291d commit b360944
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Entities/EntityFilters/PlaceFilterInfo.ts
Expand Up @@ -27,7 +27,7 @@ import { Logger } from '@Tools/Logging';
// Process a request that wants to filter Account collection with parameters:
export class PlaceFilterInfo extends CriteriaFilter {

private _maturity: string;
private _maturity: string[];
private _tags: string[];

// Set to 'true' if the pagination was passed in the criteria query parameters
Expand All @@ -47,7 +47,11 @@ export class PlaceFilterInfo extends CriteriaFilter {
// Comma separated list of attribute criteria.
if (typeof(pRequest.query.maturity) === 'string') {
if (Maturity.KnownMaturity(pRequest.query.maturity)) {
this._maturity = pRequest.query.maturity;
this._maturity = pRequest.query.maturity.split(',');
if (this._maturity.includes(Maturity.UNRATED)) {
// Adding a 'null' to the set causes places with no rating to be included
this._maturity.push(null);
}
};
};

Expand Down Expand Up @@ -80,12 +84,12 @@ export class PlaceFilterInfo extends CriteriaFilter {
else {
if (this._maturity) {
if (pThingy.hasOwnProperty('maturity')) {
if ((pThingy as PlaceEntity).maturity === this._maturity) {
if (this._maturity.includes((pThingy as PlaceEntity).maturity)) {
ret = true;
};
}
else {
if (this._maturity === Maturity.UNRATED) {
if (this._maturity.includes(Maturity.UNRATED)) {
ret = true;
};
};
Expand All @@ -107,12 +111,7 @@ export class PlaceFilterInfo extends CriteriaFilter {
this._doingQuery = true;
const criteria:VKeyedCollection = {};
if (this._maturity) {
if (this._maturity === Maturity.UNRATED) {
criteria.maturity = { '$in': [ Maturity.UNRATED, null ]};
}
else {
criteria.maturity = this._maturity;
};
criteria.maturity = { '$in': this._maturity }
};
if (this._tags) {
criteria.tags = { '$in': this._tags }
Expand Down

0 comments on commit b360944

Please sign in to comment.