Skip to content

Commit

Permalink
add chat routes
Browse files Browse the repository at this point in the history
  • Loading branch information
sevelinCa committed Jul 17, 2024
1 parent 7118ae8 commit ec77c0f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 122 deletions.
13 changes: 0 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/controllers/product.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Request, Response } from "express";

import { saveProduct, searchProducts, getAllProducts, getProductById, fetchSimilarProducts } from "../services/productService";
import Product from "../database/models/product";
import CartItem from "../database/models/cartitem";

import { checkVendorModifyPermission, checkVendorPermission } from "../services/PermisionService";
import { PRODUCT_ADDED, PRODUCT_REMOVED, PRODUCT_UPDATED, productLifecycleEmitter } from "../helpers/events";
import Vendor from "../database/models/vendor";
Expand Down Expand Up @@ -33,6 +31,7 @@ export const createProduct = async (req: Request, res: Response) => {
category,
expiringDate,
} = req.body;
console.log(image)
if (!name || !image || !description || !price || !quantity || !category) {
return res.status(200).json("All Field are required");
}
Expand All @@ -41,11 +40,11 @@ export const createProduct = async (req: Request, res: Response) => {
return res.status(400).json({ message: "Exactly 4 images are required" });
}

const imageArray: string[] = image;


const data = {
name,
images: imageArray,
image: image,
description,
discount: discount ? discount : 0,
price,
Expand Down
78 changes: 26 additions & 52 deletions src/database/config/config.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,37 @@
// require("dotenv").config();
require("dotenv").config();

// const config = {
// development: {
// url: process.env.DATABASE_DEVELOPMENT_URL,
// dialect: "postgres",
// dialectOptions: {
// ssl: {
// require: true,
// rejectUnauthorized: true,
// }
// }
// },
// test: {
// url: process.env.DATABASE_TEST_URL,
// dialect: "postgres",
// dialectOptions: {
// ssl: {
// require: true,
// rejectUnauthorized: true,
// }
// }
// },
// production: {
// url: process.env.DATABASE_PRODUCTION_URL,
// dialect: "postgres",
// dialectOptions: {
// ssl: {
// require: true,
// rejectUnauthorized: true,
// }
// }
// },
// };

// module.exports = config;

const dotenv = require("dotenv");
dotenv.config();

module.exports = {
const config = {
development: {
username: process.env.DB_USERNAME || "postgres",
password: process.env.DB_PASSWORD || "",
database: process.env.DB_NAME || "postgres",
host: process.env.DB_HOST || "127.0.0.1",
url: process.env.DATABASE_DEVELOPMENT_URL,
dialect: "postgres",
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: true,
}
}
},
test: {
username: process.env.DB_USERNAME || "postgres",
password: process.env.DB_PASSWORD || "",
database: process.env.DB_NAME || "postgres",
host: process.env.DB_HOST || "127.0.0.1",
url: process.env.DATABASE_TEST_URL,
dialect: "postgres",
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: true,
}
}
},
production: {
username: process.env.DB_USERNAME || "postgres",
password: process.env.DB_PASSWORD || "",
database: process.env.DB_NAME || "postgres",
host: process.env.DB_HOST || "127.0.0.1",
url: process.env.DATABASE_PRODUCTION_URL,
dialect: "postgres",
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: true,
}
}
},
};

module.exports = config;

86 changes: 33 additions & 53 deletions src/database/config/db.config.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,38 @@
// import { config } from "dotenv";
// import { Sequelize } from "sequelize";

// config();
// const NODE_ENV: string = process.env.NODE_ENV || "development";
// const HOST_MODE: string = process.env.HOST_MODE || "remote";

// function getURL(): string {
// switch (NODE_ENV) {
// case "development":
// return process.env.DATABASE_DEVELOPMENT_URL as string;
// case "test":
// return process.env.DATABASE_TEST_URL as string;
// default:
// return process.env.DATABASE_PRODUCTION_URL as string;
// }
// }

// function getDialectOptions() {
// return HOST_MODE === "local"
// ? {}
// : {
// ssl: {
// require: true,
// rejectUnauthorized: false,
// },
// };
// }

// const connectSequelize: Sequelize = new Sequelize(getURL(), {
// dialect: "postgres",
// dialectOptions: getDialectOptions(),
// logging: false,
// });

// export default connectSequelize;

import { config } from "dotenv";
import { Sequelize } from "sequelize";
const config = require("./config");
import dotenv from "dotenv";
dotenv.config();

const MODE: any = process.env.MODE || "development";

const currentConfig = config[`${MODE}`];

const connectSequelize: Sequelize = new Sequelize(
currentConfig.database,
currentConfig.username,
currentConfig.password,
{
host: currentConfig.host,
dialect: currentConfig.dialect,
dialectOptions: {},
config();
const NODE_ENV: string = process.env.NODE_ENV || "development";
const HOST_MODE: string = process.env.HOST_MODE || "remote";

function getURL(): string {
switch (NODE_ENV) {
case "development":
return process.env.DATABASE_DEVELOPMENT_URL as string;
case "test":
return process.env.DATABASE_TEST_URL as string;
default:
return process.env.DATABASE_PRODUCTION_URL as string;
}
);
}

function getDialectOptions() {
return HOST_MODE === "local"
? {}
: {
ssl: {
require: true,
rejectUnauthorized: false,
},
};
}

const connectSequelize: Sequelize = new Sequelize(getURL(), {
dialect: "postgres",
dialectOptions: getDialectOptions(),
logging: false,
});

export default connectSequelize;


0 comments on commit ec77c0f

Please sign in to comment.