Skip to content

Commit

Permalink
Fix DB error when filtering Places for openness.
Browse files Browse the repository at this point in the history
Modify /api/v1/places to only return Places that have an associated domain.
Modify /api/v1/places to not require logging in to get Places list.
  • Loading branch information
Misterblue committed Mar 22, 2021
1 parent e58ece2 commit 1201064
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
6 changes: 5 additions & 1 deletion docs/API-Places.md
Expand Up @@ -77,7 +77,11 @@ So, a legal request could be:
GET /api/v1/places?tag=friendly,kids,sandbox
```

(Note: as of February 2021, "order" and "status" queries are not yet implimented.)
(Note: as of March 2021, "status" queries are not yet implimented.)

(Note: as of March 2021, only visibility "OPEN" or unspecified visibility Places will be returned.)

This request does not require the requestor to be logged in to get the list of Places.

This request return JSON formatted as:

Expand Down
17 changes: 10 additions & 7 deletions src/Entities/EntityFilters/PlaceFilterInfo.ts
Expand Up @@ -14,7 +14,6 @@
'use strict'

import { Request } from 'express';
import { AccountEntity } from '@Entities/AccountEntity';
import { PlaceEntity } from '@Entities/PlaceEntity';

import { CriteriaFilter } from '@Entities/EntityFilters/CriteriaFilter';
Expand Down Expand Up @@ -180,17 +179,21 @@ export class PlaceFilterInfo extends CriteriaFilter {
this._doingQuery = true;
const criteria:VKeyedCollection = {};
if (this._maturity) {
criteria.maturity = { '$in': this._maturity }
/* tslint:disable-next-line */
criteria['maturity'] = { '$in': this._maturity }
};
if (this._tags) {
criteria.tags = { '$in': this._tags }
/* tslint:disable-next-line */
criteria['tags'] = { '$in': this._tags }
};
if (this._search) {
criteria.name = { '$regex': this._search, '$options': 'i' }
/* tslint:disable-next-line */
criteria['name'] = { '$regex': this._search, '$options': 'i' }
};
criteria.visibility = { "$or": [ { "visibility": { "$exists": false }},
{ "visibility": Visibility.OPEN },
] };
/* tslint:disable-next-line */
criteria['$or'] = [ { 'visibility': { '$exists': false }},
{ 'visibility': Visibility.OPEN },
];
return criteria;
};

Expand Down
15 changes: 9 additions & 6 deletions src/routes/api/v1/places.ts
Expand Up @@ -37,7 +37,7 @@ import { Logger } from '@Tools/Logging';
// Return places information
// The accounts returned depend on the scope (whether admin) and the search criteria (infoer)
const procGetPlaces: RequestHandler = async (req: Request, resp: Response, next: NextFunction) => {
if (req.vAuthAccount) {
// if (req.vAuthAccount) {
const pager = new PaginationInfo();
const placer = new PlaceFilterInfo();

Expand All @@ -47,7 +47,10 @@ const procGetPlaces: RequestHandler = async (req: Request, resp: Response, next:
// Loop through all the filtered accounts and create array of info
const places: any[] = [];
for await (const place of Places.enumerateAsync(pager, placer)) {
places.push(await buildPlaceInfo(place));
const aDomain = await Domains.getDomainWithId(place.domainId);
if (aDomain && IsNotNullOrEmpty(aDomain.networkAddr)) {
places.push(await buildPlaceInfo(place));
};
};

req.vRestResp.Data = {
Expand All @@ -57,10 +60,10 @@ const procGetPlaces: RequestHandler = async (req: Request, resp: Response, next:

placer.addResponseFields(req);
pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure(req.vAccountError ?? 'Not logged in');
};
// }
// else {
// req.vRestResp.respondFailure(req.vAccountError ?? 'Not logged in');
// };
next();
};

Expand Down

0 comments on commit 1201064

Please sign in to comment.