This commit is contained in:
seb
2026-09-25 07:27:22 +02:00
parent f8f61a1212
commit 387147ccf3
4 changed files with 76 additions and 14 deletions

View File

@@ -105,14 +105,15 @@ export default function add(provider) {
const transactionText = String(rawTransactionText);
const doAdd = async (runner) => {
const { companyId } = await access(googleAuthId, runner);
const { companyId, companyuserId, rootCategoryId } = await access(googleAuthId, runner);
const check = await runner.query(queries.CHECK_MANIFESTARTICLE_ACCESS, {
manifestarticleId,
companyId,
});
if (!check.rows[0]) {
const manifestArticle = check.rows[0];
if (!manifestArticle) {
throw new Error('Manifest article not found');
}
@@ -134,6 +135,22 @@ export default function add(provider) {
throw new Error('Failed to insert ledger entry');
}
const sku = manifestArticle.sku ? String(manifestArticle.sku).trim() : '';
if (sku) {
const articleMatches = await runner.query(queries.FIND_ARTICLES_FOR_HISTORY, {
sku,
companyId,
});
for (const match of articleMatches.rows) {
await runner.query(queries.INSERT_ARTICLE_HISTORY, {
articleId: match.articleId,
companyuserId,
text: transactionText,
});
}
}
return shape(row);
};