feat: Add team billing tables (#24148)
* Init billing tables * Create `IBillingRepository` types * Create billing repositories * Create billingRepositoryFactory * Eslint fix - remove unused organizationOnboarding * internal-team-billing create saveTeamBilling method using repositories * On new teams write to team billing table * On new org write to org billing table * Change fields to organizationId * Add todo comment * Revert "Change fields to organizationId" This reverts commit bbb2e5dfa6b4c20a8a395f5730848a492cd70d68. * test: add comprehensive tests for team billing tables - Fix credit-service.test.ts Prisma mock to export prisma object - Replace any types with proper TypeScript types in credit-service.test.ts - Add unit tests for PrismaTeamBillingRepository covering record creation, enum casting, and error handling - Add unit tests for PrismaOrganizationBillingRepository with same coverage - Add unit tests for BillingRepositoryFactory to verify correct repository selection - Add unit tests for InternalTeamBilling.saveTeamBilling() method testing delegation to correct repositories - All 53 tests pass with TZ=UTC yarn test - Type checking passes with yarn type-check:ci --force Co-Authored-By: [email protected] <[email protected]> * refactor: update saveTeamBilling tests to mock repository interface - Replace prismaMock usage with BillingRepositoryFactory mock - Mock IBillingRepository interface instead of Prisma directly - Follow repository mocking pattern from handleResponse.test.ts - All tests passing (53 total) Co-Authored-By: [email protected] <[email protected]> * Remove log statement * Remove repository tests * Address feedback --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
13 files changed
+446
-12
No files matched your search
+47
@@ -0,0 +1,47 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "TeamBilling" (
|
||||
"id" TEXT NOT NULL,
|
||||
"teamId" INTEGER NOT NULL,
|
||||
"subscriptionId" TEXT NOT NULL,
|
||||
"subscriptionItemId" TEXT NOT NULL,
|
||||
"customerId" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL,
|
||||
"planName" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "TeamBilling_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "OrganizationBilling" (
|
||||
"id" TEXT NOT NULL,
|
||||
"teamId" INTEGER NOT NULL,
|
||||
"subscriptionId" TEXT NOT NULL,
|
||||
"subscriptionItemId" TEXT NOT NULL,
|
||||
"customerId" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL,
|
||||
"planName" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "OrganizationBilling_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "TeamBilling_teamId_key" ON "TeamBilling"("teamId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "TeamBilling_subscriptionId_key" ON "TeamBilling"("subscriptionId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "OrganizationBilling_teamId_key" ON "OrganizationBilling"("teamId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "OrganizationBilling_subscriptionId_key" ON "OrganizationBilling"("subscriptionId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "TeamBilling" ADD CONSTRAINT "TeamBilling_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "OrganizationBilling" ADD CONSTRAINT "OrganizationBilling_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -588,6 +588,9 @@ model Team {
|
||||
managedOrganizations ManagedOrganization[] @relation("ManagerOrganization")
|
||||
filterSegments FilterSegment[]
|
||||
|
||||
teamBilling TeamBilling? @relation("TeamBilling")
|
||||
organizationBilling OrganizationBilling? @relation("OrganizationBilling")
|
||||
|
||||
@@unique([slug, parentId])
|
||||
@@index([parentId])
|
||||
}
|
||||
@@ -2595,6 +2598,36 @@ model CalAiPhoneNumber {
|
||||
@@index([outboundAgentId])
|
||||
}
|
||||
|
||||
model TeamBilling {
|
||||
id String @id @default(uuid())
|
||||
teamId Int @unique
|
||||
team Team? @relation("TeamBilling", fields: [teamId], references: [id], onDelete: Cascade)
|
||||
|
||||
subscriptionId String @unique
|
||||
subscriptionItemId String
|
||||
customerId String
|
||||
status String
|
||||
planName String
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model OrganizationBilling {
|
||||
id String @id @default(uuid())
|
||||
teamId Int @unique
|
||||
team Team @relation("OrganizationBilling", fields: [teamId], references: [id], onDelete: Cascade)
|
||||
|
||||
subscriptionId String @unique
|
||||
subscriptionItemId String
|
||||
customerId String
|
||||
status String
|
||||
planName String
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
enum CalendarCacheEventStatus {
|
||||
confirmed @map("confirmed")
|
||||
tentative @map("tentative")
|
||||
|
||||
Reference in new issue
Block a user