diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/package.json b/package.json index c4b7f97..3820232 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "npx tsc", "start": "node build/server.js", - "dev": "concurrently \"npx tsc --watch\" \"nodemon --ignore ./tmp/ --ignore ./customer-websites/ --ignore ./user-profile-exports/ -q build/server.js | pino-pretty\"" + "dev": "concurrently \"npx tsc --watch\" \"nodemon --ignore ./user-profile-exports/ -q build/server.js | pino-pretty\"" }, "author": "", "license": "ISC", diff --git a/server.ts b/server.ts index 8d51103..0e6c764 100644 --- a/server.ts +++ b/server.ts @@ -13,7 +13,6 @@ import storeRoutes from "./src/routes/storeRoutes"; import storeServicesRoutes from "./src/routes/storeServicesRoutes"; import userRoutes from "./src/routes/userRoutes"; import usersRoutes from "./src/routes/usersRoutes"; -//import websiteRoutes from "./src/routes/websiteRoutes"; dotenv.config(); @@ -23,7 +22,6 @@ import logger from "./src/logger/logger"; import passport from "passport"; import rabbitmq from "./src/rabbitmq/rabbitmq"; import { GOOGLE_CALLBACK_URL } from "./src/utils/constants"; -//import { cloneWebsiteTemplate } from "./src/controllers/websiteController"; const app: Express = express(); const host = process.env.HOST || "localhost"; const port = Number(process.env.PORT) || 3000; @@ -117,7 +115,6 @@ app.use("/api/v1/store", storeRoutes); app.use("/api/v1/store/services", storeServicesRoutes); app.use("/api/v1/user", userRoutes); app.use("/api/v1/users", usersRoutes); -//app.use("/api/v1/website", websiteRoutes); const specs = swaggerJsDoc(options); app.use("/api-docs", swaggerUI.serve, swaggerUI.setup(specs)); @@ -134,27 +131,6 @@ app.use((err: any, req: any, res: any, next: any) => { syncModels(); -// create tmp folder if not exists -/* -[ - process.env.WEBSITE_BUILDER_TMP_DIR as string, - process.env.WEBSITE_BUILDER_TMP_CUSTOMER_WEBSITES_DIR as string, -].forEach((dir) => { - fs.mkdir(dir, { recursive: true }, (err) => { - if (err) throw err; - }); -}); - -// clone website template if not exists - -if ( - !fs.pathExistsSync( - process.env.WEBSITE_BUILDER_TMP_DIR_WEBSITE_TEMPLATE as string - ) -) { - cloneWebsiteTemplate(); -} -*/ // start server rabbitmq diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index 89dfbcd..8f8db77 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -367,8 +367,7 @@ export async function GetUser(req: Request, res: Response) { "settings", "employees", "services", - "calendar", - "website" + "calendar" ); // calc account plan expiry by created_at + demo days diff --git a/src/controllers/websiteController.ts b/src/controllers/websiteController.ts deleted file mode 100644 index 244e66b..0000000 --- a/src/controllers/websiteController.ts +++ /dev/null @@ -1,162 +0,0 @@ -/*import { Request, Response } from "express"; -import logger from "../logger/logger"; -import util from "util"; -import { exec } from "child_process"; -import fs from "fs-extra"; -import Website from "../models/website"; -import Store from "../models/store"; - -const execPromise = util.promisify(exec); - -// this is a webhook that will be called by github when a new commit is pushed to the website template repository -export async function UpdateTemplateWebhook(req: Request, res: Response) { - try { - await cloneWebsiteTemplate(); - - res.status(200).send({ message: "ok" }); - } catch (error) { - console.log("error", error); - res.status(500).send({ error: "invalid request" }); - } -} - -export async function cloneWebsiteTemplate() { - let tmpDirWebsiteTemplate = process.env - .WEBSITE_BUILDER_TMP_DIR_WEBSITE_TEMPLATE as string; - - // if website folder exists, pull, else clone - - if (await fs.pathExists(tmpDirWebsiteTemplate)) { - let { stdout } = await execPromise(`git pull`, { - cwd: tmpDirWebsiteTemplate, - }); - - console.debug(stdout); - } else { - let { stdout } = await execPromise( - `git clone ${process.env.WEBSITE_BUILDER_TEMPLATE_REPOSITORY_URL} ${tmpDirWebsiteTemplate}` - ); - - console.debug(stdout); - } - - // execute npm install - - let { stdout: installOutput } = await execPromise(`npm install`, { - cwd: tmpDirWebsiteTemplate, - }); - - console.debug(installOutput); - console.debug("website template cloned"); -} - -export async function CreateWebsite(req: Request, res: Response) { - try { - let { storeId } = req.body; - - // validate request - - if (!storeId) { - res.status(400).send({ error: "invalid request" }); - return; - } - - // check if website already exists - - const websiteExists = await Website.findOne({ - where: { - store_id: storeId, - }, - }); - - if (websiteExists) { - res.status(409).send({ error: "website already exists" }); - return; - } - - // get store name - - const store = await Store.findOne({ - where: { - store_id: storeId, - }, - attributes: ["name"], - }); - - if (!store) { - res.status(404).send({ error: "store not found" }); - return; - } - - const storeName = store.name.toLowerCase().replace(/ /g, "-"); - - const tmpDirWebsiteTemplate = process.env - .WEBSITE_BUILDER_TMP_DIR_WEBSITE_TEMPLATE as string; - const tmpDirCustomerWebsite = `${process.env.WEBSITE_BUILDER_TMP_DIR}/${storeName}`; - const customerWebsiteDir = `${process.env.WEBSITE_BUILDER_TMP_CUSTOMER_WEBSITES_DIR}/${storeName}`; - - // check if website template folder exists - - if (!(await fs.pathExists(tmpDirWebsiteTemplate))) { - logger.error("Website template folder does not exist. Clone it first."); - res.status(500).send({ error: "invalid request" }); - return; - } - - // copy website-template folder to customer website folder - await fs.copy(tmpDirWebsiteTemplate, tmpDirCustomerWebsite); - - // TODO: add config file - - // run npm build - - let { stdout: buildOutput } = await execPromise(`npm run build`, { - cwd: tmpDirCustomerWebsite, - }); - - console.debug(buildOutput); - - // copy the build folder to customer websites folder - - await fs.copy(`${tmpDirCustomerWebsite}/build`, customerWebsiteDir); - - // remove tmp folder - - await fs.remove(tmpDirCustomerWebsite); - - // create database record - - await Website.create({ - website_id: storeName, - store_id: storeId, - }); - - res.status(200).send({ message: "oks" }); - } catch (error) { - console.log("error", error); - res.status(500).send({ error: "invalid request" }); - } -} - -export async function GetWebsite(req: Request, res: Response) { - try { - const { storeId } = req.params; - - const website = await Website.findOne({ - where: { - store_id: storeId, - }, - }); - - if (!website) { - res.status(404).send({ error: "website not found" }); - return; - } - - res.status(200).json({ message: "ok" }); - } catch (error) { - console.log("error", error); - res.status(500).send({ error: "invalid request" }); - } -} -*/ diff --git a/src/models/index.ts b/src/models/index.ts index 782474a..5a6ffe1 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -6,7 +6,6 @@ import StoreService from "./storeService"; import StoreServiceActivity from "./storeServiceActivity"; import StoreServiceActivityUsers from "./storeServiceActivityUsers"; import User from "./user"; -import Website from "./website"; function syncModels() { EmailVerification.sync(); @@ -16,7 +15,6 @@ function syncModels() { StoreService.sync(); StoreServiceActivity.sync(); StoreServiceActivityUsers.sync(); - Website.sync(); Feedback.sync(); // UserGoogleTokens.sync(); not needed as it is created by the calendar backend diff --git a/src/models/website.ts b/src/models/website.ts deleted file mode 100644 index 51a6d5a..0000000 --- a/src/models/website.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { DataTypes, Model } from "sequelize"; -import sequelize from "../database/database"; - -interface WebsiteAttributes { - website_id: string; - store_id: string; -} - -class Website extends Model implements WebsiteAttributes { - declare website_id: string; - declare store_id: string; -} - -Website.init( - { - website_id: { - type: DataTypes.STRING, - primaryKey: true, - }, - store_id: { - type: DataTypes.STRING, - allowNull: false, - }, - }, - { - sequelize, - tableName: "websites", - createdAt: "created_at", - updatedAt: "updated_at", - } -); - -export default Website; diff --git a/src/routes/websiteRoutes.ts b/src/routes/websiteRoutes.ts deleted file mode 100644 index 0c76831..0000000 --- a/src/routes/websiteRoutes.ts +++ /dev/null @@ -1,14 +0,0 @@ -/*import express from "express"; -const router = express.Router(); - -import * as websiteController from "../controllers/websiteController"; - -router.post( - "/update-template-webhook", - websiteController.UpdateTemplateWebhook -); -router.post("/", websiteController.CreateWebsite); -router.get("/:storeId", websiteController.GetWebsite); - -export default router; -*/ diff --git a/src/validator/validator.ts b/src/validator/validator.ts index 7411219..459ac7a 100644 --- a/src/validator/validator.ts +++ b/src/validator/validator.ts @@ -142,12 +142,6 @@ export function isCalendarMaxFutureBookingDaysValid( calendarMaxFutureBookingDays: number, paymentPlan: number ) { - console.log( - PAYMENT_PLAN_SETTINGS[paymentPlan].calendarMaxFutureBookingDays, - PAYMENT_PLAN_SETTINGS[paymentPlan].calendarMaxFutureBookingDays >= - calendarMaxFutureBookingDays - ); - return ( PAYMENT_PLAN_SETTINGS[paymentPlan].calendarMaxFutureBookingDays >= calendarMaxFutureBookingDays