Skip to content

Commit

Permalink
PO invoice endpoint clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
vsoraas committed Aug 7, 2024
1 parent 11c7526 commit 27ef535
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
25 changes: 6 additions & 19 deletions apps/api/src/lib/poweroffice/invoice.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
import { Env } from "@/env"
import { PO_ROOT } from "@/lib/poweroffice/auth"
import { superget, superpost } from "../poweroffice"
import { superpost } from "../poweroffice"


const INVOICE_URL = `https://goapi.poweroffice.net/Demo/v2/SalesOrders/Complete`


// poCustomerId should maybe be a field on Tenant?
// Either as extCustomerId to be compatible with all integrations, or as a separate through-model (TenantPowerOfficeCustomer)
async function createSalesOrder(env: Env, workspaceId: string, poCustomerId: number, productId: number, departmentId?: number, projectId?: number) {
// POST https://goapi.poweroffice.net/v2/SalesOrders/Complete

async function createSalesOrder(env: Env, workspaceId: string, invoiceData: Record<string, any>) {
const url = INVOICE_URL
const currencyCode = "NOK"
const invoiceData = {
"CurrencyCode": currencyCode,
"CustomerId": poCustomerId,
"SalesOrderLines": [{
"Description": "Faktura sendt via Propdock",
"ProductId": productId,
}],

"SalesOrderStatus": "Draft",
const data = {
...invoiceData,
"SalesOrderStatus": "Draft"
}

const response = await superpost(env, url, workspaceId, invoiceData)
const response = await superpost(env, url, workspaceId, data)

return response
}
Expand Down
8 changes: 2 additions & 6 deletions apps/api/src/routes/internal/poweroffice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,10 @@ app.post("/invoices/create", async (c) => {
return c.json({ ok: false, message: "x-user-id header is missing"}, 400)
}

//const invoiceData = await c.req.json()

// Dummy data
const customerId = 17763838
const productId = 20681521
const invoiceData = await c.req.json()

try {
const invoiceResponse = await createSalesOrder(c.env, user.workspaceId!, customerId, productId)
const invoiceResponse = await createSalesOrder(c.env, user.workspaceId!, invoiceData)
return c.json({ ok: true, message: invoiceResponse }, 200)
} catch (error: any) {
return c.json({ "ok": false, message: "Network error while creating the invoice", "error": error.message }, 500 )
Expand Down

0 comments on commit 27ef535

Please sign in to comment.