feat(order): Modify createOrder() to work with the user model

This commit is contained in:
Daniel Gonzalez
2025-05-05 18:26:04 -04:00
parent 5ede934be5
commit fafa7eecd9
7 changed files with 151 additions and 14 deletions
@@ -35,6 +35,8 @@ class OrderRESTControllerLib {
// console.log('body: ', ctx.request.body)
const orderObj = ctx.request.body.order
const user = ctx.state.user
orderObj.userId = user._id
console.log('orderObj: ', orderObj)
const { eventId, noteId } = await _this.useCases.order.createOrder(orderObj)
+9 -1
View File
@@ -7,6 +7,7 @@ import Router from 'koa-router'
// Local libraries.
import OrderRESTControllerLib from './controller.js'
import Validators from '../middleware/validators.js'
let _this
@@ -32,12 +33,14 @@ class OrderRouter {
}
// Encapsulate dependencies.
this.validators = new Validators()
this.orderRESTController = new OrderRESTControllerLib(dependencies)
// Instantiate the router and set the base route.
const baseUrl = '/order'
this.router = new Router({ prefix: baseUrl })
this.createOrder = this.createOrder.bind(this)
_this = this
}
@@ -49,7 +52,7 @@ class OrderRouter {
}
// Define the routes and attach the controller.
this.router.post('/', _this.orderRESTController.createOrder)
this.router.post('/', this.createOrder)
this.router.get('/list/all/:page', _this.orderRESTController.listOrders)
this.router.post('/delete', _this.orderRESTController.deleteOrder)
@@ -57,6 +60,11 @@ class OrderRouter {
app.use(_this.router.routes())
app.use(_this.router.allowedMethods())
}
async createOrder (ctx, next) {
await _this.validators.ensureUser(ctx, next)
await _this.orderRESTController.createOrder(ctx, next)
}
}
export default OrderRouter