Migrate to @orbito/api-lib 2.0.0 for single-company container model.
Remove companyId from handlers, models, cron jobs, and cross-module calls to match the v2 one-module-one-company architecture. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,11 +2,11 @@ const { Log } = require('@orbito/api-lib');
|
||||
const ShopConfig = require('../../src/models/ShopConfig');
|
||||
const { toFormResponse } = require('../../src/config-form');
|
||||
|
||||
module.exports = async function(companyId, instanceId, params, ctx) {
|
||||
const config = await ShopConfig.findOne({ companyId, isRemoved: { $ne: true } });
|
||||
module.exports = async function(params, ctx) {
|
||||
const config = await ShopConfig.findOne({ isRemoved: { $ne: true } });
|
||||
const form = toFormResponse(config);
|
||||
|
||||
Log.debug(companyId, 'config.get', {
|
||||
Log.debug( 'config.get', {
|
||||
found: Boolean(config),
|
||||
storeUrl: form.storeUrl,
|
||||
shopPrefix: form.shopPrefix,
|
||||
|
||||
@@ -6,8 +6,8 @@ const { extractPsStateName } = require('../../src/status-mapper');
|
||||
const { normalizeFormParams } = require('../../src/config-form');
|
||||
const { methodOk, methodFail } = require('../../src/method-result');
|
||||
|
||||
module.exports = async function(companyId, instanceId, params, ctx) {
|
||||
const existing = await ShopConfig.findOne({ companyId, isRemoved: { $ne: true } });
|
||||
module.exports = async function(params, ctx) {
|
||||
const existing = await ShopConfig.findOne({ isRemoved: { $ne: true } });
|
||||
const input = normalizeFormParams(params);
|
||||
|
||||
const storeUrl = (input.storeUrl || existing?.apiUrl || '').trim();
|
||||
@@ -43,19 +43,18 @@ module.exports = async function(companyId, instanceId, params, ctx) {
|
||||
|
||||
if (existing) {
|
||||
await ShopConfig.update({ _id: existing._id }, payload);
|
||||
Log.info(companyId, 'PrestaShop order states saved', { configId: existing._id, count: psStates.length });
|
||||
Log.info( 'PrestaShop order states saved', { configId: existing._id, count: psStates.length });
|
||||
} else {
|
||||
await ShopConfig.create({
|
||||
companyId,
|
||||
...payload,
|
||||
shopPrefix: (input.shopPrefix || '').trim()
|
||||
});
|
||||
Log.info(companyId, 'PrestaShop config created with order states', { count: psStates.length });
|
||||
Log.info( 'PrestaShop config created with order states', { count: psStates.length });
|
||||
}
|
||||
|
||||
return methodOk({ count: psStates.length, psStates });
|
||||
} catch (e) {
|
||||
Log.warn(companyId, 'config.get_ps_states failed', { storeUrl, error: e.message });
|
||||
Log.warn( 'config.get_ps_states failed', { storeUrl, error: e.message });
|
||||
return methodFail('Nie udało się pobrać statusów: ' + (e.message || 'błąd API PrestaShop'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,8 +2,8 @@ const ShopConfig = require('../../src/models/ShopConfig');
|
||||
const { buildMappingRows } = require('../../src/config-form');
|
||||
|
||||
// Zwraca wiersze UI mapowania statusów PS → Orbito (tablica dla widoku type: list).
|
||||
module.exports = async function(companyId, instanceId, params, ctx) {
|
||||
const config = await ShopConfig.findOne({ companyId, isRemoved: { $ne: true } });
|
||||
module.exports = async function(params, ctx) {
|
||||
const config = await ShopConfig.findOne({ isRemoved: { $ne: true } });
|
||||
if (!config) return [];
|
||||
|
||||
const psStates = Array.isArray(config.psStates) ? config.psStates : [];
|
||||
|
||||
@@ -2,13 +2,13 @@ const { Log } = require('@orbito/api-lib');
|
||||
const ShopConfig = require('../../src/models/ShopConfig');
|
||||
const { methodOk } = require('../../src/method-result');
|
||||
|
||||
module.exports = async function(companyId, instanceId, params, ctx) {
|
||||
const configs = await ShopConfig.find({ companyId, isRemoved: { $ne: true } });
|
||||
module.exports = async function(params, ctx) {
|
||||
const configs = await ShopConfig.find({ isRemoved: { $ne: true } });
|
||||
|
||||
for (const config of configs) {
|
||||
await ShopConfig.update({ _id: config._id }, { isRemoved: true });
|
||||
}
|
||||
|
||||
Log.info(companyId, 'PrestaShop config reset', { removed: configs.length });
|
||||
Log.info( 'PrestaShop config reset', { removed: configs.length });
|
||||
return methodOk({ removed: configs.length });
|
||||
};
|
||||
|
||||
@@ -3,12 +3,12 @@ const ShopConfig = require('../../src/models/ShopConfig');
|
||||
const { toFormResponse, buildSavePayload, normalizeFormParams } = require('../../src/config-form');
|
||||
const { methodOk, methodFail } = require('../../src/method-result');
|
||||
|
||||
module.exports = async function(companyId, instanceId, params, ctx) {
|
||||
module.exports = async function(params, ctx) {
|
||||
try {
|
||||
const input = normalizeFormParams(params);
|
||||
const existing = await ShopConfig.findOne({ companyId, isRemoved: { $ne: true } });
|
||||
const existing = await ShopConfig.findOne({ isRemoved: { $ne: true } });
|
||||
|
||||
Log.debug(companyId, 'config.save input', {
|
||||
Log.debug( 'config.save input', {
|
||||
keys: Object.keys(input),
|
||||
storeUrl: input.storeUrl,
|
||||
shopPrefix: input.shopPrefix,
|
||||
@@ -24,20 +24,20 @@ module.exports = async function(companyId, instanceId, params, ctx) {
|
||||
return methodFail('Klucz API jest wymagany. Wpisz klucz Webservice API lub zachowaj już zapisany.');
|
||||
}
|
||||
|
||||
const payload = { companyId, ...data };
|
||||
const payload = { ...data };
|
||||
|
||||
if (existing) {
|
||||
await ShopConfig.update({ _id: existing._id }, payload);
|
||||
Log.info(companyId, 'PrestaShop config updated', { configId: existing._id });
|
||||
Log.info( 'PrestaShop config updated', { configId: existing._id });
|
||||
const updated = await ShopConfig.findOne({ _id: existing._id });
|
||||
return methodOk({ data: toFormResponse(updated) });
|
||||
}
|
||||
|
||||
const created = await ShopConfig.create(payload);
|
||||
Log.info(companyId, 'PrestaShop config created', { configId: created._id });
|
||||
Log.info( 'PrestaShop config created', { configId: created._id });
|
||||
return methodOk({ data: toFormResponse(created) });
|
||||
} catch (err) {
|
||||
Log.error(companyId, 'config.save failed', { error: err?.message });
|
||||
Log.error( 'config.save failed', { error: err?.message });
|
||||
return methodFail(err?.message || 'Nie udało się zapisać konfiguracji');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,8 +5,8 @@ const { isLegacyApi } = require('../../src/utils');
|
||||
const { normalizeFormParams } = require('../../src/config-form');
|
||||
const { methodOk, methodFail } = require('../../src/method-result');
|
||||
|
||||
module.exports = async function(companyId, instanceId, params, ctx) {
|
||||
const existing = await ShopConfig.findOne({ companyId, isRemoved: { $ne: true } });
|
||||
module.exports = async function(params, ctx) {
|
||||
const existing = await ShopConfig.findOne({ isRemoved: { $ne: true } });
|
||||
const input = normalizeFormParams(params);
|
||||
|
||||
const storeUrl = (input.storeUrl || existing?.apiUrl || '').trim();
|
||||
@@ -29,10 +29,10 @@ module.exports = async function(companyId, instanceId, params, ctx) {
|
||||
return methodFail('API nie zwróciło danych (sprawdź klucz Webservice i uprawnienia)');
|
||||
}
|
||||
const count = Array.isArray(statuses) ? statuses.length : undefined;
|
||||
Log.info(companyId, 'PrestaShop connection test OK', { storeUrl, statusesCount: count });
|
||||
Log.info( 'PrestaShop connection test OK', { storeUrl, statusesCount: count });
|
||||
return methodOk({ statusesCount: count });
|
||||
} catch (e) {
|
||||
Log.warn(companyId, 'PrestaShop connection test failed', { storeUrl, error: e.message });
|
||||
Log.warn( 'PrestaShop connection test failed', { storeUrl, error: e.message });
|
||||
return methodFail('Połączenie nieudane: ' + (e.message || 'błąd API PrestaShop'));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user