From 989e3a47ba8c2aed9bf378a989773953739336f4 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 4 Feb 2024 20:18:17 +0100 Subject: [PATCH] account demo --- src/controllers/userController.ts | 33 ++++++++++++++++++++++++++++++- src/models/user.ts | 1 + src/utils/constants.ts | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index f40d82b..0622e18 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -10,6 +10,7 @@ import { isUsernameValid, } from "../validator/validator"; import { + ACCOUNT_DEMO_DAYS, ACCOUNT_STATE, CALENDAR_MAX_FUTURE_BOOKING_DAYS, CALENDAR_MAX_SERVICE_DURATION, @@ -284,6 +285,7 @@ export async function GetUser(req: Request, res: Response) { "store_id", "language", "analytics_enabled", + "created_at", ], }); @@ -298,8 +300,16 @@ export async function GetUser(req: Request, res: Response) { attributes: ["store_id", "name"], }); + // send user data + let respData = { - user: user, + user: { + user_id: user.user_id, + username: user.username, + //store_id: user.store_id, + language: user.language, + analytics_enabled: user.analytics_enabled, + }, stores: stores, // only temporary until we have a proper permissions system permissions: [] as string[], @@ -307,6 +317,7 @@ export async function GetUser(req: Request, res: Response) { // if user is not a store master, then check if user is a worker if (!stores || stores.length === 0) { + // user is a worker const store = await Store.findOne({ where: { store_id: user.store_id, @@ -324,6 +335,7 @@ export async function GetUser(req: Request, res: Response) { respData.permissions.push("calendar"); } else { + // user is a store owner respData.permissions.push( "settings", "employees", @@ -331,6 +343,25 @@ export async function GetUser(req: Request, res: Response) { "calendar", "website" ); + + // calc account plan expiry by created_at + demo days + + const accountPlanExpiry = new Date(user.created_at); + + accountPlanExpiry.setDate( + accountPlanExpiry.getDate() + ACCOUNT_DEMO_DAYS + ); + + respData.user = { + ...respData.user, + account_plan_expiry: accountPlanExpiry, + } as { + user_id: string; + username: string; + language: string; + analytics_enabled: boolean; + account_plan_expiry: Date; + }; } // update user session last_used diff --git a/src/models/user.ts b/src/models/user.ts index 84c9fb1..700baf6 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -30,6 +30,7 @@ class User extends Model implements UserAttributes { declare language: string; declare state: number; declare analytics_enabled: boolean; + declare created_at: Date; } User.init( diff --git a/src/utils/constants.ts b/src/utils/constants.ts index fe35eb1..0fe9959 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -65,3 +65,5 @@ export const Roles = { // worker of a store belonging to a master Worker: "worker", }; + +export const ACCOUNT_DEMO_DAYS = 30; // how many days a demo account is valid until payment is required or account will be deleted