mirror of
https://github.com/andwati/order-service.git
synced 2026-11-03 17:42:15 +00:00
33 lines
871 B
TypeScript
33 lines
871 B
TypeScript
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);
|
|
}
|
|
}
|
|
}
|