Skip to content

Commit

Permalink
rename curation sort to collection sort
Browse files Browse the repository at this point in the history
  • Loading branch information
meelrossi committed Dec 12, 2022
1 parent 6076a3e commit fe134f3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
22 changes: 11 additions & 11 deletions src/Collection/Collection.model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Model, raw, SQL } from 'decentraland-server'
import { DEFAULT_LIMIT } from '../Pagination/utils'
import { CurationStatusFilter, CurationStatusSort } from '../Curation'
import { CurationStatusFilter } from '../Curation'
import { CollectionCuration } from '../Curation/CollectionCuration'
import { ItemCuration } from '../Curation/ItemCuration'
import { database } from '../database/database'
import { Item } from '../Item/Item.model'
import { CollectionAttributes, CollectionTypeFilter } from './Collection.types'
import { CollectionAttributes, CollectionTypeFilter, CollectionSort } from './Collection.types'

type CollectionWithItemCount = CollectionAttributes & {
item_count: number
Expand All @@ -24,7 +24,7 @@ export type FindCollectionParams = {
assignee?: string
status?: CurationStatusFilter
type?: CollectionTypeFilter
sort?: CurationStatusSort
sort?: CollectionSort
isPublished?: boolean
remoteIds?: CollectionAttributes['id'][]
itemTags?: string[]
Expand All @@ -33,9 +33,9 @@ export type FindCollectionParams = {
export class Collection extends Model<CollectionAttributes> {
static tableName = 'collections'

static getOrderByStatement(sort?: CurationStatusSort, remoteIds?: string[]) {
static getOrderByStatement(sort?: CollectionSort, remoteIds?: string[]) {
switch (sort) {
case CurationStatusSort.MOST_RELEVANT:
case CollectionSort.MOST_RELEVANT:
// Order should be
// 1- To review: Not assigned && isApproved false from the contract
// 2- Under review: Assigned && isApproved false from the contract OR has pending curation
Expand All @@ -55,17 +55,17 @@ export class Collection extends Model<CollectionAttributes> {
ELSE 4
END, collections.created_at DESC
`
case CurationStatusSort.NAME_ASC:
case CollectionSort.NAME_ASC:
return SQL`ORDER BY collections.name ASC`
case CurationStatusSort.NAME_DESC:
case CollectionSort.NAME_DESC:
return SQL`ORDER BY collections.name DESC`
case CurationStatusSort.NEWEST:
case CollectionSort.NEWEST:
return SQL`ORDER BY collections.created_at DESC`
case CurationStatusSort.OLDEST:
case CollectionSort.OLDEST:
return SQL`ORDER BY collections.created_at ASC`
case CurationStatusSort.UPDATED_AT_ASC:
case CollectionSort.UPDATED_AT_ASC:
return SQL`ORDER BY collections.updated_at ASC`
case CurationStatusSort.UPDATED_AT_DESC:
case CollectionSort.UPDATED_AT_DESC:
return SQL`ORDER BY collections.updated_at DESC`

default:
Expand Down
16 changes: 10 additions & 6 deletions src/Collection/Collection.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
SlotUsageCheque,
SlotUsageChequeAttributes,
} from '../SlotUsageCheque'
import { CurationStatus, CurationStatusSort } from '../Curation'
import { CurationStatus } from '../Curation'
import { isCommitteeMember } from '../Committee'
import { app } from '../server'
import { hasPublicAccess } from './access'
Expand All @@ -76,6 +76,7 @@ import {
CollectionAttributes,
ThirdPartyCollectionAttributes,
FullCollection,
CollectionSort
} from './Collection.types'

const server = supertest(app.getApp())
Expand Down Expand Up @@ -1059,12 +1060,15 @@ describe('Collection router', () => {
let page: number,
limit: number,
isPublished: string,
totalCollectionsFromDb: number
totalCollectionsFromDb: number,
sort: string

beforeEach(() => {
;(page = 1),
(limit = 3),
(isPublished = 'true'),
(totalCollectionsFromDb = 1)
(totalCollectionsFromDb = 1),
(sort=CollectionSort.NAME_ASC)
;(Collection.findAll as jest.Mock).mockReturnValueOnce([
{ ...dbCollection, collection_count: totalCollectionsFromDb },
])
Expand All @@ -1078,7 +1082,7 @@ describe('Collection router', () => {
return server
.get(
buildURL(
`${url}?limit=${limit}&page=${page}&is_published=${isPublished}`
`${url}?limit=${limit}&page=${page}&is_published=${isPublished}&sort=${sort}`
)
)
.set(createAuthHeaders('get', url))
Expand All @@ -1104,7 +1108,7 @@ describe('Collection router', () => {
address: wallet.address,
limit,
offset: page - 1,
sort: CurationStatusSort.NEWEST,
sort,
isPublished: true,
thirdPartyIds: [],
remoteIds: [],
Expand Down Expand Up @@ -1141,7 +1145,7 @@ describe('Collection router', () => {
address: wallet.address,
limit: undefined,
offset: undefined,
sort: CurationStatusSort.NEWEST,
sort: CollectionSort.NEWEST,
thirdPartyIds: [dbTPCollection.third_party_id],
remoteIds: [],
})
Expand Down
11 changes: 6 additions & 5 deletions src/Collection/Collection.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ import {
getOffset,
getPaginationParams,
} from '../Pagination/utils'
import { CurationStatusFilter, CurationStatusSort } from '../Curation'
import { CurationStatusFilter } from '../Curation'
import { hasTPCollectionURN, isTPCollection } from '../utils/urn'
import { Collection } from './Collection.model'
import { CollectionService } from './Collection.service'
import {
PublishCollectionResponse,
CollectionAttributes,
FullCollection,
CollectionTypeFilter
CollectionTypeFilter,
CollectionSort
} from './Collection.types'
import { upsertCollectionSchema, saveTOSSchema } from './Collection.schema'
import { hasPublicAccess } from './access'
Expand Down Expand Up @@ -254,7 +255,7 @@ export class CollectionRouter extends Router {
assignee: assignee as string,
status: status as CurationStatusFilter,
type: type as CollectionTypeFilter,
sort: sort as CurationStatusSort,
sort: sort as CollectionSort,
isPublished: is_published ? is_published === 'true' : undefined,
offset: page && limit ? getOffset(page, limit) : undefined,
limit,
Expand Down Expand Up @@ -311,7 +312,7 @@ export class CollectionRouter extends Router {
offset: page && limit ? getOffset(page, limit) : undefined,
limit,
address: eth_address,
sort: sort as CurationStatusSort || CurationStatusSort.NEWEST,
sort: sort as CollectionSort || CollectionSort.NEWEST,
isPublished: is_published ? is_published === 'true' : undefined,
remoteIds: authorizedRemoteCollections.map(
(remoteCollection) => remoteCollection.id
Expand Down Expand Up @@ -615,7 +616,7 @@ export class CollectionRouter extends Router {
q: q as string,
assignee: assignee as string,
status: status as CurationStatusFilter,
sort: sort as CurationStatusSort,
sort: sort as CollectionSort,
isPublished: is_published ? is_published === 'true' : undefined,
offset: page && limit ? getOffset(page, limit) : undefined,
limit,
Expand Down
10 changes: 10 additions & 0 deletions src/Collection/Collection.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ export enum CollectionTypeFilter {
STANDARD = 'standard',
THIRD_PARTY = 'third_party'
}

export enum CollectionSort {
MOST_RELEVANT = 'MOST_RELEVANT',
NEWEST = 'NEWEST',
OLDEST = 'OLDEST',
NAME_DESC = 'NAME_DESC',
NAME_ASC = 'NAME_ASC',
UPDATED_AT_DESC = 'UPDATED_AT_DESC',
UPDATED_AT_ASC = 'UPDATED_AT_ASC'
}
10 changes: 0 additions & 10 deletions src/Curation/Curation.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ export enum CurationStatusFilter {
UNDER_REVIEW = 'under_review',
}

export enum CurationStatusSort {
MOST_RELEVANT = 'MOST_RELEVANT',
NEWEST = 'NEWEST',
OLDEST = 'OLDEST',
NAME_DESC = 'NAME_DESC',
NAME_ASC = 'NAME_ASC',
UPDATED_AT_DESC = 'UPDATED_AT_DESC',
UPDATED_AT_ASC = 'UPDATED_AT_ASC'
}

export const patchCurationSchema = Object.freeze({
type: 'object',
properties: {
Expand Down

0 comments on commit fe134f3

Please sign in to comment.