-
Notifications
You must be signed in to change notification settings - Fork 60
Basic Store Credit Plugin Setup #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughIntroduces a new Vendure plugin for store credit wallet functionality, including wallet and adjustment entities, GraphQL API extensions for both shop and admin, a wallet service with balance management, resolvers, and supporting configuration files for testing and linting. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In `@packages/vendure-plugin-store-credit/src/api/customer-entity.resolver.ts`:
- Around line 14-23: The wallets resolver returns wallets for the parent
Customer without verifying the requester owns that customer; update the
wallets(`@Ctx`() ctx: RequestContext, `@Parent`() customer: Customer) method to
check that ctx.session?.customer?.id === customer.id (or equivalent current user
id) and throw an authorization error (e.g., ForbiddenError/Unauthorized) if it
does not match, before calling this.connection.getRepository(...).find(...), so
only the owning customer can access their wallets.
In `@packages/vendure-plugin-store-credit/src/api/wallet.resolver.ts`:
- Around line 13-25: The GraphQL mutations createWallet and
adjustBalanceForWallet are using `@Args`() which passes the whole args object ({
input: ... }) to walletService; change the decorators to `@Args`('input') so the
resolver receives the unwrapped input object expected by WalletService (update
the parameters on createWallet and adjustBalanceForWallet to accept the input
type via `@Args`('input') and pass that input directly to
this.walletService.createWallet(...) and
this.walletService.adjustBalanceForWallet(...)).
In `@packages/vendure-plugin-store-credit/src/services/wallet.service.ts`:
- Around line 70-74: The ledger currently always saves a positive amount via
adjustmentRepo.create(... { wallet: { id: input.walletId } as Wallet, amount:
input.amount }), losing debit/credit direction; change this to persist either a
signed amount or the adjustment type: compute a signedAmount (e.g. signedAmount
= input.type === 'DEBIT' ? -Math.abs(input.amount) : Math.abs(input.amount)) and
pass amount: signedAmount into adjustmentRepo.create, or include a type field
(e.g. type: input.type or isDebit: boolean) on the created entity so
adjustmentRepo.save/adjustmentRepo.create records the direction alongside the
magnitude.
- Around line 19-31: The createWallet method is creating a Wallet without
required non-null fields and misassigning balances; before saving the new Wallet
instance (in createWallet) set channel and currencyCode to valid values (e.g.,
derive from ctx or input) and set balance to the numeric input.initialBalance
(use the same source as initialAmount), ensuring initialAmount and amount
reflect intended semantics; update the Wallet construction or assign properties
on the Wallet instance (referencing createWallet, Wallet, input.initialBalance,
initialAmount, amount, balance, channel, currencyCode) so the DB insert includes
channel and currencyCode and balance is initialized correctly.
🧹 Nitpick comments (1)
packages/vendure-plugin-store-credit/test/dev-server.ts (1)
20-21: Inconsistent import style.
testConfigis dynamically required while other exports from@vendure/testingare statically imported at the top. Consider importingtestConfigstatically with the other imports for consistency.
packages/vendure-plugin-store-credit/src/api/customer-entity.resolver.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/api/wallet.resolver.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/services/wallet.service.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/api/customer-entity.resolver.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/entities/wallet.entity.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/entities/wallet.entity.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/services/wallet.service.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/services/wallet.service.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/services/wallet.service.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/services/wallet.service.ts
Outdated
Show resolved
Hide resolved
packages/vendure-plugin-store-credit/src/services/wallet.service.ts
Outdated
Show resolved
Hide resolved
|
It has been a while since I worked on the plugins, sorry I had missed so many minor details |
…cross-channel payment blocks
Description
Checklist
📌 Always:
👍 Most of the time:
📦 For publishable packages:
package.jsonCHANGELOG.md