mirror of
https://github.com/andwati/order-service.git
synced 2026-10-18 02:12:53 +00:00
feat: add validation for product ID in update method and implement placeholder methods in order service
This commit is contained in:
@@ -23,6 +23,10 @@ export class ProductController {
|
||||
static async update(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
if (typeof id !== "string") {
|
||||
res.status(400);
|
||||
return next({ statusCode: 400, message: "Invalid product id" });
|
||||
}
|
||||
const product = await ProductService.update(id, req.body);
|
||||
res.status(200).json(product);
|
||||
} catch (err) {
|
||||
|
||||
@@ -6,7 +6,7 @@ export class OrderRepository {
|
||||
data: Omit<OrderDocument, "_id" | "createdAt" | "updatedAt">,
|
||||
session: ClientSession,
|
||||
): Promise<OrderDocument> {
|
||||
return OrderModel.create([data], { session }).then((res) => res[0]);
|
||||
return OrderModel.create(data, { session });
|
||||
}
|
||||
|
||||
static findById(id: string, session?: ClientSession) {
|
||||
@@ -21,7 +21,14 @@ export class OrderRepository {
|
||||
return OrderModel.find({ userId }).lean();
|
||||
}
|
||||
|
||||
static save(order: OrderDocument, session?: ClientSession) {
|
||||
return order.save({ session });
|
||||
static save(
|
||||
order: OrderDocument & {
|
||||
save: (options?: {
|
||||
session?: ClientSession | null;
|
||||
}) => Promise<OrderDocument>;
|
||||
},
|
||||
session?: ClientSession,
|
||||
) {
|
||||
return order.save({ session: session ?? null });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,15 @@ import { ProductRepository } from "../repositories/product.repo.js";
|
||||
import { OrderRepository } from "../repositories/order.repo.js";
|
||||
|
||||
export class OrderService {
|
||||
static listOrders(userId: string, role: string) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
static payOrder(id: string | string[] | undefined) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
static cancelOrder(id: string | string[] | undefined) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
static async createOrder(
|
||||
userId: string,
|
||||
items: { productId: string; quantity: number }[],
|
||||
|
||||
Reference in New Issue
Block a user