Files
order-service/src/controllers/product.controller.ts
T

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);
}
}
}