This commit is contained in:
seb
2026-09-25 12:30:45 +02:00
parent b5255bdd17
commit 607e6cc0ac
10 changed files with 98 additions and 124 deletions

View File

@@ -54,6 +54,7 @@ export default function createUnderParent(provider) {
let article;
try {
article = await runner.query(createArticleSql, {
companyId,
sku,
unitId,
unitamount: 1,

View File

@@ -157,7 +157,7 @@ export default function importRows(provider) {
continue;
}
const existing = await baseRunner.query(articleQueries.GET_ID_BY_SKU, { sku });
const existing = await baseRunner.query(articleQueries.GET_ID_BY_SKU, { sku, companyId });
if (existing.rows[0]) {
skipped.push({ sku, name, reason: 'duplicate sku' });
continue;
@@ -169,6 +169,7 @@ export default function importRows(provider) {
const slug = slugify(name);
const article = await runner.query(articleQueries.CREATE, {
companyId,
sku,
unitId,
unitamount: 1,
@@ -277,10 +278,10 @@ export default function importRows(provider) {
try {
await runInTx(async (runner) => {
const child = await runner.query(articleQueries.GET_ID_BY_SKU, { sku });
const child = await runner.query(articleQueries.GET_ID_BY_SKU, { sku, companyId });
const childId = child.rows[0]?.articleId;
if (childId) {
const father = await runner.query(articleQueries.GET_ID_BY_SKU, { sku: fatherSku });
const father = await runner.query(articleQueries.GET_ID_BY_SKU, { sku: fatherSku, companyId });
const fatherId = father.rows[0]?.articleId;
if (fatherId && fatherId !== childId) {
const childCount = await runner.query(getChildCountSql, {
@@ -289,6 +290,7 @@ export default function importRows(provider) {
const count = childCount.rows[0].count;
await runner.query(articleQueries.UPDATE_FATHER_BY_SKU, {
sku,
companyId,
fatherArticleId: fatherId,
fathersort: count,
});

View File

@@ -30,11 +30,12 @@ export default function setFatherBySku(provider) {
*/
return async (googleAuthId, sku, fatherSku, tx) => {
const runSet = async (runner) => {
const { articleId, languageId } = await resolve(googleAuthId, sku, runner);
const { articleId, languageId, companyId } = await resolve(googleAuthId, sku, runner);
if (fatherSku == null || fatherSku === '') {
await runner.query(queries.UPDATE_FATHER_BY_SKU, {
sku,
companyId,
fatherArticleId: null,
});
const unlinked = await load(articleId, languageId, runner);
@@ -44,7 +45,7 @@ export default function setFatherBySku(provider) {
return unlinked;
}
const father = await runner.query(queries.GET_ID_BY_SKU, { sku: fatherSku });
const father = await runner.query(queries.GET_ID_BY_SKU, { sku: fatherSku, companyId });
const fatherId = father.rows[0]?.articleId;
if (!fatherId) {
throw new Error('Father not found');
@@ -60,6 +61,7 @@ export default function setFatherBySku(provider) {
await runner.query(queries.UPDATE_FATHER_BY_SKU, {
sku,
companyId,
fatherArticleId: fatherId,
fathersort: count,
});