diff --git a/package-lock.json b/package-lock.json index f7b5e5f..53438f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "otpauth": "^9.2.4", "passport": "^0.7.0", "passport-google-oauth20": "^2.0.0", - "pg": "^8.11.5", + "pg": "^8.12.0", "pg-hstore": "^2.3.4", "pusher": "^5.2.0", "sequelize": "^6.37.3", @@ -1603,7 +1603,6 @@ "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.12.tgz", "integrity": "sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==", "dev": true, - "license": "MIT", "dependencies": { "expect": "^29.0.0", "pretty-format": "^29.0.0" @@ -1645,11 +1644,10 @@ "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==" }, "node_modules/@types/mocha": { - "version": "10.0.6", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz", - "integrity": "sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==", - "dev": true, - "license": "MIT" + "version": "10.0.7", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.7.tgz", + "integrity": "sha512-GN8yJ1mNTcFcah/wKEFIJckJx9iJLoMSzWcfRRuxz/Jk+U6KQNnml+etbtxFK8lPjzOw3zp4Ha/kjSst9fsHYw==", + "dev": true }, "node_modules/@types/ms": { "version": "0.7.34", @@ -2329,13 +2327,12 @@ } }, "node_modules/braces": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", - "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", "dev": true, - "license": "MIT", "dependencies": { - "fill-range": "^7.1.1" + "fill-range": "^7.0.1" }, "engines": { "node": ">=8" @@ -3556,11 +3553,10 @@ } }, "node_modules/fill-range": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", - "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", "dev": true, - "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -4213,7 +4209,6 @@ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true, - "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -5603,10 +5598,9 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, "node_modules/mysql2": { - "version": "3.10.0", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.10.0.tgz", - "integrity": "sha512-qx0mfWYt1DpTPkw8mAcHW/OwqqyNqBLBHvY5IjN8+icIYTjt6znrgYJ+gxqNNRpVknb5Wc/gcCM4XjbCR0j5tw==", - "license": "MIT", + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.9.7.tgz", + "integrity": "sha512-KnJT8vYRcNAZv73uf9zpXqNbvBG7DJrs+1nACsjZP1HMJ1TgXEy8wnNilXAn/5i57JizXKtrUtwDB7HxT9DDpw==", "dependencies": { "denque": "^2.1.0", "generate-function": "^2.3.1", @@ -5745,9 +5739,9 @@ "dev": true }, "node_modules/node-mocks-http": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/node-mocks-http/-/node-mocks-http-1.14.1.tgz", - "integrity": "sha512-mfXuCGonz0A7uG1FEjnypjm34xegeN5+HI6xeGhYKecfgaZhjsmYoLE9LEFmT+53G1n8IuagPZmVnEL/xNsFaA==", + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/node-mocks-http/-/node-mocks-http-1.15.0.tgz", + "integrity": "sha512-3orGBAxXrnwz3ixU8AZpa0x8srAvVSHvbWanAqd5F0zVCVA2QstxaVcTSarFcjz4+pFSnR1zm28MsV83s/BtmA==", "dependencies": { "@types/express": "^4.17.21", "@types/node": "^20.10.6", @@ -8585,9 +8579,9 @@ "integrity": "sha512-KG8UEiEVkR3wGEb4m5yZkVCzigAD+cVEJck2CzYZO37ZGJfctvVptVO192MwrtPhzONn6go8ylnOdMhKqi4nfg==" }, "node_modules/pg": { - "version": "8.11.5", - "resolved": "https://registry.npmjs.org/pg/-/pg-8.11.5.tgz", - "integrity": "sha512-jqgNHSKL5cbDjFlHyYsCXmQDrfIX/3RsNwYqpd4N0Kt8niLuNoRNH+aazv6cOd43gPh9Y4DjQCtb+X0MH0Hvnw==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.12.0.tgz", + "integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==", "dependencies": { "pg-connection-string": "^2.6.4", "pg-pool": "^3.6.2", @@ -10019,7 +10013,6 @@ "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, - "license": "MIT", "dependencies": { "is-number": "^7.0.0" }, @@ -10058,9 +10051,9 @@ "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, "node_modules/ts-jest": { - "version": "29.1.4", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.4.tgz", - "integrity": "sha512-YiHwDhSvCiItoAgsKtoLFCuakDzDsJ1DLDnSouTaTmdOcOwIkSzbLXduaQ6M5DRVhuZC/NYaaZ/mtHbWMv/S6Q==", + "version": "29.1.5", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.5.tgz", + "integrity": "sha512-UuClSYxM7byvvYfyWdFI+/2UxMmwNyJb0NPkZPQE2hew3RurV7l7zURgOHAd/1I1ZdPpe3GUsXNXAcN8TFKSIg==", "dev": true, "dependencies": { "bs-logger": "0.x", diff --git a/src/controllers/Chat.controller.ts b/src/controllers/Chat.controller.ts index 7f7c610..85e100d 100644 --- a/src/controllers/Chat.controller.ts +++ b/src/controllers/Chat.controller.ts @@ -138,4 +138,4 @@ export const getLatestMessages = async (req: Request, res: Response) => { } catch (error: any) { res.status(500).json({ error: error.message }); } -}; \ No newline at end of file +}; diff --git a/src/controllers/analyticController.ts b/src/controllers/analyticController.ts index 35eb572..2f6b3f6 100644 --- a/src/controllers/analyticController.ts +++ b/src/controllers/analyticController.ts @@ -2,8 +2,6 @@ import { Request, Response } from "express"; import Order from "../database/models/order"; import Product from "../database/models/product"; - - //Annual selling report for Vendor export const annualSellingReport = async (req: Request, res: Response) => { @@ -24,6 +22,7 @@ export const annualSellingReport = async (req: Request, res: Response) => { products.push({ productId: single_product.productId, name: single_product.name, + image: single_product.image[0], quantity: data.quantity, price: single_product.price, date: new Date(order.createdAt), @@ -33,7 +32,12 @@ export const annualSellingReport = async (req: Request, res: Response) => { } const productRevenueMap: { - [key: string]: { productId: string; name: string; totalRevenue: number }; + [key: string]: { + productId: string; + image: string; + name: string; + totalRevenue: number; + }; } = {}; for (const prod of products) { @@ -41,6 +45,7 @@ export const annualSellingReport = async (req: Request, res: Response) => { productRevenueMap[prod.productId] = { productId: prod.productId, name: prod.name, + image: prod.image, totalRevenue: 0, }; } @@ -52,8 +57,6 @@ export const annualSellingReport = async (req: Request, res: Response) => { .sort((a, b) => b.totalRevenue - a.totalRevenue) .slice(0, 5); - const currentMonth = new Date().getMonth(); - const monthlySales = Array(12).fill(0); for (const prod of products) { const month = prod.date.getMonth(); @@ -62,14 +65,14 @@ export const annualSellingReport = async (req: Request, res: Response) => { const formattedSales = monthlySales.map((totalSales, index) => { const commissionFee = 0.1; - const income = totalSales - totalSales * commissionFee; + const income = totalSales - (totalSales - totalSales * commissionFee); const currentYear = new Date().getFullYear(); return { month: new Date(currentYear, index).toLocaleString("default", { month: "long", }), - totalSales: index <= currentMonth ? totalSales : 0, - income: index <= currentMonth ? income : 0, + totalSales, + income, }; }); @@ -83,8 +86,6 @@ export const annualSellingReport = async (req: Request, res: Response) => { } }; - - //Annual selling report for Admin export const overallAnnualSellingReport = async ( @@ -108,6 +109,7 @@ export const overallAnnualSellingReport = async ( products.push({ productId: data.productId, name: single_product.name, + image: single_product.image[0], quantity: data.quantity, price: single_product.price, date: new Date(order.createdAt), @@ -116,9 +118,14 @@ export const overallAnnualSellingReport = async ( } } -//Finding top products + //Finding top products const productRevenueMap: { - [key: string]: { productId: string; name: string; totalRevenue: number }; + [key: string]: { + productId: string; + name: string; + image: string; + totalRevenue: number; + }; } = {}; for (const prod of products) { @@ -126,6 +133,7 @@ export const overallAnnualSellingReport = async ( productRevenueMap[prod.productId] = { productId: prod.productId, name: prod.name, + image: prod.image, totalRevenue: 0, }; } @@ -136,10 +144,8 @@ export const overallAnnualSellingReport = async ( const topProducts = Object.values(productRevenueMap) .sort((a, b) => b.totalRevenue - a.totalRevenue) .slice(0, 4); - - //monthly total sales - const currentMonth = new Date().getMonth(); + //monthly total sales const monthlySales = Array(12).fill(0); for (const prod of products) { @@ -149,14 +155,14 @@ export const overallAnnualSellingReport = async ( const formattedSales = monthlySales.map((totalSales, index) => { const commissionFee = 0.1; - const income = totalSales * commissionFee; + const income = totalSales - (totalSales - totalSales * commissionFee); const currentYear = new Date().getFullYear(); return { month: new Date(currentYear, index).toLocaleString("default", { month: "long", }), - totalSales: index <= currentMonth ? totalSales : 0, - income: index <= currentMonth ? income : 0, + totalSales, + income, }; }); @@ -171,7 +177,6 @@ export const overallAnnualSellingReport = async ( } }; - //weekly selling report for Vendor export const WeeklySellingReport = async (req: Request, res: Response) => { @@ -191,6 +196,7 @@ export const WeeklySellingReport = async (req: Request, res: Response) => { if (single_product?.vendorId === vendorId) { products.push({ productId: single_product.productId, + product: single_product.name, quantity: data.quantity, price: single_product.price, date: new Date(order.createdAt), @@ -208,20 +214,33 @@ export const WeeklySellingReport = async (req: Request, res: Response) => { "Friday", "Saturday", ]; - const currentDay = new Date().getDay(); + + const currentDate = new Date(); + const currentDay = currentDate.getDay(); + + // Get the start and end date of the current week + const startOfWeek = new Date(currentDate); + startOfWeek.setDate(currentDate.getDate() - currentDay); + startOfWeek.setHours(0, 0, 0, 0); + + const endOfWeek = new Date(currentDate); + endOfWeek.setDate(currentDate.getDate() + (6 - currentDay)); + endOfWeek.setHours(23, 59, 59, 999); + const dailySales = Array(7).fill(0); for (const prod of products) { - const day = prod.date.getDay(); - dailySales[day] += prod.price * prod.quantity; + const prodDate = new Date(prod.date); + if (prodDate >= startOfWeek && prodDate <= endOfWeek) { + const day = prodDate.getDay(); + dailySales[day] += prod.price * prod.quantity; + } } - const formattedSales = dailySales.map((totalSales, index) => { - return { - day: daysOfWeek[index], - totalSales: index <= currentDay ? totalSales : 0, - }; - }); + const formattedSales = dailySales.map((totalSales, index) => ({ + day: daysOfWeek[index], + totalSales: index <= currentDay ? totalSales : 0, + })); res.status(200).json({ data: products, weeklySales: formattedSales }); } catch (error: any) { @@ -229,15 +248,16 @@ export const WeeklySellingReport = async (req: Request, res: Response) => { } }; - //weekly selling report for admin -export const OverallWeeklySellingReport = async (req: Request, res: Response) => { +export const OverallWeeklySellingReport = async ( + req: Request, + res: Response +) => { try { - const orders: any = await Order.findAll(); - if (!orders) { - return res.status(404).json({ message: "No order found" }); + if (!orders || orders.length === 0) { + return res.status(404).json({ message: "No orders found" }); } const products: any[] = []; @@ -250,12 +270,36 @@ export const OverallWeeklySellingReport = async (req: Request, res: Response) => products.push({ productId: data.productId, quantity: data.quantity, + name: single_product?.name, price: single_product?.price, date: new Date(order.createdAt), }); } } + // Calculate start and end of the current week (Monday to Sunday) + const currentDate = new Date(); + const currentDay = currentDate.getDay(); + + const startOfWeek = new Date(currentDate); + startOfWeek.setDate( + currentDate.getDate() - currentDay + (currentDay === 0 ? -6 : 1) + ); + + const endOfWeek = new Date(startOfWeek); + endOfWeek.setDate(startOfWeek.getDate() + 6); + endOfWeek.setHours(23, 59, 59, 999); + startOfWeek.setHours(0, 0, 0, 0); + + const dailySales = Array(7).fill(0); + + for (const prod of products) { + const prodDate = new Date(prod.date); + if (prodDate >= startOfWeek && prodDate <= endOfWeek) { + const dayOfWeek = prodDate.getDay(); + dailySales[dayOfWeek] += prod.price * prod.quantity; + } + } const daysOfWeek = [ "Sunday", @@ -266,20 +310,11 @@ export const OverallWeeklySellingReport = async (req: Request, res: Response) => "Friday", "Saturday", ]; - const currentDay = new Date().getDay(); - const dailySales = Array(7).fill(0); - for (const prod of products) { - const day = prod.date.getDay(); - dailySales[day] += prod.price * prod.quantity; - } - - const formattedSales = dailySales.map((totalSales, index) => { - return { - day: daysOfWeek[index], - totalSales: index <= currentDay ? totalSales : 0, - }; - }); + const formattedSales = dailySales.map((totalSales, index) => ({ + day: daysOfWeek[index], + totalSales: index <= currentDay ? totalSales : 0, + })); res.status(200).json({ data: products, weeklySales: formattedSales }); } catch (error: any) { diff --git a/src/controllers/cart.controller.ts b/src/controllers/cart.controller.ts index f7dc4d4..4c0d58c 100644 --- a/src/controllers/cart.controller.ts +++ b/src/controllers/cart.controller.ts @@ -71,6 +71,7 @@ export const getCart = async (req: Request, res: Response) => { as: "Product" } }); + return res.status(200).json({ cartitem }); } catch (error: any) { console.log(error); diff --git a/src/controllers/checkout.controller.ts b/src/controllers/checkout.controller.ts index c8bc07a..6edd612 100644 --- a/src/controllers/checkout.controller.ts +++ b/src/controllers/checkout.controller.ts @@ -29,6 +29,7 @@ export const createOrder = async (req: Request, res: Response) => { })); const totalAmount = orderItems.reduce((total, item) => total + (item.price * item.quantity), 0); + console.log(orderItems) const order = await Order.create({ orderId: uuidv4(), diff --git a/src/controllers/orderController.ts b/src/controllers/orderController.ts index e98a008..ac6fdef 100644 --- a/src/controllers/orderController.ts +++ b/src/controllers/orderController.ts @@ -1,7 +1,12 @@ import { Request, Response } from "express"; import Order from "../database/models/order"; import { findVendorByUserId } from "../services/orderStatus"; + +import Vendor from "../database/models/vendor"; + import Product from "../database/models/product"; +import User from "../database/models/user"; +import { userInfo } from "os"; const allowedStatuses = ["pending", "delivered", "cancelled"]; @@ -61,10 +66,8 @@ export const modifyOrderStatus = async (req: Request, res: Response) => { } }; - - -export const getAllOrders = async (req:Request, res: Response) => { - try{ +export const getAllOrders = async (req: Request, res: Response) => { + try { const userId = (req as any).token.id; const vendorId = req.params.vendorId; @@ -95,8 +98,7 @@ export const getAllOrders = async (req:Request, res: Response) => { console.error(error); return res.status(500).json({ error: error.message}) } -} - +}; export const getAllOrder = async (req: Request, res: Response) => { try { @@ -109,19 +111,26 @@ export const getAllOrder = async (req: Request, res: Response) => { } }; -export const getOrder = async(req: Request, res: Response) => { - try{ - +export const getOrder = async (req: Request, res: Response) => { + try { const orderId: string = req.params.orderId; const order = await Order.findByPk(orderId); - if (!order){ - return res.status(404).json({ error: "Order not found"}); + if (!order) { + return res.status(404).json({ error: "Order not found" }); } return res.status(200).json(order); - } catch(err: any){ - return res.status(500).json({ error: err.message}) + } catch (err: any) { + return res.status(500).json({ error: err.message }); } -} +}; + +export const getSellerOrder = async (req: Request, res: Response) => { + try { + const vendorId = req.params.vendorId; + const orders: any = await Order.findAll(); + if (!orders) { + return res.status(404).json({ message: "No order found" }); + } export const getSellerOrder = async (req: Request, res: Response) => { try { @@ -149,4 +158,3 @@ export const getSellerOrder = async (req: Request, res: Response) => { res.status(500).json({ message: "Internal error server" }); } }; - diff --git a/src/controllers/user.controller.ts b/src/controllers/user.controller.ts index 17d77a1..20feceb 100644 --- a/src/controllers/user.controller.ts +++ b/src/controllers/user.controller.ts @@ -485,4 +485,4 @@ export const getUserInfo = async(req: Request, res: Response) => { } catch(error: any){ return res.status(500).json({ error: error.message}); } - } \ No newline at end of file + } diff --git a/src/database/config/config.js b/src/database/config/config.js index 01ddaa7..79c606d 100644 --- a/src/database/config/config.js +++ b/src/database/config/config.js @@ -4,12 +4,7 @@ const config = { development: { url: process.env.DATABASE_DEVELOPMENT_URL, dialect: "postgres", - dialectOptions: { - ssl: { - require: true, - rejectUnauthorized: true, - } - } + }, test: { url: process.env.DATABASE_TEST_URL, diff --git a/src/database/config/db.config.ts b/src/database/config/db.config.ts index 4ada04c..6962d82 100644 --- a/src/database/config/db.config.ts +++ b/src/database/config/db.config.ts @@ -33,7 +33,6 @@ const connectSequelize: Sequelize = new Sequelize(getURL(), { logging: false, }); - export default connectSequelize; diff --git a/src/database/migrations/20240520142627-create-order.js b/src/database/migrations/20240520142627-create-order.js index 1022cce..224a94b 100644 --- a/src/database/migrations/20240520142627-create-order.js +++ b/src/database/migrations/20240520142627-create-order.js @@ -20,6 +20,10 @@ module.exports = { }, onDelete: "CASCADE", }, + client: { + type: Sequelize.STRING, + allowNull: true, + }, paymentMethod: { type: Sequelize.STRING, allowNull: false, diff --git a/src/database/models/order.ts b/src/database/models/order.ts index 83903d9..63d6181 100644 --- a/src/database/models/order.ts +++ b/src/database/models/order.ts @@ -2,7 +2,6 @@ import { Model, DataTypes, Sequelize } from "sequelize"; import connectSequelize from "../config/db.config"; - class Order extends Model { public orderId?: string; public deliveryAddress!: any; @@ -11,7 +10,7 @@ class Order extends Model { public status!: string; public products!: any; public totalAmount!: number; - public expectedDeliveryDate?: Date + public expectedDeliveryDate?: Date; static associate(models: any) {} static initModel(sequelize: Sequelize) { Order.init( @@ -23,12 +22,13 @@ class Order extends Model { }, deliveryAddress: { type: DataTypes.JSONB, allowNull: false }, userId: { type: DataTypes.STRING, allowNull: false }, + client: { type: DataTypes.STRING, allowNull: false }, paymentMethod: { type: DataTypes.INTEGER, allowNull: false }, status: { type: DataTypes.STRING, allowNull: false }, client: { type: DataTypes.STRING, allowNull: false }, products: { type: DataTypes.JSONB, allowNull: false }, - totalAmount: {type:DataTypes.INTEGER,allowNull: false}, - expectedDeliveryDate: {type: DataTypes.DATE, allowNull: true} + totalAmount: { type: DataTypes.INTEGER, allowNull: false }, + expectedDeliveryDate: { type: DataTypes.DATE, allowNull: true }, }, { sequelize: connectSequelize, diff --git a/src/database/seeders/20240522075149-seed-orders.js b/src/database/seeders/20240522075149-seed-orders.js index ad772c5..babef13 100644 --- a/src/database/seeders/20240522075149-seed-orders.js +++ b/src/database/seeders/20240522075149-seed-orders.js @@ -6,14 +6,14 @@ const { v4: uuidv4 } = require("uuid"); module.exports = { async up(queryInterface, Sequelize) { const [users] = await queryInterface.sequelize.query(` - SELECT "userId" + SELECT "userId","name" FROM "Users" LIMIT 3; `); const [products] = await queryInterface.sequelize.query(` - SELECT "productId", "name", "vendorId" - FROM "Products" + SELECT "productId","name","image","price" FROM "Products" + LIMIT 3; `); @@ -26,6 +26,8 @@ module.exports = { }), // @ts-ignore userId: user.userId, + // @ts-ignore + client: user.name, paymentMethod: "Bank Transfer", status: "pending", products: JSON.stringify([ @@ -34,10 +36,18 @@ module.exports = { productId: product.productId, // @ts-ignore productName: product.name, + // @ts-ignore + productImage: product.image, + // @ts-ignore + price: product.price, status: "pending", quantity: 3, }, ]), + + // @ts-ignore + + totalAmount: 36000, createdAt: new Date(), updatedAt: new Date(), })) diff --git a/src/helpers/generateToken.ts b/src/helpers/generateToken.ts index 9e61c8c..17e6f19 100644 --- a/src/helpers/generateToken.ts +++ b/src/helpers/generateToken.ts @@ -1,7 +1,9 @@ -import jwt from 'jsonwebtoken'; -import User from '../database/models/user'; -import dotenv from 'dotenv'; -import Vendor from '../database/models/vendor'; + +import jwt from "jsonwebtoken"; +import User from "../database/models/user"; +import dotenv from "dotenv"; +import Vendor from "../database/models/vendor"; +import { where } from "sequelize"; dotenv.config(); @@ -28,4 +30,19 @@ const generateToken = async (userData: User) => { export { generateToken }; + return jwt.sign( + { + role: userData.role, + email: userData.email, + id: userData.userId, + vendor: vendorId, + password: userData.password, + }, + "crafters1234", + { + expiresIn: "1d", + } + ); +}; +export { generateToken }; diff --git a/src/index.ts b/src/index.ts index d7f60b9..f75ebf2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,12 +51,12 @@ ioServer.on("connection", (socket) => { }); }); - -app.use(cors({ - origin: process.env.CORS_ORIGIN_URL, - credentials: true -} -)); +app.use( + cors({ + origin: process.env.CORS_ORIGIN_URL, + credentials: true, + }) +); app.use(cookieParser()); app.use((req, res, next) => { @@ -104,11 +104,18 @@ app.use("/admin", adminRoute); app.use("/", cartroute); app.use("/", wishlistroute); app.use("/", TwoFaRoute); -app.use("/", chatRouter); -app.use('/', messageRoutes); + + +app.use("/", messageRoutes); + + +// app.use("/", chatRouter); +// app.use('/', messageRoutes); + app.use("/", messageRoutes); app.use("/", analyticRoute); +app.use("/", chatRouter); cron.schedule("0 0 * * *", () => { checkExpiredProducts(); diff --git a/src/pusher.ts b/src/pusher.ts index 467844e..8ca1543 100644 --- a/src/pusher.ts +++ b/src/pusher.ts @@ -4,7 +4,7 @@ const pusher = new Pusher({ appId: process.env.PUSHER_APP_ID as string, key: process.env.PUSHER_KEY as string, secret: process.env.PUSHER_SECRET as string, - cluster: "ap2", + cluster: "mt1", }); export default pusher \ No newline at end of file diff --git a/src/routes/order.route.ts b/src/routes/order.route.ts index e492a02..711057d 100644 --- a/src/routes/order.route.ts +++ b/src/routes/order.route.ts @@ -29,7 +29,11 @@ router.put( router.get("/order/getAllOrder", getAllOrder); router.get("/order/getOrder/:orderId", getOrder); + +router.get("/order/getSellerOrder/:vendorId", getSellerOrder); + router.get("/orders", VerifyAccessToken, getAllOrders); router.get("/order/getSellerOrder/:vendorId", getSellerOrder); + export default router; diff --git a/src/routes/user.route.ts b/src/routes/user.route.ts index 4070716..675d985 100644 --- a/src/routes/user.route.ts +++ b/src/routes/user.route.ts @@ -39,4 +39,8 @@ route.get("/getfeedback/:id", selectFeedback); route.get("/verfiy-email", verifyEmail); route.get("/user-info/:id", getUserInfo); +route.get("/finduser/:id", findUser); +route.get("/allusers", allUsers); +route.get("/allvendors", allVendors); + export default route;