Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Billing Service * chore: others * chore: don't type * chore: typo * chore: use proper wh secret * chore: updates * chore: lockfile * chore: docs and comment out * chore: updates and include plan * chore: config * chore: bring back alias * chore: update lockfile * chore: refactor * chore: default none plan in db * chore: read from env vars * chore: feedback * chore: remove json config * chore: proper type
- Loading branch information
Showing
38 changed files
with
663 additions
and
132 deletions.
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
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
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
File renamed without changes.
File renamed without changes.
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,10 @@ | ||
import { Injectable, NestMiddleware } from "@nestjs/common"; | ||
import * as bodyParser from "body-parser"; | ||
import type { Request, Response } from "express"; | ||
|
||
@Injectable() | ||
export class JsonBodyMiddleware implements NestMiddleware { | ||
use(req: Request, res: Response, next: () => any) { | ||
bodyParser.json()(req, res, next); | ||
} | ||
} |
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,10 @@ | ||
import { Injectable, NestMiddleware } from "@nestjs/common"; | ||
import * as bodyParser from "body-parser"; | ||
import type { Request, Response } from "express"; | ||
|
||
@Injectable() | ||
export class RawBodyMiddleware implements NestMiddleware { | ||
use(req: Request, res: Response, next: () => any) { | ||
bodyParser.raw({ type: "*/*" })(req, res, next); | ||
} | ||
} |
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,17 @@ | ||
import { BillingRepository } from "@/modules/billing/billing.repository"; | ||
import { BillingController } from "@/modules/billing/controllers/billing.controller"; | ||
import { BillingConfigService } from "@/modules/billing/services/billing.config.service"; | ||
import { BillingService } from "@/modules/billing/services/billing.service"; | ||
import { MembershipsModule } from "@/modules/memberships/memberships.module"; | ||
import { OrganizationsModule } from "@/modules/organizations/organizations.module"; | ||
import { PrismaModule } from "@/modules/prisma/prisma.module"; | ||
import { StripeModule } from "@/modules/stripe/stripe.module"; | ||
import { Module } from "@nestjs/common"; | ||
|
||
@Module({ | ||
imports: [PrismaModule, StripeModule, MembershipsModule, OrganizationsModule], | ||
providers: [BillingConfigService, BillingService, BillingRepository], | ||
exports: [BillingService, BillingRepository], | ||
controllers: [BillingController], | ||
}) | ||
export class BillingModule {} |
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,36 @@ | ||
import { PlatformPlan } from "@/modules/billing/types"; | ||
import { PrismaReadService } from "@/modules/prisma/prisma-read.service"; | ||
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service"; | ||
import { Injectable } from "@nestjs/common"; | ||
|
||
@Injectable() | ||
export class BillingRepository { | ||
constructor(private readonly dbRead: PrismaReadService, private readonly dbWrite: PrismaWriteService) {} | ||
|
||
getBillingForTeam = (teamId: number) => | ||
this.dbRead.prisma.platformBilling.findUnique({ | ||
where: { | ||
id: teamId, | ||
}, | ||
}); | ||
|
||
async updateTeamBilling( | ||
teamId: number, | ||
billingStart: number, | ||
billingEnd: number, | ||
plan: PlatformPlan, | ||
subscription?: string | ||
) { | ||
return this.dbWrite.prisma.platformBilling.update({ | ||
where: { | ||
id: teamId, | ||
}, | ||
data: { | ||
billingCycleStart: billingStart, | ||
billingCycleEnd: billingEnd, | ||
subscriptionId: subscription, | ||
plan: plan.toString(), | ||
}, | ||
}); | ||
} | ||
} |
Oops, something went wrong.