Skip to content

Commit

Permalink
chore: adds documentation to methods
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed May 19, 2022
1 parent 8b35708 commit 09ee607
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
19 changes: 18 additions & 1 deletion src/Collection/Collection.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Collection extends Model<CollectionAttributes> {
CurationStatusFilter.PENDING,
CurationStatusFilter.APPROVED,
].includes(status)
? SQL`collection_curations.status = ${status}`
? SQL`collection_curations.status = ${status} AND collections.contract_address = ANY(${remoteIds})`
: status === CurationStatusFilter.REJECTED // Rejected not a single curation in approved
? SQL`collection_curations.status = ${status} AND collections.contract_address = ANY(${remoteIds})`
: status === CurationStatusFilter.TO_REVIEW // To review: Not assigned && isApproved false from the contract
Expand Down Expand Up @@ -148,6 +148,23 @@ export class Collection extends Model<CollectionAttributes> {
: SQL``
}

/**
* Finds all the Collections that given parameters. It sorts and paginates the results.
* If the status is APPROVED, the remoteIds will be the ones with `isApproved` true.
* If the status is TO_REVIEW, UNDER_REVIEW or REJECTED, the remoteIds will be the ones with `isApproved` false.
* If status is not defined, the remoteIds will be the ones with `isApproved` false, so the ORDER BY can put them first.
*
* @param limit - limit param to paginate the query
* @param offset - offset param to paginate the query
* @param sort - the type of sorting to apply. MOST_RELEVANT will return the NOT approved first.
* @param isPublished - if true, will return only the published collections. If false, will return only the unpublished collections.
* @param q - the query to search for.
* @param assignee - the assignee to filter by.
* @param status - the status to filter by.
* @param address - the address to filter by.
* @param thirdPartyIds - the third party ids to filter by. If it's a committee member, the array will have all the ids.
* @param remoteIds - The remote ids to filter the query with
*/
static findAll({
limit = DEFAULT_LIMIT,
offset = 0,
Expand Down
6 changes: 5 additions & 1 deletion src/Collection/Collection.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ export class CollectionRouter extends Router {
)
}

// If status is passed, the graph query will be filtered and those results will be included in a WHERE statement in the query later on
// If status is not passed, the query won't be filtered and all the collections will be retrieved
const remoteCollections = await collectionAPI.fetchCollections(
toRemoteWhereCondition({ status: status as CurationStatusFilter })
)
Expand All @@ -247,7 +249,9 @@ export class CollectionRouter extends Router {
limit,
remoteIds: status
? remoteCollections.map((c) => c.id)
: remoteCollections.filter((r) => !r.isApproved).map((c) => c.id), // if the status is not passed, we still want to prioritize the not approved. It won't filter by them, it'll just use them for the sort
: // if the status is not passed, we still want to prioritize the not approved. It won't filter by them, it'll just use them for the sort.
// We filter at this level and not in the query because we need all the collections so they can be consolidated later on.
remoteCollections.filter((r) => !r.isApproved).map((c) => c.id),
})

const totalCollections =
Expand Down
12 changes: 1 addition & 11 deletions src/Collection/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,6 @@ export function toRemoteWhereCondition({
status?: CurationStatusFilter
}): CollectionQueryFilters {
return {
isApproved: status
? status === CurationStatusFilter.APPROVED
? true
: [
CurationStatusFilter.TO_REVIEW,
CurationStatusFilter.UNDER_REVIEW,
CurationStatusFilter.REJECTED,
].includes(status)
? false
: undefined
: undefined,
isApproved: status ? status === CurationStatusFilter.APPROVED : undefined,
}
}

0 comments on commit 09ee607

Please sign in to comment.