Skip to content

Commit

Permalink
feat: Add missing backfills for profile pro and open for business (#115)
Browse files Browse the repository at this point in the history
* feat: Add missing backfills for profile pro and open for business

* feat: Log also backfill data and user progress when there is an error
  • Loading branch information
kevinszuchet committed Oct 22, 2024
1 parent b1fcbb8 commit d88416d
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ on:

jobs:
build:
uses: decentraland/platform-actions/.github/workflows/apps-with-db-build.yml@main
uses: decentraland/platform-actions/.github/workflows/apps-with-db-build.yml@feat/coverage-for-apps-with-db
16 changes: 16 additions & 0 deletions api/src/logic/backfill-merger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { mergeSocialButterflyProgress } from './backfills/social-butterfly-backf
import { mergeLandArchitectProgress } from './backfills/land-architect-backfill'
import { mergeEmoteCreatorProgress } from './backfills/emote-creator-backfill'
import { mergeWearableDesignerProgress } from './backfills/wearable-designer-backfill'
import { mergeProfileProProgress } from './backfills/profile-pro-backfill'
import { mergeOpenForBusinessProgress } from './backfills/open-for-business-backfill'

export function createBackfillMergerComponent({
logs,
Expand Down Expand Up @@ -93,6 +95,20 @@ export function createBackfillMergerComponent({
badgeService.getBadge(BadgeId.LAND_ARCHITECT),
backfillData
)
case BadgeId.PROFILE_PRO:
return mergeProfileProProgress(
userAddress,
currentUserProgress,
badgeService.getBadge(BadgeId.PROFILE_PRO),
backfillData
)
case BadgeId.OPEN_FOR_BUSINESS:
return mergeOpenForBusinessProgress(
userAddress,
currentUserProgress,
badgeService.getBadge(BadgeId.OPEN_FOR_BUSINESS),
backfillData
)

default:
throw new InvalidRequestError('Invalid Badge ID')
Expand Down
48 changes: 48 additions & 0 deletions api/src/logic/backfills/open-for-business-backfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Badge, UserBadge } from '@badges/common'
import { EthAddress } from '@dcl/schemas'

type BackfillData = {
progress: {
completedAt: number
}
}

function validateOpenForBusinessBackfillData(data: BackfillData): boolean {
return Number.isInteger(data.progress.completedAt)
}

export function mergeOpenForBusinessProgress(
userAddress: EthAddress,
currentUserProgress: UserBadge | undefined,
badge: Badge,
backfillData: BackfillData
): UserBadge {
if (!badge || !validateOpenForBusinessBackfillData(backfillData)) {
throw new Error(`Failed while processing backfill. Badge: ${JSON.stringify(badge)}. User: ${userAddress}.`)
}

const userProgress: UserBadge = currentUserProgress || {
user_address: userAddress,
badge_id: badge.id,
completed_at: undefined,
progress: {
steps: 0
}
}

try {
userProgress.progress.steps = 2
userProgress.progress.store_completed = true
userProgress.progress.collection_submitted = true
userProgress.completed_at = Math.min(userProgress.completed_at || Date.now(), backfillData.progress.completedAt)

return userProgress
} catch (error) {
console.error(`Error processing user ${userAddress}:`, {
error,
backfillData: JSON.stringify(backfillData),
userProgress: JSON.stringify(userProgress)
})
throw error
}
}
48 changes: 48 additions & 0 deletions api/src/logic/backfills/profile-pro-backfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Badge, UserBadge } from '@badges/common'
import { EthAddress } from '@dcl/schemas'

type BackfillData = {
progress: {
completedAt: number
description: string
}
}

function validateProfileProBackfillData(data: BackfillData): boolean {
return Number.isInteger(data.progress.completedAt) && typeof data.progress.description === 'string'
}

export function mergeProfileProProgress(
userAddress: EthAddress,
currentUserProgress: UserBadge | undefined,
badge: Badge,
backfillData: BackfillData
): UserBadge {
if (!badge || !validateProfileProBackfillData(backfillData)) {
throw new Error(`Failed while processing backfill. Badge: ${JSON.stringify(badge)}. User: ${userAddress}.`)
}

const userProgress: UserBadge = currentUserProgress || {
user_address: userAddress,
badge_id: badge.id,
completed_at: undefined,
progress: {
steps: 0
}
}

try {
userProgress.progress.steps = 1
userProgress.progress.description_added = backfillData.progress.description
userProgress.completed_at = Math.min(userProgress.completed_at || Date.now(), backfillData.progress.completedAt)

return userProgress
} catch (error) {
console.error(`Error processing user ${userAddress}:`, {
error,
backfillData: JSON.stringify(backfillData),
userProgress: JSON.stringify(userProgress)
})
throw error
}
}

0 comments on commit d88416d

Please sign in to comment.