Skip to content

Commit

Permalink
feat: chaange jest setup
Browse files Browse the repository at this point in the history
  • Loading branch information
braianj committed Nov 19, 2024
1 parent 0533ea4 commit 7f5de1b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/entities/Place/routes/getPlaceBasePositionList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ApiResponse from "decentraland-gatsby/dist/entities/Route/wkc/response/ApiResponse"
import Router from "decentraland-gatsby/dist/entities/Route/wkc/routes/Router"

import PlacePositionModel from "../../PlacePosition/model"

export const getPlaceBasePositionList = Router.memo(async () => {
const [data, total] = await Promise.all([
PlacePositionModel.findAll(),
PlacePositionModel.count(),
])

return new ApiResponse(data, { total })
})
2 changes: 2 additions & 0 deletions src/entities/Place/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import routes from "decentraland-gatsby/dist/entities/Route/wkc/routes"
import env from "decentraland-gatsby/dist/utils/env"

import { getPlace } from "./getPlace"
import { getPlaceBasePositionList } from "./getPlaceBasePositionList"
import { getPlaceCategories } from "./getPlaceCategories"
import { getPlaceList } from "./getPlaceList"
import { updateRating } from "./updateRating"
Expand All @@ -26,6 +27,7 @@ export default routes((router) => {
],
})
)
router.get("/places/positions", getPlaceBasePositionList)
router.get("/places/:place_id", getPlace)
router.get("/places", getPlaceList)
router.put("/places/:place_id/rating", updateRating)
Expand Down
23 changes: 23 additions & 0 deletions src/entities/PlacePosition/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ export default class PlacePositionModel extends Model<PlacePositionAttributes> {
return this.namedQuery<string>("find_base_positions", query)
}

static async findAll(): Promise<PlacePositionAttributes[]> {
const query = SQL`
SELECT position, base_position
FROM ${table(this)}
`

return this.namedQuery<PlacePositionAttributes>("find_all_positions", query)
}

static async count(): Promise<number> {
const query = SQL`
SELECT count(position) as total
FROM ${table(this)}
`

const results = await this.namedQuery<{ total: string }>(
"find_all_positions",
query
)

return Number(results[0].total)
}

static async removePositions(positions: string[]): Promise<number> {
if (positions.length === 0) {
return 0
Expand Down

0 comments on commit 7f5de1b

Please sign in to comment.