sign up
parent
fdfd658fd0
commit
1880bd64b8
|
@ -19,6 +19,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,
|
||||||
PAYMENT_PLAN_SETTINGS,
|
PAYMENT_PLAN_SETTINGS,
|
||||||
PAYMENT_PLAN_STATUS,
|
PAYMENT_PLAN_STATUS,
|
||||||
Roles,
|
Roles,
|
||||||
|
@ -62,15 +63,12 @@ export async function SignUp(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
let {
|
let {
|
||||||
companyName,
|
companyName,
|
||||||
|
companyAddress,
|
||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
language,
|
language,
|
||||||
rememberMe,
|
|
||||||
recaptcha,
|
recaptcha,
|
||||||
paymentPlan,
|
|
||||||
paymentInterval,
|
|
||||||
companyAddress,
|
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
// validate request
|
// validate request
|
||||||
|
@ -85,12 +83,7 @@ export async function SignUp(req: Request, res: Response) {
|
||||||
!isUsernameValid(username) ||
|
!isUsernameValid(username) ||
|
||||||
!(await isEmailValid(email)) ||
|
!(await isEmailValid(email)) ||
|
||||||
!isLanguageCodeValid(language) ||
|
!isLanguageCodeValid(language) ||
|
||||||
rememberMe === undefined ||
|
|
||||||
!recaptcha ||
|
!recaptcha ||
|
||||||
paymentPlan === undefined ||
|
|
||||||
!isPaymentPlanValid(paymentPlan) ||
|
|
||||||
paymentInterval === undefined ||
|
|
||||||
!isPaymentIntervalValid(paymentInterval) ||
|
|
||||||
!isCompanyAddressValid(companyAddress)
|
!isCompanyAddressValid(companyAddress)
|
||||||
) {
|
) {
|
||||||
return res.status(400).send({ err: "invalid request" });
|
return res.status(400).send({ err: "invalid request" });
|
||||||
|
@ -142,14 +135,14 @@ export async function SignUp(req: Request, res: Response) {
|
||||||
owner_user_id: userId,
|
owner_user_id: userId,
|
||||||
name: companyName,
|
name: companyName,
|
||||||
calendar_max_future_booking_days:
|
calendar_max_future_booking_days:
|
||||||
PAYMENT_PLAN_SETTINGS[paymentPlan].calendarMaxFutureBookingDays,
|
PAYMENT_PLAN_SETTINGS[PAYMENT_PLAN.DEMO].calendarMaxFutureBookingDays,
|
||||||
calendar_min_earliest_booking_time: CALENDAR_MIN_EARLIEST_BOOKING_TIME,
|
calendar_min_earliest_booking_time: CALENDAR_MIN_EARLIEST_BOOKING_TIME,
|
||||||
calendar_max_service_duration: CALENDAR_MAX_SERVICE_DURATION,
|
calendar_max_service_duration: CALENDAR_MAX_SERVICE_DURATION,
|
||||||
address: companyAddress,
|
address: companyAddress,
|
||||||
});
|
});
|
||||||
|
|
||||||
// create email verification
|
// create email verification
|
||||||
/*
|
|
||||||
const emailVerificationId = newEmailVerificationId();
|
const emailVerificationId = newEmailVerificationId();
|
||||||
const state = EMAIL_VERIFICATION_STATE.PENDING_EMAIL_VERIFICATION;
|
const state = EMAIL_VERIFICATION_STATE.PENDING_EMAIL_VERIFICATION;
|
||||||
|
|
||||||
|
@ -161,7 +154,7 @@ export async function SignUp(req: Request, res: Response) {
|
||||||
|
|
||||||
rabbitmq.sendEmail(email, "dashboardSignUpEmailVerification", language, {
|
rabbitmq.sendEmail(email, "dashboardSignUpEmailVerification", language, {
|
||||||
emailVerificationUrl: getEmailVerificationUrl(state, emailVerificationId),
|
emailVerificationUrl: getEmailVerificationUrl(state, emailVerificationId),
|
||||||
}); */
|
});
|
||||||
|
|
||||||
// create user
|
// create user
|
||||||
|
|
||||||
|
@ -175,10 +168,10 @@ 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.INIT_PAYMENT,
|
state: ACCOUNT_STATE.INIT_PAYMENT,
|
||||||
payment_plan: paymentPlan,
|
payment_plan: PAYMENT_PLAN.DEMO,
|
||||||
payment_plan_status: PAYMENT_PLAN_STATUS.TRAILING,
|
// payment_plan_status: PAYMENT_PLAN_STATUS.TRAILING,
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
const checkoutSessionUrl = await CreateCheckoutSession(
|
const checkoutSessionUrl = await CreateCheckoutSession(
|
||||||
await getPriceId(paymentPlan, paymentInterval),
|
await getPriceId(paymentPlan, paymentInterval),
|
||||||
userId
|
userId
|
||||||
|
@ -186,15 +179,24 @@ export async function SignUp(req: Request, res: Response) {
|
||||||
|
|
||||||
if (!checkoutSessionUrl) {
|
if (!checkoutSessionUrl) {
|
||||||
return res.status(500).send({ err: "invalid request" });
|
return res.status(500).send({ err: "invalid request" });
|
||||||
}
|
} */
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`new user signed up: user_id: ${userId} email: ${email} language: ${language} company: ${companyName} username: ${username}`
|
`new user signed up: user_id: ${userId} email: ${email} language: ${language} company: ${companyName} username: ${username}`
|
||||||
);
|
);
|
||||||
|
|
||||||
saveSession(req, res, userId, true, {
|
res.status(200).send({ msg: "success" });
|
||||||
|
|
||||||
|
/*
|
||||||
|
saveSession(
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
userId,
|
||||||
|
true
|
||||||
|
, {
|
||||||
redirectUrl: checkoutSessionUrl,
|
redirectUrl: checkoutSessionUrl,
|
||||||
});
|
}
|
||||||
|
);*/
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("signup error", error as string);
|
logger.error("signup error", error as string);
|
||||||
res.status(500).send({ err: "invalid request" });
|
res.status(500).send({ err: "invalid request" });
|
||||||
|
@ -481,7 +483,7 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
language: user.language,
|
language: user.language,
|
||||||
analytics_enabled: user.analytics_enabled,
|
analytics_enabled: user.analytics_enabled,
|
||||||
payment_plan: user.payment_plan,
|
payment_plan: user.payment_plan,
|
||||||
payment_plan_status: user.payment_plan_status,
|
// payment_plan_status: user.payment_plan_status,
|
||||||
payment_plan_trial_end: user.payment_plan_trial_end,
|
payment_plan_trial_end: user.payment_plan_trial_end,
|
||||||
payment_plan_canceled_at: user.payment_plan_canceled_at,
|
payment_plan_canceled_at: user.payment_plan_canceled_at,
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,7 +18,7 @@ interface UserAttributes {
|
||||||
google_account_picture?: string;
|
google_account_picture?: string;
|
||||||
analytics_enabled: boolean;
|
analytics_enabled: boolean;
|
||||||
payment_plan: number;
|
payment_plan: number;
|
||||||
payment_plan_status?: string;
|
// payment_plan_status?: string;
|
||||||
payment_plan_trial_end?: number;
|
payment_plan_trial_end?: number;
|
||||||
payment_plan_canceled_at?: number;
|
payment_plan_canceled_at?: number;
|
||||||
stripe_customer_id?: string;
|
stripe_customer_id?: string;
|
||||||
|
@ -40,7 +40,7 @@ class User extends Model<UserAttributes> implements UserAttributes {
|
||||||
declare google_account_picture: string;
|
declare google_account_picture: string;
|
||||||
declare analytics_enabled: boolean;
|
declare analytics_enabled: boolean;
|
||||||
declare payment_plan: number;
|
declare payment_plan: number;
|
||||||
declare payment_plan_status: string;
|
// declare payment_plan_status: string;
|
||||||
declare payment_plan_trial_end: number;
|
declare payment_plan_trial_end: number;
|
||||||
declare payment_plan_canceled_at: number;
|
declare payment_plan_canceled_at: number;
|
||||||
declare stripe_customer_id: string;
|
declare stripe_customer_id: string;
|
||||||
|
@ -111,10 +111,10 @@ User.init(
|
||||||
type: DataTypes.TINYINT,
|
type: DataTypes.TINYINT,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
payment_plan_status: {
|
/*payment_plan_status: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
}, */
|
||||||
payment_plan_trial_end: {
|
payment_plan_trial_end: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
|
|
|
@ -89,11 +89,18 @@ export const ACCOUNT_EXPORT_URL = `${DASHBOARD_URL}/api/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 {
|
export enum PAYMENT_PLAN {
|
||||||
BASIC = 0,
|
DEMO = 0,
|
||||||
PREMIUM = 1,
|
BASIC = 1,
|
||||||
|
PREMIUM = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PAYMENT_PLAN_SETTINGS = [
|
export const PAYMENT_PLAN_SETTINGS = [
|
||||||
|
{
|
||||||
|
id: "demo", // used in the backend for identifiying the stripe pricing product
|
||||||
|
name: "Demo", // used in the frontend
|
||||||
|
maxEmployees: 5,
|
||||||
|
calendarMaxFutureBookingDays: 7,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "basic", // used in the backend for identifiying the stripe pricing product
|
id: "basic", // used in the backend for identifiying the stripe pricing product
|
||||||
name: "Basic", // used in the frontend
|
name: "Basic", // used in the frontend
|
||||||
|
|
Loading…
Reference in New Issue