account demo
parent
a49d035e80
commit
989e3a47ba
|
@ -10,6 +10,7 @@ import {
|
||||||
isUsernameValid,
|
isUsernameValid,
|
||||||
} from "../validator/validator";
|
} from "../validator/validator";
|
||||||
import {
|
import {
|
||||||
|
ACCOUNT_DEMO_DAYS,
|
||||||
ACCOUNT_STATE,
|
ACCOUNT_STATE,
|
||||||
CALENDAR_MAX_FUTURE_BOOKING_DAYS,
|
CALENDAR_MAX_FUTURE_BOOKING_DAYS,
|
||||||
CALENDAR_MAX_SERVICE_DURATION,
|
CALENDAR_MAX_SERVICE_DURATION,
|
||||||
|
@ -284,6 +285,7 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
"store_id",
|
"store_id",
|
||||||
"language",
|
"language",
|
||||||
"analytics_enabled",
|
"analytics_enabled",
|
||||||
|
"created_at",
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -298,8 +300,16 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
attributes: ["store_id", "name"],
|
attributes: ["store_id", "name"],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// send user data
|
||||||
|
|
||||||
let respData = {
|
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,
|
stores: stores,
|
||||||
// only temporary until we have a proper permissions system
|
// only temporary until we have a proper permissions system
|
||||||
permissions: [] as string[],
|
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 user is not a store master, then check if user is a worker
|
||||||
if (!stores || stores.length === 0) {
|
if (!stores || stores.length === 0) {
|
||||||
|
// user is a worker
|
||||||
const store = await Store.findOne({
|
const store = await Store.findOne({
|
||||||
where: {
|
where: {
|
||||||
store_id: user.store_id,
|
store_id: user.store_id,
|
||||||
|
@ -324,6 +335,7 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
|
|
||||||
respData.permissions.push("calendar");
|
respData.permissions.push("calendar");
|
||||||
} else {
|
} else {
|
||||||
|
// user is a store owner
|
||||||
respData.permissions.push(
|
respData.permissions.push(
|
||||||
"settings",
|
"settings",
|
||||||
"employees",
|
"employees",
|
||||||
|
@ -331,6 +343,25 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
"calendar",
|
"calendar",
|
||||||
"website"
|
"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
|
// update user session last_used
|
||||||
|
|
|
@ -30,6 +30,7 @@ class User extends Model<UserAttributes> implements UserAttributes {
|
||||||
declare language: string;
|
declare language: string;
|
||||||
declare state: number;
|
declare state: number;
|
||||||
declare analytics_enabled: boolean;
|
declare analytics_enabled: boolean;
|
||||||
|
declare created_at: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
User.init(
|
User.init(
|
||||||
|
|
|
@ -65,3 +65,5 @@ export const Roles = {
|
||||||
// worker of a store belonging to a master
|
// worker of a store belonging to a master
|
||||||
Worker: "worker",
|
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