Migrate PrestaShop config to Config API blocks and add permissions.
Replace custom ShopConfig pages/models with registerConfigBlocks, load config from Config store, and enforce RBAC on methods. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+6
-11
@@ -1,20 +1,15 @@
|
||||
const { Core } = require('@orbito/api-lib');
|
||||
const ShopConfig = require('../src/models/ShopConfig');
|
||||
const PrestashopApi = require('../src/PrestaApi');
|
||||
const { importFromPSOrder } = require('../src/OrderImporter');
|
||||
const { isLegacyApi } = require('../src/utils');
|
||||
const { loadConfig, isConfigured, setLastOrderId } = require('../src/module-config');
|
||||
const { PERMISSIONS, requirePermission } = require('../src/register-permissions');
|
||||
|
||||
module.exports = async function(params, ctx) {
|
||||
const configs = await ShopConfig.find({ isRemoved: { $ne: true } });
|
||||
const active = configs.filter(c => c.apiUrl && c.apiKey);
|
||||
requirePermission(PERMISSIONS.ORDERS_IMPORT, ctx);
|
||||
|
||||
if (active.length === 0) return { error: 'No active shop configs found' };
|
||||
|
||||
const config = params.configId
|
||||
? active.find(c => String(c._id) === String(params.configId))
|
||||
: active[0];
|
||||
|
||||
if (!config) return { error: 'Config not found' };
|
||||
const config = await loadConfig();
|
||||
if (!isConfigured(config)) return { error: 'No active shop configs found' };
|
||||
|
||||
const api = new PrestashopApi(config.apiUrl, config.apiKey, isLegacyApi(config.versionCode));
|
||||
|
||||
@@ -49,7 +44,7 @@ module.exports = async function(params, ctx) {
|
||||
}
|
||||
}
|
||||
const maxId = Math.max(...orders.map(o => parseInt(o.id)));
|
||||
await ShopConfig.update({ _id: config._id }, { lastOrderId: maxId });
|
||||
await setLastOrderId(maxId);
|
||||
return { shopName: config.shopName, imported, errors, newLastOrderId: maxId };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user