diff --git a/.env.example b/.env.example index ade6c8be..cfeb7655 100644 --- a/.env.example +++ b/.env.example @@ -61,4 +61,5 @@ gender="" FRONT_END_BASEURL=""; STRIPE_SECRET_KEY="" -STRIPE_WEBHOOK_SECRET="" \ No newline at end of file +STRIPE_WEBHOOK_SECRET="" +CLIENT_URL \ No newline at end of file diff --git a/src/controllers/authController.ts b/src/controllers/authController.ts index 699171cf..7177d420 100644 --- a/src/controllers/authController.ts +++ b/src/controllers/authController.ts @@ -160,7 +160,7 @@ export const forgotPassword = async (req: Request, res: Response) => { const token = await userToken(user.id, user.email); // Send email with token - const link = `${process.env.URL_HOST}/api/auth/reset-password/${token}`; + const link = `${process.env.CLIENT_URL}/reset-password/${token}`; await sendEmail('reset_password', { name: `${user.firstName} ${user.lastName}`, diff --git a/src/controllers/cartController.ts b/src/controllers/cartController.ts index 28710d85..00ac7a1d 100644 --- a/src/controllers/cartController.ts +++ b/src/controllers/cartController.ts @@ -9,8 +9,6 @@ import { Size } from '../database/models/Size'; import CartsProducts from '../database/models/cartsProducts'; import { validateFields } from '../validations'; import { Transaction } from 'sequelize'; -import { checkStockSize, updateStock } from '../helpers/stockSizeManagers'; - const addCartItem = async (req: Request, res: Response): Promise => { const { productId, sizeId, quantity } = req.body; const { id: userId } = req.user as User; @@ -36,18 +34,7 @@ const addCartItem = async (req: Request, res: Response): Promise => { res.status(404).json({ ok: false, message: 'Size not found for this product' }); return; } - const stock = await checkStockSize(sizeId, productId, quantity); - if (stock <= 0) { - const product = await Product.findByPk(productId, { - include: [{ model: Size, as: 'sizes', where: { id: sizeId }, attributes: ['quantity'] }], - }); - res - .status(404) - .json({ ok: false, message: `Our stock has ${product?.sizes[0].quantity} product(s) of this size only!` }); - return; - } - await updateStock(sizeId, productId, stock); // Find the cart for the current user const cart = await Cart.findOne({ where: { userId }, transaction }); if (cart) { @@ -102,12 +89,12 @@ const updateCartItem = async (req: Request, res: Response): Promise => { const transaction = await sequelize.transaction(); try { - const cartItem: any = await Cart.findOne({ + const cartItem: Cart | null = await Cart.findOne({ where: { userId }, transaction, }); - if (!cartItem) { + if (cartItem === null) { res.status(404).json({ ok: false, message: 'Cart not found' }); return; } @@ -139,7 +126,7 @@ const getCartItems = async (req: Request, res: Response): Promise => { const transaction = await sequelize.transaction(); try { - const cart: any = await Cart.findOne({ + const cart: Cart | null = await Cart.findOne({ where: { userId }, include: [ { @@ -157,7 +144,7 @@ const getCartItems = async (req: Request, res: Response): Promise => { ], transaction, }); - if (!cart) { + if (cart === null) { res.status(404).json({ ok: false, message: 'Cart not found' }); return; } diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index 38fe766e..b9c5d195 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -187,17 +187,14 @@ export const editUserRole = async (req: Request, res: Response) => { export const editUser = async (req: Request, res: Response) => { try { const { firstName, lastName, gender, phoneNumber } = req.body; - const user = await User.findOne({ where: { id: req.params.id } }); // eslint-disable-next-line @typescript-eslint/no-explicit-any - let uploadedImage: any; if (!req.file) { res.status(400).json({ ok: false, error: 'Profile Image required.' }); + return; } - if (req.file) { - uploadedImage = await uploadImage(req.file.buffer); - } + const uploadedImage = await uploadImage(req.file.buffer); const updatedFields = { firstName: firstName || user?.firstName, lastName: lastName || user?.lastName, diff --git a/src/database/models/Size.ts b/src/database/models/Size.ts index c9850534..baf4b2fe 100644 --- a/src/database/models/Size.ts +++ b/src/database/models/Size.ts @@ -1,7 +1,7 @@ -import { Model, Optional, DataTypes, UUIDV4 } from 'sequelize'; +import { Model, DataTypes, UUIDV4 } from 'sequelize'; import sequelize from './index'; export interface SizeAttributes { - id?: number; + id?: string; size?: string; price: number; quantity?: number; @@ -14,7 +14,7 @@ export interface SizeAttributes { } export class Size extends Model implements SizeAttributes { - public id!: number; + public id!: string; public size!: string; public price!: number; public quantity!: number;