Record articlehistory entry on article creation

This commit is contained in:
seb
2026-08-08 10:09:02 +02:00
parent 53acc6a8ff
commit 91e7c03655
2 changed files with 12 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import { CREATE } from '../../sql/article.js';
import { ADD as ADD_CATEGORYARTICLE } from '../../sql/categoryarticle.js';
import { CREATE as CREATE_ARTICLETEXT } from '../../sql/articletext.js';
import { INSERT as INSERT_HISTORY } from '../../sql/articlehistory.js';
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
import ensureDefaultUnit from '../unit/ensureDefault.js';
import nextSku from '../numbers/nextSku.js';
@@ -27,7 +28,10 @@ export default function createUnderParent(pool) {
* // => { id, parentId, name, sku }
*/
return async ({ googleAuthId, parentId, name }) => {
const { companyId, languageId } = await access(googleAuthId, parentId);
const { companyId, languageId, companyuserId } = await access(
googleAuthId,
parentId
);
const tx = pool.transaction();
await tx.begin();
@@ -58,6 +62,12 @@ export default function createUnderParent(pool) {
.input('slug', slug)
.query(CREATE_ARTICLETEXT);
await request(pool, tx)
.input('articleId', id)
.input('companyuserId', companyuserId)
.input('text', `Artikel "${name}" angelegt`)
.query(INSERT_HISTORY);
await tx.commit();
return {

View File

@@ -24,6 +24,7 @@ export default function resolveCategoryAccess(pool) {
rootCategoryId: row.rootCategoryId,
languageId: row.languageId,
posCustomerGroupId: row.posCustomerGroupId ?? null,
companyuserId: row.companyuserId,
};
};
}