[fixed] - issue

This commit is contained in:
Swapnil
2024-12-06 01:44:11 +05:30
parent abeb6b0b30
commit 450819bb17
2 changed files with 6 additions and 4 deletions

View File

@@ -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: [],
})

View File

@@ -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'));