Skip to content

Commit

Permalink
feat: obiz hook article update integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNumericite committed Nov 29, 2024
1 parent 852aac4 commit b56c08a
Show file tree
Hide file tree
Showing 7 changed files with 5,221 additions and 92 deletions.
3 changes: 1 addition & 2 deletions webapp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
## [0.71.2](https://github.com/SocialGouv/carte-jeune-engage/compare/v0.71.1...v0.71.2) (2024-11-29)


### Bug Fixes

* add missing migrations ([827a31e](https://github.com/SocialGouv/carte-jeune-engage/commit/827a31ece7352ae9ca7c057c9f42858e7a4dd089))
- add missing migrations ([827a31e](https://github.com/SocialGouv/carte-jeune-engage/commit/827a31ece7352ae9ca7c057c9f42858e7a4dd089))

## [0.71.1](https://github.com/SocialGouv/carte-jeune-engage/compare/v0.71.0...v0.71.1) (2024-11-29)

Expand Down
53 changes: 38 additions & 15 deletions webapp/src/pages/api/obizSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ const ObizSync = async (req: NextApiRequest, res: NextApiResponse) => {
return res.status(405).send("Invalid request method.");
}

const { numero } = req.query as {
numero: string;
const { numero, article_id } = req.query as {
numero?: string;
article_id?: string;
};

console.log("obiz synchronizing order", numero);

try {
const payload = await getPayloadClient({ seed: false });
const createCaller = createCallerFactory(appRouter);
Expand All @@ -35,19 +34,43 @@ const ObizSync = async (req: NextApiRequest, res: NextApiResponse) => {
req,
});

const orderId = await caller.order.getIdByNumber({
number: parseInt(numero),
});
if (numero) {
console.log("obiz synchronizing order", numero);

const orderId = await caller.order.getIdByNumber({
number: parseInt(numero),
});

caller.order
.synchronizeOrder({
order_id: orderId.data,
})
.then((order) => {
console.log(
`Finish synchronizing obiz order : [numero: ${numero} / obiz status : ${order.data.obiz_status} / cje status : ${order.data.status}]`
);
caller.order
.synchronizeOrder({
order_id: orderId.data,
})
.then((order) => {
console.log(
`Finish synchronizing obiz order : [numero: ${numero} / obiz status : ${order.data.obiz_status} / cje status : ${order.data.status}]`
);
});
} else if (article_id) {
console.log("obiz synchronizing article", article_id);
caller.offer
.synchronizeObizOffer({
article_id,
})
.then(({ offer, updateArticles, article_actif }) => {
if (updateArticles) {
console.log(
`Finish synchronizing obiz offer : [${offer.formatedTitle} : article ${article_actif ? "listed" : "delisted"} (${article_id})]`
);
} else {
console.log(`Nothing to synchronize`);
}
});
} else {
throw new TRPCError({
code: "BAD_REQUEST",
message: `No order number or article_id provided`,
});
}

return res.status(200).json({ data: "ok" });
} catch (error) {
Expand Down
8 changes: 8 additions & 0 deletions webapp/src/payload/collections/Offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ export const Offers: CollectionConfig = {
},
},
fields: [
{
name: "obiz_id",
type: "text",
label: "Identifiant Obiz",
admin: {
readOnly: true,
},
},
{
name: "available",
label: "Disponible",
Expand Down
Loading

0 comments on commit b56c08a

Please sign in to comment.