Adds endpoint for booking and drafting invoices in Economic
This commit is contained in:
1 parent
62e46ee820
commit
1e48ab3d74
8 files changed
+76
-1
No files matched your search
@@ -0,0 +1,10 @@
|
|||||||
|
import { Router } from "express"
|
||||||
|
import routes from "./routes"
|
||||||
|
|
||||||
|
export default (container) => {
|
||||||
|
const app = Router()
|
||||||
|
|
||||||
|
routes(app)
|
||||||
|
|
||||||
|
return app
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export default (fn) => (...args) => fn(...args).catch(args[2])
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { default as wrap } from "./await-middleware"
|
||||||
|
|
||||||
|
export default {
|
||||||
|
wrap,
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
export default async (req, res) => {
|
||||||
|
const schema = Validator.object().keys({
|
||||||
|
orderId: Validator.string().required(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const { value, error } = schema.validate(req.body)
|
||||||
|
if (error) {
|
||||||
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const economicService = req.scope.resolve("economicService")
|
||||||
|
await economicService.bookEconomicInvoice(value.orderId)
|
||||||
|
res.sendStatus(200)
|
||||||
|
} catch (error) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
export default async (req, res) => {
|
||||||
|
const schema = Validator.object().keys({
|
||||||
|
orderId: Validator.string().required(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const { value, error } = schema.validate(req.body)
|
||||||
|
if (error) {
|
||||||
|
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const economicService = req.scope.resolve("economicService")
|
||||||
|
await economicService.draftEconomicInvoice(value.orderId)
|
||||||
|
res.sendStatus(200)
|
||||||
|
} catch (error) {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
Whitespace-only changes.
@@ -0,0 +1,20 @@
|
|||||||
|
import { Router } from "express"
|
||||||
|
import middlewares from "../../middlewares"
|
||||||
|
|
||||||
|
const route = Router()
|
||||||
|
|
||||||
|
export default (app) => {
|
||||||
|
app.use("/economic", route)
|
||||||
|
|
||||||
|
route.post(
|
||||||
|
"/draft-invoice",
|
||||||
|
middlewares.wrap(require("./create-draft-invoice").default)
|
||||||
|
)
|
||||||
|
|
||||||
|
route.post(
|
||||||
|
"/book-invoice",
|
||||||
|
middlewares.wrap(require("./book-invoice").default)
|
||||||
|
)
|
||||||
|
|
||||||
|
return app
|
||||||
|
}
|
||||||
@@ -188,6 +188,9 @@ class EconomicService extends BaseService {
|
|||||||
"economicDraftId",
|
"economicDraftId",
|
||||||
draftInvoice.draftInvoiceNumber
|
draftInvoice.draftInvoiceNumber
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const invoiceOrder = await this.orderService_.retrieve(order._id)
|
||||||
|
return invoiceOrder
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
@@ -211,7 +214,7 @@ class EconomicService extends BaseService {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.economic_.post(
|
return this.economic_.post(
|
||||||
`${ECONOMIC_BASE_URL}/invoices/booked`,
|
`${ECONOMIC_BASE_URL}/invoices/booked`,
|
||||||
bookInvoiceRequest
|
bookInvoiceRequest
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user