Skip to content

feat: add computePriceChange helper - #656

Open
Godfrey-Delight wants to merge 4 commits into
accesslayerorg:mainfrom
Godfrey-Delight:feat/compute-price-change-helper
Open

feat: add computePriceChange helper#656
Godfrey-Delight wants to merge 4 commits into
accesslayerorg:mainfrom
Godfrey-Delight:feat/compute-price-change-helper

Conversation

@Godfrey-Delight

Copy link
Copy Markdown
Contributor

Summary

  • Adds a CreatorPriceHistory model (id, creatorId, price, recordedAt, indexed on creatorId + recordedAt) and a computePriceChange(creatorId, windowMs, db) helper that fetches the oldest and latest snapshot in a given window and returns the signed percentage change rounded to two decimal places, with 5 unit tests covering positive/negative change, single-snapshot and no-snapshot null cases, and rounding precision. Wires up price-snapshot.service.ts to write a history record on every trade, and switches creator-profile.service.ts and creator-list-item.mapper.ts to use the helper for the 24h window, falling back to the existing inline calc when no history exists yet; the mapper and downstream serializers/controllers (creators.serializers.ts, creators.utils.ts, creators.controllers.ts) are updated to async to support this. Updates existing tests to match the new shapes and mocks.

Closes #643

Testing

  • pnpm lint
  • pnpm build
  • pnpm exec prisma generate when schema or generated types changed

Checklist

  • Linked issue or backlog item
  • No secrets or live credentials added
  • Docs updated if setup or env changed
  • Change is scoped to one problem

Adds a CreatorPriceHistory model (id, creatorId, price, recordedAt, indexed on creatorId + recordedAt) and a computePriceChange(creatorId, windowMs, db) helper that fetches the oldest and latest snapshot in a given window and returns the signed percentage change rounded to two decimal places, with 5 unit tests covering positive/negative change, single-snapshot and no-snapshot null cases, and rounding precision. Wires up price-snapshot.service.ts to write a history record on every trade, and switches creator-profile.service.ts and creator-list-item.mapper.ts to use the helper for the 24h window, falling back to the existing inline calc when no history exists yet; the mapper and downstream serializers/controllers (creators.serializers.ts, creators.utils.ts, creators.controllers.ts) are updated to async to support this. Updates existing tests to match the new shapes and mocks. Closes accesslayerorg#643
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@Godfrey-Delight Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add helper for computing the percentage change in a creator's key price over a configurable time window

1 participant