mirror of
https://github.com/andwati/order-service.git
synced 2026-11-10 20:25:11 +00:00
feat: implement authentication and product management services with validation schemas
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { ProductService } from "../services/product.service";
|
||||
|
||||
export class ProductController {
|
||||
static async create(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
const product = await ProductService.create(req.body);
|
||||
res.status(201).json(product);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
static async list(_req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
const products = await ProductService.list();
|
||||
res.status(200).json(products);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
static async update(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const product = await ProductService.update(id, req.body);
|
||||
res.status(200).json(product);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user