Skip to content

Commit

Permalink
Add a mandatory GET listings county query param
Browse files Browse the repository at this point in the history
  • Loading branch information
pbn4 committed Feb 2, 2021
1 parent bb514ab commit 9547714
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 0 additions & 1 deletion backend/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"express": "^4.17.1",
"handlebars": "^4.7.6",
"joi": "^17.3.0",
"jsonpath": "^1.0.2",
"nanoid": "^3.1.12",
"nestjs-typeorm-paginate": "^2.2.1",
"node-polyglot": "^2.4.0",
Expand Down
8 changes: 4 additions & 4 deletions backend/core/src/listings/listings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export class ListingsController {
@Get()
@ApiOperation({ summary: "List listings", operationId: "list" })
@ApiImplicitQuery({
name: "jsonpath",
required: false,
name: "county",
required: true,
type: String,
})
public async getAll(@Query("jsonpath") jsonpath?: string): Promise<ListingDto[]> {
return mapTo(ListingDto, await this.listingsService.list(jsonpath))
public async getAll(@Query("county") county?: string): Promise<ListingDto[]> {
return mapTo(ListingDto, await this.listingsService.list(county))
}

@Post()
Expand Down
9 changes: 3 additions & 6 deletions backend/core/src/listings/listings.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable } from "@nestjs/common"
import jp from "jsonpath"

import { Listing } from "./entities/listing.entity"
import { ListingCreateDto, ListingUpdateDto } from "./dto/listing.dto"
Expand Down Expand Up @@ -28,18 +27,16 @@ export class ListingsService {
.leftJoinAndSelect("amiChart.items", "amiChartItems")
}

public async list(jsonpath?: string): Promise<Listing[]> {
let listings = await this.getQueryBuilder()
public async list(county: string): Promise<Listing[]> {
const listings = await this.getQueryBuilder()
.orderBy({
"listings.id": "DESC",
"units.max_occupancy": "ASC",
"preferences.ordinal": "ASC",
})
.andWhere("buildingAddress.county = :county", { county })
.getMany()

if (jsonpath) {
listings = jp.query(listings, jsonpath)
}
return listings
}

Expand Down

0 comments on commit 9547714

Please sign in to comment.