feat: add validation for product ID in update method and implement placeholder methods in order service

This commit is contained in:
2026-01-13 00:38:47 +03:00
parent 0a3e5cfa95
commit f8aebd53df
3 changed files with 23 additions and 3 deletions
+4
View File
@@ -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) {
+10 -3
View File
@@ -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 });
}
}
+9
View File
@@ -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 }[],