-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c588406
commit cb6707c
Showing
3 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { TRPCError } from "@trpc/server"; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import getPayloadClient from "~/payload/payloadClient"; | ||
import { appRouter } from "~/server/api/root"; | ||
import { createCallerFactory } from "~/server/api/trpc"; | ||
import { obiz_soap_client_options } from "~/server/soap-obiz"; | ||
var soap = require("soap"); | ||
|
||
export const obiz_soap_client_url = process.env.OBIZ_SOAP_URL; | ||
|
||
const ObizSync = async (req: NextApiRequest, res: NextApiResponse) => { | ||
if (req.method !== "POST") { | ||
return res.status(405).send("Invalid request method."); | ||
} | ||
|
||
const { numero } = req.query as { | ||
numero: string; | ||
}; | ||
|
||
try { | ||
const payload = await getPayloadClient({ seed: false }); | ||
const createCaller = createCallerFactory(appRouter); | ||
|
||
var soapObizClient = await soap.createClientAsync( | ||
obiz_soap_client_url, | ||
obiz_soap_client_options | ||
); | ||
|
||
const caller = createCaller({ | ||
payload, | ||
session: null, | ||
soapObizClient, | ||
req, | ||
}); | ||
|
||
const orderId = await caller.order.getIdByNumber({ | ||
number: parseInt(numero), | ||
}); | ||
|
||
const result = await caller.order.synchronizeOrder({ | ||
order_id: orderId.data, | ||
}); | ||
|
||
return res.status(200).json(result); | ||
} catch (error) { | ||
if (error instanceof TRPCError) { | ||
return res.status(400).json({ message: error.message, code: error.code }); | ||
} else { | ||
return res.status(500).json({ message: "Internal server error" }); | ||
} | ||
} | ||
}; | ||
|
||
export default ObizSync; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters