Add native Olist composition sync
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m24s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m24s
This commit is contained in:
55
backend/routes/olistRoutes.js
Normal file
55
backend/routes/olistRoutes.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const express = require('express');
|
||||
const { verifySuperAdmin } = require('../auth');
|
||||
const {
|
||||
completeAuthorization,
|
||||
createAuthorizationUrl,
|
||||
getOlistFrontendRedirect,
|
||||
getOlistStatus,
|
||||
startOlistSync
|
||||
} = require('../services/olistService');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/olist/status', verifySuperAdmin, async (req, res, next) => {
|
||||
try {
|
||||
res.json(await getOlistStatus());
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/olist/authorization-url', verifySuperAdmin, async (req, res, next) => {
|
||||
try {
|
||||
res.json({ url: await createAuthorizationUrl() });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/olist/sync', verifySuperAdmin, async (req, res, next) => {
|
||||
try {
|
||||
const result = await startOlistSync({
|
||||
trigger: 'manual',
|
||||
fullSync: req.body?.fullSync === true
|
||||
});
|
||||
res.status(result.accepted ? 202 : 409).json(result);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/olist/oauth/callback', async (req, res) => {
|
||||
try {
|
||||
if (req.query.error || !req.query.code || !req.query.state) {
|
||||
res.redirect(getOlistFrontendRedirect('cancelled'));
|
||||
return;
|
||||
}
|
||||
await completeAuthorization({ code: String(req.query.code), state: String(req.query.state) });
|
||||
res.redirect(getOlistFrontendRedirect('connected'));
|
||||
} catch (error) {
|
||||
console.error('Olist OAuth callback failed:', error.message);
|
||||
res.redirect(getOlistFrontendRedirect('failed'));
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user