payment plan
parent
7c1d3f9ca2
commit
c7535df98c
|
@ -15,6 +15,7 @@ import {
|
||||||
CALENDAR_MAX_SERVICE_DURATION,
|
CALENDAR_MAX_SERVICE_DURATION,
|
||||||
CALENDAR_MIN_EARLIEST_BOOKING_TIME,
|
CALENDAR_MIN_EARLIEST_BOOKING_TIME,
|
||||||
EMAIL_VERIFICATION_STATE,
|
EMAIL_VERIFICATION_STATE,
|
||||||
|
PAYMENT_PLAN,
|
||||||
Roles,
|
Roles,
|
||||||
USER_ANALYTICS_ENABLED_DEFAULT,
|
USER_ANALYTICS_ENABLED_DEFAULT,
|
||||||
} from "../utils/constants";
|
} from "../utils/constants";
|
||||||
|
@ -151,6 +152,7 @@ export async function SignUp(req: Request, res: Response) {
|
||||||
language: language,
|
language: language,
|
||||||
analytics_enabled: USER_ANALYTICS_ENABLED_DEFAULT,
|
analytics_enabled: USER_ANALYTICS_ENABLED_DEFAULT,
|
||||||
state: ACCOUNT_STATE.PENDING_EMAIL_VERIFICATION,
|
state: ACCOUNT_STATE.PENDING_EMAIL_VERIFICATION,
|
||||||
|
payment_plan: PAYMENT_PLAN.DEMO,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).send({ msg: "success" });
|
res.status(200).send({ msg: "success" });
|
||||||
|
@ -307,6 +309,7 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
"store_id",
|
"store_id",
|
||||||
"language",
|
"language",
|
||||||
"analytics_enabled",
|
"analytics_enabled",
|
||||||
|
"payment_plan",
|
||||||
"created_at",
|
"created_at",
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -331,6 +334,7 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
//store_id: user.store_id,
|
//store_id: user.store_id,
|
||||||
language: user.language,
|
language: user.language,
|
||||||
analytics_enabled: user.analytics_enabled,
|
analytics_enabled: user.analytics_enabled,
|
||||||
|
payment_plan: user.payment_plan,
|
||||||
},
|
},
|
||||||
stores: stores,
|
stores: stores,
|
||||||
// only temporary until we have a proper permissions system
|
// only temporary until we have a proper permissions system
|
||||||
|
@ -383,6 +387,7 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
language: string;
|
language: string;
|
||||||
analytics_enabled: boolean;
|
analytics_enabled: boolean;
|
||||||
account_plan_expiry: Date;
|
account_plan_expiry: Date;
|
||||||
|
payment_plan: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
import User from "../models/user";
|
import User from "../models/user";
|
||||||
import {
|
import {
|
||||||
ACCOUNT_STATE,
|
ACCOUNT_STATE,
|
||||||
|
PAYMENT_PLAN_SETTINGS,
|
||||||
Roles,
|
Roles,
|
||||||
USER_ANALYTICS_ENABLED_DEFAULT,
|
USER_ANALYTICS_ENABLED_DEFAULT,
|
||||||
} from "../utils/constants";
|
} from "../utils/constants";
|
||||||
|
@ -75,6 +76,34 @@ export async function AddEmployee(req: Request, res: Response) {
|
||||||
return res.status(401).send({ err: "unauthorized" });
|
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
|
// validate username and email
|
||||||
|
|
||||||
email = email.toLowerCase();
|
email = email.toLowerCase();
|
||||||
|
@ -112,6 +141,7 @@ export async function AddEmployee(req: Request, res: Response) {
|
||||||
state: passwordSetOnInitLogging
|
state: passwordSetOnInitLogging
|
||||||
? ACCOUNT_STATE.INIT_LOGIN
|
? ACCOUNT_STATE.INIT_LOGIN
|
||||||
: ACCOUNT_STATE.ACTIVE,
|
: ACCOUNT_STATE.ACTIVE,
|
||||||
|
payment_plan: storeOwner.payment_plan,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!passwordSetOnInitLogging) {
|
if (!passwordSetOnInitLogging) {
|
||||||
|
@ -142,6 +172,7 @@ export async function AddEmployee(req: Request, res: Response) {
|
||||||
analytics_enabled: boolean;
|
analytics_enabled: boolean;
|
||||||
password: string;
|
password: string;
|
||||||
state: number;
|
state: number;
|
||||||
|
payment_plan: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ interface UserAttributes {
|
||||||
google_account_name?: string;
|
google_account_name?: string;
|
||||||
google_account_picture?: string;
|
google_account_picture?: string;
|
||||||
analytics_enabled: boolean;
|
analytics_enabled: boolean;
|
||||||
|
payment_plan: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class User extends Model<UserAttributes> implements UserAttributes {
|
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 calendar_using_primary_calendar: boolean;
|
||||||
declare language: string;
|
declare language: string;
|
||||||
declare state: number;
|
declare state: number;
|
||||||
declare analytics_enabled: boolean;
|
|
||||||
declare google_account_name: string;
|
declare google_account_name: string;
|
||||||
declare google_account_picture: string;
|
declare google_account_picture: string;
|
||||||
|
declare analytics_enabled: boolean;
|
||||||
|
declare payment_plan: number;
|
||||||
declare created_at: Date;
|
declare created_at: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,10 +87,6 @@ User.init(
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
analytics_enabled: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
allowNull: false,
|
|
||||||
},
|
|
||||||
google_account_name: {
|
google_account_name: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
|
@ -97,6 +95,14 @@ User.init(
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
|
analytics_enabled: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
payment_plan: {
|
||||||
|
type: DataTypes.TINYINT,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tableName: "users",
|
tableName: "users",
|
||||||
|
|
|
@ -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 PASSPORT_SUCCESS_REDIRECT_URL = `${DASHBOARD_URL}/store/calendar/auth/finish`;
|
||||||
export const ACCOUNT_EXPORT_URL = `${DASHBOARD_URL}/v1/user/profile/export/`;
|
export const ACCOUNT_EXPORT_URL = `${DASHBOARD_URL}/v1/user/profile/export/`;
|
||||||
export const TERMIN_PLANNER_URL = process.env.TERMIN_PLANNER_URL;
|
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,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
Loading…
Reference in New Issue