forked from swapnil.bendal/TypeScript-Backend-Template
[fixed] - issue
This commit is contained in:
@@ -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: [],
|
||||
})
|
||||
|
||||
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user