-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add missing backfills for profile pro and open for business (#115)
* 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
1 parent
b1fcbb8
commit d88416d
Showing
4 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |