From c4434c43cfd167ae0895b16e49cf64c87e2500d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20D=C3=ADaz?= <git@subsme.slmail.me> Date: Mon, 4 Nov 2024 10:48:03 -0300 Subject: [PATCH] Revert "feat: Add a new order_by option created_at (#555)" (#556) This reverts commit 09b14e559857c59becd9863923075f277ca338d4. --- src/entities/Place/model.test.ts | 12 ++++++------ src/entities/Place/model.ts | 4 ++-- src/entities/Place/routes/getPlaceList.ts | 1 - src/entities/Place/schemas.ts | 6 +----- src/entities/Place/types.ts | 1 - src/entities/World/routes/getWorldList.ts | 7 +------ src/entities/World/schemas.ts | 6 +----- src/entities/World/types.ts | 1 - 8 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/entities/Place/model.test.ts b/src/entities/Place/model.test.ts index 887fed05..e463e0ad 100644 --- a/src/entities/Place/model.test.ts +++ b/src/entities/Place/model.test.ts @@ -174,7 +174,7 @@ describe(`findWithAggregates`, () => { AND p.base_position IN ( SELECT DISTINCT(base_position) FROM "place_positions" WHERE position IN ($1) ) - ORDER BY p.created_at DESC NULLS LAST, p."deployed_at" DESC + ORDER BY p.like_score DESC NULLS LAST, p."deployed_at" DESC LIMIT $2 OFFSET $3 ` @@ -218,7 +218,7 @@ describe(`findWithAggregates`, () => { WHERE p."disabled" is false AND "world" is false AND p.base_position IN ( SELECT DISTINCT(base_position) FROM "place_positions" WHERE position IN ($3) ) - ORDER BY p.created_at DESC NULLS LAST, p."deployed_at" DESC + ORDER BY p.like_score DESC NULLS LAST, p."deployed_at" DESC LIMIT $4 OFFSET $5 ` @@ -265,7 +265,7 @@ describe(`findWithAggregates`, () => { SELECT DISTINCT(base_position) FROM "place_positions" WHERE position IN ($4) ) ORDER BY rank DESC, - p.created_at DESC NULLS LAST, p."deployed_at" DESC + p.like_score DESC NULLS LAST, p."deployed_at" DESC LIMIT $5 OFFSET $6 ` @@ -504,7 +504,7 @@ describe(`findWithHotScenes`, () => { AND p.base_position IN ( SELECT DISTINCT(base_position) FROM "place_positions" WHERE position IN ($1) ) - ORDER BY p.created_at DESC NULLS LAST, p."deployed_at" DESC + ORDER BY p.like_score DESC NULLS LAST, p."deployed_at" DESC LIMIT $2 OFFSET $3 ` @@ -606,7 +606,7 @@ describe(`findWorld`, () => { p.disabled is false AND world is true AND world_name IN ($1) - ORDER BY p.created_at DESC NULLS LAST, p."deployed_at" DESC + ORDER BY p.like_score DESC NULLS LAST, p."deployed_at" DESC LIMIT $2 OFFSET $3 ` @@ -652,7 +652,7 @@ describe(`findWorld`, () => { AND world is true AND world_name IN ($4) AND rank > 0 - ORDER BY rank DESC, p.created_at DESC NULLS LAST, p."deployed_at" DESC + ORDER BY rank DESC, p.like_score DESC NULLS LAST, p."deployed_at" DESC LIMIT $5 OFFSET $6 ` diff --git a/src/entities/Place/model.ts b/src/entities/Place/model.ts index 41b6b330..4f9fdc58 100644 --- a/src/entities/Place/model.ts +++ b/src/entities/Place/model.ts @@ -142,7 +142,7 @@ export default class PlaceModel extends Model<PlaceAttributes> { return [] } - const orderBy = options.order_by ?? PlaceListOrderBy.LIKE_SCORE_BEST + const orderBy = PlaceListOrderBy.LIKE_SCORE_BEST const orderDirection = oneOf(options.order, ["asc", "desc"]) ?? "desc" const order = SQL.raw( @@ -451,7 +451,7 @@ export default class PlaceModel extends Model<PlaceAttributes> { return [] } - const orderBy = options.order_by ?? WorldListOrderBy.LIKE_SCORE_BEST + const orderBy = WorldListOrderBy.LIKE_SCORE_BEST const orderDirection = oneOf(options.order, ["asc", "desc"]) ?? "desc" const order = SQL.raw( diff --git a/src/entities/Place/routes/getPlaceList.ts b/src/entities/Place/routes/getPlaceList.ts index d8a807db..32679f45 100644 --- a/src/entities/Place/routes/getPlaceList.ts +++ b/src/entities/Place/routes/getPlaceList.ts @@ -46,7 +46,6 @@ export const getPlaceList = Router.memo( oneOf(ctx.url.searchParams.get("order_by"), [ PlaceListOrderBy.LIKE_SCORE_BEST, PlaceListOrderBy.UPDATED_AT, - PlaceListOrderBy.CREATED_AT, ]) || PlaceListOrderBy.LIKE_SCORE_BEST, order: oneOf(ctx.url.searchParams.get("order"), ["asc", "desc"]) || "desc", diff --git a/src/entities/Place/schemas.ts b/src/entities/Place/schemas.ts index 029fd857..0c809658 100644 --- a/src/entities/Place/schemas.ts +++ b/src/entities/Place/schemas.ts @@ -46,11 +46,7 @@ export const getPlaceListQuerySchema = schema({ order_by: { type: "string", description: "Order places by", - enum: [ - PlaceListOrderBy.LIKE_SCORE_BEST, - PlaceListOrderBy.MOST_ACTIVE, - PlaceListOrderBy.CREATED_AT, - ], + enum: [PlaceListOrderBy.LIKE_SCORE_BEST, PlaceListOrderBy.MOST_ACTIVE], nullable: true as any, }, order: { diff --git a/src/entities/Place/types.ts b/src/entities/Place/types.ts index 331b4527..11ee4412 100644 --- a/src/entities/Place/types.ts +++ b/src/entities/Place/types.ts @@ -63,7 +63,6 @@ export enum PlaceListOrderBy { LIKE_SCORE_BEST = "like_score", UPDATED_AT = "updated_at", USER_VISITS = "user_visits", - CREATED_AT = "created_at", } export type GetPlaceListQuery = { diff --git a/src/entities/World/routes/getWorldList.ts b/src/entities/World/routes/getWorldList.ts index 3a04375e..e867ae75 100644 --- a/src/entities/World/routes/getWorldList.ts +++ b/src/entities/World/routes/getWorldList.ts @@ -29,12 +29,7 @@ export const getWorldList = Router.memo( offset: ctx.url.searchParams.get("offset"), limit: ctx.url.searchParams.get("limit"), only_favorites: ctx.url.searchParams.get("only_favorites"), - order_by: - oneOf(ctx.url.searchParams.get("order_by"), [ - WorldListOrderBy.MOST_ACTIVE, - WorldListOrderBy.LIKE_SCORE_BEST, - WorldListOrderBy.CREATED_AT, - ]) || WorldListOrderBy.MOST_ACTIVE, + order_by: WorldListOrderBy.MOST_ACTIVE, search: ctx.url.searchParams.get("search"), order: oneOf(ctx.url.searchParams.get("order"), ["asc", "desc"]) || "desc", diff --git a/src/entities/World/schemas.ts b/src/entities/World/schemas.ts index df3da922..a035836e 100644 --- a/src/entities/World/schemas.ts +++ b/src/entities/World/schemas.ts @@ -32,11 +32,7 @@ export const getWorldListQuerySchema = schema({ order_by: { type: "string", description: "Order worlds by", - enum: [ - WorldListOrderBy.LIKE_SCORE_BEST, - WorldListOrderBy.MOST_ACTIVE, - WorldListOrderBy.CREATED_AT, - ], + enum: [WorldListOrderBy.LIKE_SCORE_BEST, WorldListOrderBy.MOST_ACTIVE], nullable: true as any, }, order: { diff --git a/src/entities/World/types.ts b/src/entities/World/types.ts index d8cc182f..0b6d06b1 100644 --- a/src/entities/World/types.ts +++ b/src/entities/World/types.ts @@ -12,7 +12,6 @@ export type GetWorldListQuery = { export enum WorldListOrderBy { LIKE_SCORE_BEST = "like_score", MOST_ACTIVE = "most_active", - CREATED_AT = "created_at", } export type WorldListOptions = {