forked from swapnil.bendal/TypeScript-Backend-Template
add chnanges
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { NextFunction, Request, Response } from 'express';
|
||||
import { Request, Response } from 'express';
|
||||
import { IProductInteractor } from '../interfaces/IProductInteractor';
|
||||
import ApiResponse from '../utils/helper/ApiResponse';
|
||||
import { AsyncHandler } from '../utils/handler/async.handler';
|
||||
@@ -11,16 +11,16 @@ export class ProductController {
|
||||
}
|
||||
|
||||
@AsyncHandler()
|
||||
async onCreateProduct(req: Request, res: Response, next: NextFunction) {
|
||||
async onCreateProduct(req: Request, res: Response) {
|
||||
const data = await this.interactor.createProduct(req.body);
|
||||
res.status(201).json(new ApiResponse(201, data, 'Successfully created'));
|
||||
}
|
||||
|
||||
@AsyncHandler()
|
||||
async onGetProducts(req: Request, res: Response, next: NextFunction) {
|
||||
async onGetProducts(req: Request, res: Response) {
|
||||
const offset = Number.isInteger(Number(req.query.offset)) ? parseInt(`${req.query.offset}`, 10) : 0;
|
||||
const limit = Number.isInteger(Number(req.query.limit)) ? parseInt(`(${req.query.limit}`, 10) : 10;
|
||||
|
||||
|
||||
const data = await this.interactor.getProducts(limit, offset);
|
||||
|
||||
if (data.length === 0) {
|
||||
@@ -32,7 +32,7 @@ export class ProductController {
|
||||
}
|
||||
|
||||
@AsyncHandler()
|
||||
async onUpdateStock(req: Request, res: Response, next: NextFunction) {
|
||||
async onUpdateStock(req: Request, res: Response) {
|
||||
const data = await this.interactor.updateStock(parseInt(`${req.params.id}`, 10), parseInt(`${req.body.stock}`, 10));
|
||||
res.status(200).json(new ApiResponse(200, data, 'Successfully updated'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user