diff --git a/src/controllers/product.controller.ts b/src/controllers/product.controller.ts index 1979758..cad37a4 100644 --- a/src/controllers/product.controller.ts +++ b/src/controllers/product.controller.ts @@ -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) { diff --git a/src/repositories/order.repo.ts b/src/repositories/order.repo.ts index 305ba62..8103e6a 100644 --- a/src/repositories/order.repo.ts +++ b/src/repositories/order.repo.ts @@ -6,7 +6,7 @@ export class OrderRepository { data: Omit, session: ClientSession, ): Promise { - 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; + }, + session?: ClientSession, + ) { + return order.save({ session: session ?? null }); } } diff --git a/src/services/order.service.ts b/src/services/order.service.ts index 50992b1..07f877b 100644 --- a/src/services/order.service.ts +++ b/src/services/order.service.ts @@ -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 }[],