add credit purchase log (#21768)
Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
1 parent
6cccb1725f
commit
5a1e1e231b
4 files changed
+56
-26
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import stripe from "@calcom/features/ee/payments/server/stripe";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { CreditsRepository } from "@calcom/lib/server/repository/credits";
|
||||
|
||||
import type { SWHMap } from "./__handler";
|
||||
import { HttpCode } from "./__handler";
|
||||
@@ -39,31 +39,29 @@ async function saveToCreditBalance({
|
||||
teamId?: number;
|
||||
nrOfCredits: number;
|
||||
}) {
|
||||
const creditBalance = await prisma.creditBalance.findUnique({
|
||||
where: {
|
||||
teamId,
|
||||
userId: !teamId ? userId : undefined,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
const creditBalance = await CreditsRepository.findCreditBalance({ teamId, userId });
|
||||
|
||||
let creditBalanceId = creditBalance?.id;
|
||||
|
||||
if (creditBalance) {
|
||||
await prisma.creditBalance.update({
|
||||
where: {
|
||||
id: creditBalance.id,
|
||||
},
|
||||
await CreditsRepository.updateCreditBalance({
|
||||
id: creditBalance.id,
|
||||
data: { additionalCredits: { increment: nrOfCredits }, limitReachedAt: null, warningSentAt: null },
|
||||
});
|
||||
return;
|
||||
}
|
||||
await prisma.creditBalance.create({
|
||||
data: {
|
||||
} else {
|
||||
const newCreditBalance = await CreditsRepository.createCreditBalance({
|
||||
teamId: teamId,
|
||||
userId: !teamId ? userId : undefined,
|
||||
additionalCredits: nrOfCredits,
|
||||
},
|
||||
});
|
||||
});
|
||||
creditBalanceId = newCreditBalance.id;
|
||||
}
|
||||
|
||||
if (creditBalanceId) {
|
||||
await CreditsRepository.createCreditPurchaseLog({
|
||||
credits: nrOfCredits,
|
||||
creditBalanceId,
|
||||
});
|
||||
}
|
||||
}
|
||||
export default handler;
|
||||
Reference in new issue
Block a user