Adds endpoint for booking and drafting invoices in Economic

This commit is contained in:
olivermrbl
2020-07-09 15:30:00 +02:00
parent 62e46ee820
commit 1e48ab3d74
8 changed files with 76 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
import { Router } from "express"
import routes from "./routes"
export default (container) => {
const app = Router()
routes(app)
return app
}

View File

@@ -0,0 +1 @@
export default (fn) => (...args) => fn(...args).catch(args[2])

View File

@@ -0,0 +1,5 @@
import { default as wrap } from "./await-middleware"
export default {
wrap,
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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
}

View File

@@ -188,6 +188,9 @@ class EconomicService extends BaseService {
"economicDraftId",
draftInvoice.draftInvoiceNumber
)
const invoiceOrder = await this.orderService_.retrieve(order._id)
return invoiceOrder
} catch (error) {
throw error
}
@@ -211,7 +214,7 @@ class EconomicService extends BaseService {
},
}
await this.economic_.post(
return this.economic_.post(
`${ECONOMIC_BASE_URL}/invoices/booked`,
bookInvoiceRequest
)