Skip to content

Commit

Permalink
feat: merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Mar 9, 2022
2 parents 815462f + ff6afcc commit 178015d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 53 deletions.
65 changes: 23 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Collection/Collection.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ describe('Collection router', () => {
describe('when the collection already has a pending ItemCuration', () => {
beforeEach(() => {
;(Item.findByIds as jest.Mock).mockResolvedValueOnce([dbItemMock])
;(ItemCuration.findLastByCollectionId as jest.Mock).mockResolvedValueOnce(
;(ItemCuration.findLastCreatedByCollectionIdAndStatus as jest.Mock).mockResolvedValueOnce(
itemCurationMock
)
jest.spyOn(ethers.utils, 'verifyMessage').mockReturnValue('0x')
Expand Down
13 changes: 8 additions & 5 deletions src/Collection/Collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ export class CollectionService {
}

/**
* It should receive the list of items to be operated on so it can decide where it should create or update the curations for them accordingly
* It will also receive a signed message and its signature, so it can check and store it in the SlotUsageCheque
* Publishes a TP collection by storing the slots cheque and creating the curations for the items to be published.
* It creates or updates the virtual CollectionCuration for the items
* @param dbCollection - Database TP collection
* @param dbItems - Database TP items that belong to the collection
* @param signedMessage - The message we signed
Expand All @@ -151,10 +151,10 @@ export class CollectionService {
// That will fire a /collections/${collectionId}/curation which will create a new CollectionCuration
// Subsequent changes will not show the push changes button, as it's already under_review

// For TP items, creations always exist. PUSH CHANGES should appear if the item has an approved ItemCuration and has changes in the Catalyst
// For TP items, curations always exist. PUSH CHANGES should appear if the item has an approved ItemCuration and has changes in the Catalyst
// That should fire /items/:id/curation for each item that changed

// What we should migrate over here is the creation of the virtual CollectionCuration, as there'll always be a publish before a PUSH CHANGES
// There'll always be a publish before a PUSH CHANGES, so this method also creates or updates the virtual CollectionCuration for the items

if (dbItems.length === 0) {
throw new InvalidRequestError('Tried to publish no TP items')
Expand All @@ -178,7 +178,10 @@ export class CollectionService {
)
}

const isPublished = await ItemCuration.findLastByCollectionId(collectionId)
const isPublished = await ItemCuration.findLastCreatedByCollectionIdAndStatus(
collectionId,
CurationStatus.PENDING
)
if (isPublished) {
throw new AlreadyPublishedCollectionError(
collectionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class CollectionCuration extends Model<CollectionCurationAttributes> {
static async updateByItemId(itemId: string): Promise<{ rowCount: number }> {
const columns = await this.query(SQL`
UPDATE ${raw(CollectionCuration.tableName)} as collection_curations
SET updated_at = now()
SET updated_at = ${new Date()}
FROM ${raw(Item.tableName)} as items
WHERE collection_curations.collection_id = items.collection_id
AND items.id = ${itemId}`)
Expand Down
20 changes: 18 additions & 2 deletions src/Curation/ItemCuration/ItemCuration.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Model, raw, SQL } from 'decentraland-server'
import { Collection } from '../../Collection'
import { Item } from '../../Item'
import { CurationType } from '../Curation.types'
import { CurationStatus, CurationType } from '../Curation.types'
import { ItemCurationAttributes } from './ItemCuration.types'

export class ItemCuration extends Model<ItemCurationAttributes> {
Expand Down Expand Up @@ -44,7 +44,23 @@ export class ItemCuration extends Model<ItemCurationAttributes> {
return itemCurations[0]
}

static async getItemCurationCountByThirdPartyId(thirdPartyId: string) {
static async findLastCreatedByCollectionIdAndStatus(
collectionId: string,
curationStatus: CurationStatus
): Promise<ItemCurationAttributes | undefined> {
const itemCurations = await this.query<ItemCurationAttributes>(SQL`
SELECT item_curations.*
FROM ${raw(this.tableName)} item_curations
JOIN ${raw(Item.tableName)} items ON items.id = item_curations.item_id
WHERE items.collection_id = ${collectionId}
AND items.status = ${curationStatus}
ORDER BY item_curations.created_at DESC
LIMIT 1`)

return itemCurations[0]
}

static async getCountByThirdPartyId(thirdPartyId: string) {
const counts = await this.query<{ count: number }>(
SQL`SELECT COUNT(DISTINCT item_curations.id) AS Count
FROM ${raw(ItemCuration.tableName)} AS item_curations
Expand Down
2 changes: 1 addition & 1 deletion src/ThirdParty/ThirdParty.router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('ThirdParty router', () => {
maxSlots
)
;(thirdPartyAPI.isManager as jest.Mock).mockResolvedValueOnce(true)
;(ItemCuration.getItemCurationCountByThirdPartyId as jest.Mock).mockResolvedValueOnce(
;(ItemCuration.getCountByThirdPartyId as jest.Mock).mockResolvedValueOnce(
itemsInCuration
)
url = '/thirdParties/aThirdPartyId/slots'
Expand Down
2 changes: 1 addition & 1 deletion src/ThirdParty/ThirdParty.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class ThirdPartyService {
): Promise<number> {
const [maxItems, itemCurationsCount] = await Promise.all([
thirdPartyAPI.fetchMaxItemsByThirdParty(thirdPartyId),
ItemCuration.getItemCurationCountByThirdPartyId(thirdPartyId),
ItemCuration.getCountByThirdPartyId(thirdPartyId),
])
return maxItems - itemCurationsCount
}
Expand Down

0 comments on commit 178015d

Please sign in to comment.