account demo
parent
a49d035e80
commit
989e3a47ba
|
@ -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
|
||||
|
|
|
@ -30,6 +30,7 @@ class User extends Model<UserAttributes> implements UserAttributes {
|
|||
declare language: string;
|
||||
declare state: number;
|
||||
declare analytics_enabled: boolean;
|
||||
declare created_at: Date;
|
||||
}
|
||||
|
||||
User.init(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue