-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init paid plans model config (#2275)
- Loading branch information
Showing
5 changed files
with
139 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Attributes } from "sequelize"; | ||
|
||
import { Plan } from "@app/lib/models"; | ||
|
||
export type PlanAttributes = Omit< | ||
Attributes<Plan>, | ||
"id" | "createdAt" | "updatedAt" | ||
>; | ||
|
||
/** | ||
* We have 3 categories of plans: | ||
* - Free: plans with no paid subscription. | ||
* - Pro: plans with a paid subscription, not tailored. -> i.e. the same plan is used by all Pro workspaces. | ||
* - Entreprise: plans with a paid subscription, tailored to the needs of the entreprise. -> i.e. we will have one plan per "Entreprise". | ||
* | ||
* This file about Entreprise plans. | ||
* As entreprise plans are custom, we won't create them in this file, but directly from Poké. | ||
*/ | ||
|
||
/** | ||
* ENT_PLAN_FAKE is not subscribable and is only used to display the Enterprise plan in the UI (hence it's not stored on the db). | ||
*/ | ||
export const ENT_PLAN_FAKE_CODE = "ENT_PLAN_FAKE_CODE"; | ||
export const ENT_PLAN_FAKE_DATA: PlanAttributes = { | ||
code: ENT_PLAN_FAKE_CODE, | ||
name: "Entreprise", | ||
stripeProductId: null, | ||
maxMessages: -1, | ||
maxUsersInWorkspace: -1, | ||
isSlackbotAllowed: true, | ||
isManagedSlackAllowed: true, | ||
isManagedNotionAllowed: true, | ||
isManagedGoogleDriveAllowed: true, | ||
isManagedGithubAllowed: true, | ||
maxNbStaticDataSources: -1, | ||
maxNbStaticDocuments: -1, | ||
maxSizeStaticDataSources: 2, // 2MB | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Attributes } from "sequelize"; | ||
|
||
import { Plan } from "@app/lib/models"; | ||
|
||
export type PlanAttributes = Omit< | ||
Attributes<Plan>, | ||
"id" | "createdAt" | "updatedAt" | ||
>; | ||
|
||
/** | ||
* We have 3 categories of plans: | ||
* - Free: plans with no paid subscription. | ||
* - Pro: plans with a paid subscription, not tailored. -> i.e. the same plan is used by all Pro workspaces. | ||
* - Entreprise: plans with a paid subscription, tailored to the needs of the entreprise. -> i.e. we will have one plan per "Entreprise". | ||
* | ||
* This file about Pro plans. | ||
*/ | ||
|
||
// Current pro plans: | ||
export const PRO_PLAN_MAU_29_CODE = "PRO_PLAN_MAU_29"; | ||
export const PRO_PLAN_FIXED_1000_CODE = "PRO_PLAN_FIXED_1000"; | ||
|
||
/** | ||
* Paid plans are stored in the database. | ||
* We can update existing plans or add new one but never remove anything from this list. | ||
* Entreprise custom plans will be created from Poké. | ||
*/ | ||
const PRO_PLANS_DATA: PlanAttributes[] = [ | ||
{ | ||
code: "PRO_PLAN_MAU_29", | ||
name: "Pro", | ||
stripeProductId: "prod_OtB9SOIwFyiQnl", | ||
maxMessages: -1, | ||
maxUsersInWorkspace: 500, | ||
isSlackbotAllowed: true, | ||
isManagedSlackAllowed: true, | ||
isManagedNotionAllowed: true, | ||
isManagedGoogleDriveAllowed: true, | ||
isManagedGithubAllowed: true, | ||
maxNbStaticDataSources: -1, | ||
maxNbStaticDocuments: -1, | ||
maxSizeStaticDataSources: 2, // 2MB | ||
}, | ||
{ | ||
code: "PRO_PLAN_FIXED_1000", | ||
name: "Pro Fixed", | ||
stripeProductId: "prod_OtBhelMswszehT", | ||
maxMessages: -1, | ||
maxUsersInWorkspace: 50, | ||
isSlackbotAllowed: true, | ||
isManagedSlackAllowed: true, | ||
isManagedNotionAllowed: true, | ||
isManagedGoogleDriveAllowed: true, | ||
isManagedGithubAllowed: true, | ||
maxNbStaticDataSources: -1, | ||
maxNbStaticDocuments: -1, | ||
maxSizeStaticDataSources: 2, // 2MB | ||
}, | ||
]; | ||
|
||
/** | ||
* Function to call when we edit something in FREE_PLANS_DATA to update the database. It will create or update the plans. | ||
*/ | ||
export const upsertProPlans = async () => { | ||
for (const planData of PRO_PLANS_DATA) { | ||
const plan = await Plan.findOne({ | ||
where: { | ||
code: planData.code, | ||
}, | ||
}); | ||
if (plan === null) { | ||
await Plan.create(planData); | ||
console.log(`Pro plan ${planData.code} created.`); | ||
} else { | ||
await plan.update(planData); | ||
console.log(`Pro plan ${planData.code} updated.`); | ||
} | ||
} | ||
}; |