payment plan

main
alex 2024-02-11 11:44:01 +01:00
parent 7c1d3f9ca2
commit c7535df98c
4 changed files with 63 additions and 5 deletions

View File

@ -15,6 +15,7 @@ import {
CALENDAR_MAX_SERVICE_DURATION,
CALENDAR_MIN_EARLIEST_BOOKING_TIME,
EMAIL_VERIFICATION_STATE,
PAYMENT_PLAN,
Roles,
USER_ANALYTICS_ENABLED_DEFAULT,
} from "../utils/constants";
@ -151,6 +152,7 @@ export async function SignUp(req: Request, res: Response) {
language: language,
analytics_enabled: USER_ANALYTICS_ENABLED_DEFAULT,
state: ACCOUNT_STATE.PENDING_EMAIL_VERIFICATION,
payment_plan: PAYMENT_PLAN.DEMO,
});
res.status(200).send({ msg: "success" });
@ -307,6 +309,7 @@ export async function GetUser(req: Request, res: Response) {
"store_id",
"language",
"analytics_enabled",
"payment_plan",
"created_at",
],
});
@ -331,6 +334,7 @@ export async function GetUser(req: Request, res: Response) {
//store_id: user.store_id,
language: user.language,
analytics_enabled: user.analytics_enabled,
payment_plan: user.payment_plan,
},
stores: stores,
// only temporary until we have a proper permissions system
@ -383,6 +387,7 @@ export async function GetUser(req: Request, res: Response) {
language: string;
analytics_enabled: boolean;
account_plan_expiry: Date;
payment_plan: number;
};
}

View File

@ -16,6 +16,7 @@ import {
import User from "../models/user";
import {
ACCOUNT_STATE,
PAYMENT_PLAN_SETTINGS,
Roles,
USER_ANALYTICS_ENABLED_DEFAULT,
} from "../utils/constants";
@ -75,6 +76,34 @@ export async function AddEmployee(req: Request, res: Response) {
return res.status(401).send({ err: "unauthorized" });
}
// get payment plan of store owner
const storeOwner = await User.findOne({
where: {
user_id: store.owner_user_id,
},
attributes: ["payment_plan"],
});
if (!storeOwner) {
return res.status(400).send({ err: "invalid request" });
}
// check max employees limit by payment plan
const employees = await User.findAll({
where: {
store_id: storeId,
},
});
if (
employees.length - 1 >=
PAYMENT_PLAN_SETTINGS[storeOwner.payment_plan].maxEmployees
) {
return res.status(400).send({ err: "invalid request" });
}
// validate username and email
email = email.toLowerCase();
@ -112,6 +141,7 @@ export async function AddEmployee(req: Request, res: Response) {
state: passwordSetOnInitLogging
? ACCOUNT_STATE.INIT_LOGIN
: ACCOUNT_STATE.ACTIVE,
payment_plan: storeOwner.payment_plan,
};
if (!passwordSetOnInitLogging) {
@ -142,6 +172,7 @@ export async function AddEmployee(req: Request, res: Response) {
analytics_enabled: boolean;
password: string;
state: number;
payment_plan: number;
};
}

View File

@ -17,6 +17,7 @@ interface UserAttributes {
google_account_name?: string;
google_account_picture?: string;
analytics_enabled: boolean;
payment_plan: number;
}
class User extends Model<UserAttributes> implements UserAttributes {
@ -31,9 +32,10 @@ class User extends Model<UserAttributes> implements UserAttributes {
declare calendar_using_primary_calendar: boolean;
declare language: string;
declare state: number;
declare analytics_enabled: boolean;
declare google_account_name: string;
declare google_account_picture: string;
declare analytics_enabled: boolean;
declare payment_plan: number;
declare created_at: Date;
}
@ -85,10 +87,6 @@ User.init(
type: DataTypes.INTEGER,
allowNull: false,
},
analytics_enabled: {
type: DataTypes.BOOLEAN,
allowNull: false,
},
google_account_name: {
type: DataTypes.STRING,
allowNull: true,
@ -97,6 +95,14 @@ User.init(
type: DataTypes.STRING,
allowNull: true,
},
analytics_enabled: {
type: DataTypes.BOOLEAN,
allowNull: false,
},
payment_plan: {
type: DataTypes.TINYINT,
allowNull: false,
},
},
{
tableName: "users",

View File

@ -82,3 +82,19 @@ export const PASSPORT_FAILURE_REDIRECT_URL = `${DASHBOARD_URL}/store/calendar/au
export const PASSPORT_SUCCESS_REDIRECT_URL = `${DASHBOARD_URL}/store/calendar/auth/finish`;
export const ACCOUNT_EXPORT_URL = `${DASHBOARD_URL}/v1/user/profile/export/`;
export const TERMIN_PLANNER_URL = process.env.TERMIN_PLANNER_URL;
export enum PAYMENT_PLAN {
DEMO = 0,
BASIC = 1,
}
export const PAYMENT_PLAN_SETTINGS = [
{
//id: PAYMENT_PLAN.DEMO,
maxEmployees: 5,
},
{
//id: PAYMENT_PLAN.BASIC,
maxEmployees: 15,
},
];