From 450819bb176e0b60e4ff665229927fa44bc14467 Mon Sep 17 00:00:00 2001 From: Swapnil Date: Fri, 6 Dec 2024 01:44:11 +0530 Subject: [PATCH] [fixed] - issue --- src/config/data-source.ts | 3 ++- src/controllers/productController.ts | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/config/data-source.ts b/src/config/data-source.ts index 600a892..2705184 100644 --- a/src/config/data-source.ts +++ b/src/config/data-source.ts @@ -1,6 +1,7 @@ import "reflect-metadata" import { DataSource } from "typeorm" import config from "./config" +import { Product } from "../entities/Product" export const AppDataSource = new DataSource({ type: "mysql", @@ -10,7 +11,7 @@ export const AppDataSource = new DataSource({ password: config.database[config.env].password, // Dynamically set password database: config.database[config.env].database, // Dynamically set database synchronize: true, - entities: ["../entities/**/*.ts"], + entities: [Product], migrations: ["../migration/**/*.ts"], subscribers: [], }) diff --git a/src/controllers/productController.ts b/src/controllers/productController.ts index d431292..8fac1f3 100644 --- a/src/controllers/productController.ts +++ b/src/controllers/productController.ts @@ -10,13 +10,13 @@ export class ProductController { this.interactor = interactor; } - // @AsyncHandler() + @AsyncHandler() async onCreateProduct(req: Request, res: Response, next: NextFunction) { const data = await this.interactor.createProduct(req.body); res.status(201).json(new ApiResponse(201, data, 'Successfully created')); } - // @AsyncHandler() + @AsyncHandler() async onGetProducts(req: Request, res: Response, next: NextFunction) { const offset = parseInt(`${req.query.offset}`) || 0; const limit = parseInt(`${req.query.limit}`) || 10; @@ -24,12 +24,13 @@ export class ProductController { if (data.length === 0) { res.status(204).json(new ApiResponse(204, null, 'No products found')); + return; } res.status(200).json(new ApiResponse(200, data, 'Products retrieved successfully')); } - // @AsyncHandler() + @AsyncHandler() async onUpdateStock(req: Request, res: Response, next: NextFunction) { const data = await this.interactor.updateStock(parseInt(`${req.params.id}`), parseInt(`${req.body.stock}`)); res.status(200).json(new ApiResponse(200, data, 'Successfully updated'));