[update] - latest code

This commit is contained in:
Swapnil Bendal
2024-12-10 17:13:27 +05:30
parent 70ed1e2782
commit ca6d4551ca
16 changed files with 3999 additions and 434 deletions

View File

@@ -1,7 +1,7 @@
import { NextFunction, Request, Response } from 'express';
import { IProductInteractor } from '../interfaces/IProductInteractor';
import { AsyncHandler } from '../utils/handler/AsyncHandler';
import ApiResponse from '../utils/helper/ApiResponse';
import { AsyncHandler } from '../utils/handler/async.handler';
export class ProductController {
private interactor: IProductInteractor;
@@ -18,12 +18,13 @@ export class ProductController {
@AsyncHandler()
async onGetProducts(req: Request, res: Response, next: NextFunction) {
const offset = parseInt(`${req.query.offset}`) || 0;
const limit = parseInt(`${req.query.limit}`) || 10;
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) {
res.status(204).json(new ApiResponse(204, null, 'No products found'));
res.status(200).json(new ApiResponse(200, null, 'No products found'));
return;
}
@@ -32,7 +33,7 @@ export class ProductController {
@AsyncHandler()
async onUpdateStock(req: Request, res: Response, next: NextFunction) {
const data = await this.interactor.updateStock(parseInt(`${req.params.id}`), parseInt(`${req.body.stock}`));
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'));
}
}