This commit is contained in:
seb
2026-10-08 12:59:10 +02:00
parent b51149c7f0
commit 46ea04c0cb
8 changed files with 33 additions and 106 deletions

View File

@@ -95,11 +95,8 @@ Creates a new article under a given parent category, allocating a SKU and a defa
| `input.googleAuthId` | `number` | The id of the Google auth user. | | `input.googleAuthId` | `number` | The id of the Google auth user. |
| `input.parentId` | `number` | The id of the parent category. | | `input.parentId` | `number` | The id of the parent category. |
| `input.name` | `string` | The article name. | | `input.name` | `string` | The article name. |
| `[input.description]` | `string` | The article description. | | `[input.desc]` | `string` | The article description text/HTML. |
| `[input.desc]` | `string` | Alias for description. | | `[input.seo]` | `string` | The article SEO text. |
| `[input.seo]` | `object|string` | The SEO configuration or JSON string. |
| `[input.seoTitle]` | `string` | The SEO title. |
| `[input.seoDescription]` | `string` | The SEO meta description. |
| `[input.track_stock=true]` | `boolean|number` | Whether inventory stock is tracked. | | `[input.track_stock=true]` | `boolean|number` | Whether inventory stock is tracked. |
| `[tx]` | `object` | Optional transaction to run within. | | `[tx]` | `object` | Optional transaction to run within. |
@@ -189,7 +186,7 @@ Returns the full detail of an article by its SKU, including unit, brand, categor
**Returns** **Returns**
`Promise<{article: {id: number, sku: string, name: string, slug: string, description: string|null, seo: string|null, seoTitle: string|null, seoDescription: string|null, unitamount: number|null, weight: number|null, track_stock: boolean, unit: {si: string|null, basesi: string|null, basesifactor: number|null, symbol: string|null, name: string|null}, brand: {id: number|null, name: string, fullHash: string|null, thumbW: number|null, thumbH: number|null, thumbHash: string|null}|null, categoryIds: number[], photos: Array<{sort: number, fullHash: string, fullW: number, fullH: number, fullSize: number, thumbW: number, thumbH: number, thumbHash: string}>, eans: string[], prices: Array<{minmultiplier: number, net: number, taxRate: number, customergroupId: number}>, suppliers: Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, sort: number, price: {net: number, taxId: number, taxRate?: number}|null}>, optionsCount: number, articleListCount: number, childCount: number, parentArticleId: number|null, parentSku: string|null}}>` — The full article detail. `Promise<{article: {id: number, sku: string, name: string, slug: string, desc: string|null, seo: string|null, unitamount: number|null, weight: number|null, track_stock: boolean, unit: {si: string|null, basesi: string|null, basesifactor: number|null, symbol: string|null, name: string|null}, brand: {id: number|null, name: string, fullHash: string|null, thumbW: number|null, thumbH: number|null, thumbHash: string|null}|null, categoryIds: number[], photos: Array<{sort: number, fullHash: string, fullW: number, fullH: number, fullSize: number, thumbW: number, thumbH: number, thumbHash: string}>, eans: string[], prices: Array<{minmultiplier: number, net: number, taxRate: number, customergroupId: number}>, suppliers: Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, sort: number, price: {net: number, taxId: number, taxRate?: number}|null}>, optionsCount: number, articleListCount: number, childCount: number, parentArticleId: number|null, parentSku: string|null}}>` — The full article detail.
**Throws** **Throws**
@@ -669,11 +666,8 @@ Updates an article's name and/or unit (SI and amount), recording history.
| `sku` | `string` | The article SKU. | | `sku` | `string` | The article SKU. |
| `patch` | `object` | The update patch. | | `patch` | `object` | The update patch. |
| `[patch.name]` | `string` | The new article name. | | `[patch.name]` | `string` | The new article name. |
| `[patch.description]` | `string` | The article description. | | `[patch.desc]` | `string` | The article description text/HTML. |
| `[patch.desc]` | `string` | Alias for description. | | `[patch.seo]` | `string` | The article SEO text. |
| `[patch.seo]` | `object|string` | The SEO configuration or JSON string. |
| `[patch.seoTitle]` | `string` | The SEO title. |
| `[patch.seoDescription]` | `string` | The SEO meta description. |
| `[patch.unitSi]` | `string` | The new unit SI code. | | `[patch.unitSi]` | `string` | The new unit SI code. |
| `[patch.unitamount]` | `number` | The new unit amount (must be > 0). | | `[patch.unitamount]` | `number` | The new unit amount (must be > 0). |
| `[patch.track_stock]` | `boolean|number` | Whether inventory stock is tracked. | | `[patch.track_stock]` | `boolean|number` | Whether inventory stock is tracked. |

6
API.md
View File

@@ -88,10 +88,10 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met
- `addChild(googleAuthId: number, parentSku: string, options: {attach?: boolean, attributeValueId?: number, value?: string, name?: string, unitamount?: number, weight?: number, track_stock?: boolean|number}, tx?: object): Promise<object>` - `addChild(googleAuthId: number, parentSku: string, options: {attach?: boolean, attributeValueId?: number, value?: string, name?: string, unitamount?: number, weight?: number, track_stock?: boolean|number}, tx?: object): Promise<object>`
- `addImage(googleAuthId: number, sku: string, image: Buffer, tx?: object): Promise<{picId: number, sort: number, full: {w: number, h: number, size: number}, thumb: {w: number, h: number}, fullHash: string, thumbHash: string}>` - `addImage(googleAuthId: number, sku: string, image: Buffer, tx?: object): Promise<{picId: number, sort: number, full: {w: number, h: number, size: number}, thumb: {w: number, h: number}, fullHash: string, thumbHash: string}>`
- `attachChild(googleAuthId: number, parentSku: string, options: {sku: string, childSku?: string, attributeValueId?: number, value?: string, reparent?: boolean, unitamount?: number, weight?: number, track_stock?: boolean|number}, tx?: object): Promise<{article: object, children: Array<object>}>` - `attachChild(googleAuthId: number, parentSku: string, options: {sku: string, childSku?: string, attributeValueId?: number, value?: string, reparent?: boolean, unitamount?: number, weight?: number, track_stock?: boolean|number}, tx?: object): Promise<{article: object, children: Array<object>}>`
- `createUnderParent(input: {googleAuthId: number, parentId: number, name: string, description?: string, desc?: string, seo?: object|string, seoTitle?: string, seoDescription?: string, track_stock?: boolean|number}, tx?: object): Promise<{id: number, parentId: number, name: string, sku: string, track_stock: boolean}>` - `createUnderParent(input: {googleAuthId: number, parentId: number, name: string, desc?: string, seo?: string, track_stock?: boolean|number}, tx?: object): Promise<{id: number, parentId: number, name: string, sku: string, track_stock: boolean}>`
- `delete(googleAuthId: number, sku: string, optionsOrTx?: object|*, maybeTx?: object): Promise<void>` - `delete(googleAuthId: number, sku: string, optionsOrTx?: object|*, maybeTx?: object): Promise<void>`
- `deleteImage(googleAuthId: number, sku: string, fullHash: string, tx?: object): Promise<void>` - `deleteImage(googleAuthId: number, sku: string, fullHash: string, tx?: object): Promise<void>`
- `getBySku(googleAuthId: number, sku: string, tx?: object): Promise<{article: {id: number, sku: string, name: string, slug: string, description: string|null, seo: string|null, seoTitle: string|null, seoDescription: string|null, unitamount: number|null, weight: number|null, track_stock: boolean, unit: {si: string|null, basesi: string|null, basesifactor: number|null, symbol: string|null, name: string|null}, brand: {id: number|null, name: string, fullHash: string|null, thumbW: number|null, thumbH: number|null, thumbHash: string|null}|null, categoryIds: number[], photos: Array<{sort: number, fullHash: string, fullW: number, fullH: number, fullSize: number, thumbW: number, thumbH: number, thumbHash: string}>, eans: string[], prices: Array<{minmultiplier: number, net: number, taxRate: number, customergroupId: number}>, suppliers: Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, sort: number, price: {net: number, taxId: number, taxRate?: number}|null}>, optionsCount: number, articleListCount: number, childCount: number, parentArticleId: number|null, parentSku: string|null}}>` - `getBySku(googleAuthId: number, sku: string, tx?: object): Promise<{article: {id: number, sku: string, name: string, slug: string, desc: string|null, seo: string|null, unitamount: number|null, weight: number|null, track_stock: boolean, unit: {si: string|null, basesi: string|null, basesifactor: number|null, symbol: string|null, name: string|null}, brand: {id: number|null, name: string, fullHash: string|null, thumbW: number|null, thumbH: number|null, thumbHash: string|null}|null, categoryIds: number[], photos: Array<{sort: number, fullHash: string, fullW: number, fullH: number, fullSize: number, thumbW: number, thumbH: number, thumbHash: string}>, eans: string[], prices: Array<{minmultiplier: number, net: number, taxRate: number, customergroupId: number}>, suppliers: Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, sort: number, price: {net: number, taxId: number, taxRate?: number}|null}>, optionsCount: number, articleListCount: number, childCount: number, parentArticleId: number|null, parentSku: string|null}}>`
- `getHistoryBySku(googleAuthId: number, sku: string, opts?: {limit?: number}, tx?: object): Promise<Array<{id: number, companyuserId: number|null, date: string, text: string}>>` - `getHistoryBySku(googleAuthId: number, sku: string, opts?: {limit?: number}, tx?: object): Promise<Array<{id: number, companyuserId: number|null, date: string, text: string}>>`
- `importRows(input: {googleAuthId: number, rows: Array<object>}, tx?: object): Promise<{imported: Array<object>, skipped: Array<object>, errors: Array<object>}>` - `importRows(input: {googleAuthId: number, rows: Array<object>}, tx?: object): Promise<{imported: Array<object>, skipped: Array<object>, errors: Array<object>}>`
- `listChildren(googleAuthId: number, parentSku: string, tx?: object): Promise<Array<{id: number, sku: string, parentsort: number, trackStock: boolean, unitamount: number, weight: number, name: string|null, slug: string|null, attributeValueId: number|null, attributeValue: string|null}>>` - `listChildren(googleAuthId: number, parentSku: string, tx?: object): Promise<Array<{id: number, sku: string, parentsort: number, trackStock: boolean, unitamount: number, weight: number, name: string|null, slug: string|null, attributeValueId: number|null, attributeValue: string|null}>>`
@@ -108,7 +108,7 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met
- `setTrackStockBySku(googleAuthId: number, sku: string, trackStock: boolean|number, tx?: object): Promise<object>` - `setTrackStockBySku(googleAuthId: number, sku: string, trackStock: boolean|number, tx?: object): Promise<object>`
- `setWeightBySku(googleAuthId: number, sku: string, weight: number, tx?: object): Promise<object>` - `setWeightBySku(googleAuthId: number, sku: string, weight: number, tx?: object): Promise<object>`
- `toggleParent(googleAuthId: number, sku: string, options: {isParent: boolean, attributeNameId?: number, parentAttributeNameId?: number}, tx?: object): Promise<object>` - `toggleParent(googleAuthId: number, sku: string, options: {isParent: boolean, attributeNameId?: number, parentAttributeNameId?: number}, tx?: object): Promise<object>`
- `updateBySku(googleAuthId: number, sku: string, patch: {name?: string, description?: string, desc?: string, seo?: object|string, seoTitle?: string, seoDescription?: string, unitSi?: string, unitamount?: number, track_stock?: boolean|number}, tx?: object): Promise<object>` - `updateBySku(googleAuthId: number, sku: string, patch: {name?: string, desc?: string, seo?: string, unitSi?: string, unitamount?: number, track_stock?: boolean|number}, tx?: object): Promise<object>`
- [lang](API.lang.md) - [lang](API.lang.md)
- `create(iso639: string, tx?: object): Promise<number>` - `create(iso639: string, tx?: object): Promise<number>`
- `delete(id: number): Promise<void>` - `delete(id: number): Promise<void>`

View File

@@ -432,7 +432,7 @@ SELECT
a.sku, a.sku,
at.name, at.name,
at.slug, at.slug,
at.[desc] AS description, at.[desc] AS [desc],
at.seo AS seo, at.seo AS seo,
a.unitamount, a.unitamount,
a.weight, a.weight,

View File

@@ -3,7 +3,7 @@ export const ARTICLE_DETAIL_COLUMNS = `
a.sku, a.sku,
at.name, at.name,
at.slug, at.slug,
at.[desc] AS description, at.[desc] AS [desc],
at.seo, at.seo,
a.unitamount, a.unitamount,
a.weight, a.weight,

View File

@@ -122,7 +122,7 @@ WITH auth AS (
SELECT auth.*, SELECT auth.*,
json_object( json_object(
'id', a.id, 'sku', a.sku, 'name', at.name, 'slug', at.slug, 'id', a.id, 'sku', a.sku, 'name', at.name, 'slug', at.slug,
'description', at."desc", 'seo', at.seo, 'desc', at."desc", 'seo', at.seo,
'unitamount', a.unitamount, 'weight', a.weight, 'unitamount', a.unitamount, 'weight', a.weight,
'track_stock', a.track_stock, 'track_stock', a.track_stock,
'unitSi', u.si, 'unitBasesi', u.basesi, 'unitSi', u.si, 'unitBasesi', u.basesi,

View File

@@ -33,11 +33,8 @@ export default function createUnderParent(provider) {
* @param {number} input.googleAuthId - The id of the Google auth user. * @param {number} input.googleAuthId - The id of the Google auth user.
* @param {number} input.parentId - The id of the parent category. * @param {number} input.parentId - The id of the parent category.
* @param {string} input.name - The article name. * @param {string} input.name - The article name.
* @param {string} [input.description] - The article description. * @param {string} [input.desc] - The article description text/HTML.
* @param {string} [input.desc] - Alias for description. * @param {string} [input.seo] - The article SEO text.
* @param {object|string} [input.seo] - The SEO configuration or JSON string.
* @param {string} [input.seoTitle] - The SEO title.
* @param {string} [input.seoDescription] - The SEO meta description.
* @param {boolean|number} [input.track_stock=true] - Whether inventory stock is tracked. * @param {boolean|number} [input.track_stock=true] - Whether inventory stock is tracked.
* @param {object} [tx] - Optional transaction to run within. * @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{id: number, parentId: number, name: string, sku: string, track_stock: boolean}>} The created article. * @returns {Promise<{id: number, parentId: number, name: string, sku: string, track_stock: boolean}>} The created article.
@@ -46,7 +43,7 @@ export default function createUnderParent(provider) {
* const article = await store.article.createUnderParent({ googleAuthId: 42, parentId: 5, name: 'Cola' }); * const article = await store.article.createUnderParent({ googleAuthId: 42, parentId: 5, name: 'Cola' });
* // => { id, parentId, name, sku, track_stock } * // => { id, parentId, name, sku, track_stock }
*/ */
return async ({ googleAuthId, parentId, name, description, desc, shortDescription, seo, seoTitle, seoDescription, track_stock, trackStock, sku: inputSku }, tx) => { return async ({ googleAuthId, parentId, name, desc, description, seo, track_stock, trackStock, sku: inputSku }, tx) => {
const rawTrack = track_stock ?? trackStock; const rawTrack = track_stock ?? trackStock;
const finalTrackStock = rawTrack == null ? 1 : (rawTrack ? 1 : 0); const finalTrackStock = rawTrack == null ? 1 : (rawTrack ? 1 : 0);
@@ -85,23 +82,9 @@ export default function createUnderParent(provider) {
articleId: id, articleId: id,
}); });
const rawDesc = description !== undefined ? description : desc; const rawDesc = desc !== undefined ? desc : description;
const finalDesc = rawDesc != null && rawDesc !== '' ? String(rawDesc) : null; const finalDesc = rawDesc != null && rawDesc !== '' ? String(rawDesc) : null;
let finalSeo = null; const finalSeo = seo != null && seo !== '' ? String(seo) : null;
if (shortDescription !== undefined) {
finalSeo = shortDescription != null && shortDescription !== '' ? String(shortDescription) : null;
} else if (typeof seo === 'string') {
finalSeo = seo !== '' ? seo : null;
} else if (seoDescription && !seoTitle) {
finalSeo = String(seoDescription);
} else if (seo != null) {
finalSeo = typeof seo === 'string' ? seo : JSON.stringify(seo);
} else if (seoTitle || seoDescription) {
finalSeo = JSON.stringify({
title: seoTitle != null && seoTitle !== '' ? String(seoTitle) : '',
description: seoDescription != null && seoDescription !== '' ? String(seoDescription) : '',
});
}
await runner.query(createArticleTextSql, { await runner.query(createArticleTextSql, {
articleId: id, articleId: id,

View File

@@ -18,7 +18,7 @@ export default function getBySku(provider) {
* @param {number} googleAuthId - The id of the Google auth user. * @param {number} googleAuthId - The id of the Google auth user.
* @param {string} sku - The article SKU. * @param {string} sku - The article SKU.
* @param {object} [tx] - Optional transaction. * @param {object} [tx] - Optional transaction.
* @returns {Promise<{article: {id: number, sku: string, name: string, slug: string, description: string|null, seo: string|null, seoTitle: string|null, seoDescription: string|null, unitamount: number|null, weight: number|null, track_stock: boolean, unit: {si: string|null, basesi: string|null, basesifactor: number|null, symbol: string|null, name: string|null}, brand: {id: number|null, name: string, fullHash: string|null, thumbW: number|null, thumbH: number|null, thumbHash: string|null}|null, categoryIds: number[], photos: Array<{sort: number, fullHash: string, fullW: number, fullH: number, fullSize: number, thumbW: number, thumbH: number, thumbHash: string}>, eans: string[], prices: Array<{minmultiplier: number, net: number, taxRate: number, customergroupId: number}>, suppliers: Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, sort: number, price: {net: number, taxId: number, taxRate?: number}|null}>, optionsCount: number, articleListCount: number, childCount: number, parentArticleId: number|null, parentSku: string|null}}>} The full article detail. * @returns {Promise<{article: {id: number, sku: string, name: string, slug: string, desc: string|null, seo: string|null, unitamount: number|null, weight: number|null, track_stock: boolean, unit: {si: string|null, basesi: string|null, basesifactor: number|null, symbol: string|null, name: string|null}, brand: {id: number|null, name: string, fullHash: string|null, thumbW: number|null, thumbH: number|null, thumbHash: string|null}|null, categoryIds: number[], photos: Array<{sort: number, fullHash: string, fullW: number, fullH: number, fullSize: number, thumbW: number, thumbH: number, thumbHash: string}>, eans: string[], prices: Array<{minmultiplier: number, net: number, taxRate: number, customergroupId: number}>, suppliers: Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, sort: number, price: {net: number, taxId: number, taxRate?: number}|null}>, optionsCount: number, articleListCount: number, childCount: number, parentArticleId: number|null, parentSku: string|null}}>} The full article detail.
* @throws {Error} If the article is not found or the user is not authorized. * @throws {Error} If the article is not found or the user is not authorized.
* *
* @example * @example
@@ -26,10 +26,8 @@ export default function getBySku(provider) {
* // => { article: { id, sku, name, unit, brand, categoryIds, photos, eans, prices, ... } } * // => { article: { id, sku, name, unit, brand, categoryIds, photos, eans, prices, ... } }
*/ */
return async (googleAuthId, sku, tx) => { return async (googleAuthId, sku, tx) => {
const t0 = performance.now();
const runner = makeRunner(provider, tx); const runner = makeRunner(provider, tx);
const result = await runner.query(sql, { sku, googleAuthId }); const result = await runner.query(sql, { sku, googleAuthId });
console.log(`[getBySku] single query ${(performance.now() - t0).toFixed(1)}ms`);
const row = result.rows[0]; const row = result.rows[0];
if (!row) { if (!row) {
@@ -45,36 +43,16 @@ export default function getBySku(provider) {
throw new Error('Not authorized'); throw new Error('Not authorized');
} }
const a = typeof row.articleJson === 'string' ? JSON.parse(row.articleJson) : row.articleJson; const a = typeof row.articleJson === 'string' ? JSON.parse(row.articleJson) : row.articleJson;
let seoTitle = null;
let seoDescription = null;
if (a.seo) {
try {
const parsed = typeof a.seo === 'string' ? JSON.parse(a.seo) : a.seo;
if (parsed && typeof parsed === 'object') {
seoTitle = parsed.title ?? parsed.seoTitle ?? null;
seoDescription = parsed.description ?? parsed.seoDescription ?? null;
} else {
seoDescription = String(a.seo);
}
} catch {
seoDescription = String(a.seo);
}
}
return { return {
article: { article: {
id: a.id, id: a.id,
sku: a.sku, sku: a.sku,
name: a.name, name: a.name,
slug: a.slug, slug: a.slug,
description: a.description ?? null, desc: (a.desc ?? a.description) ?? null,
shortDescription: a.seo ?? null,
seo: a.seo ?? null, seo: a.seo ?? null,
seoTitle,
seoDescription: seoDescription ?? (a.seo ? String(a.seo) : null),
unitamount: a.unitamount, unitamount: a.unitamount,
weight: a.weight, weight: a.weight,
track_stock: Boolean(a.track_stock ?? 1), track_stock: Boolean(a.track_stock ?? 1),

View File

@@ -40,11 +40,8 @@ export default function updateBySku(provider) {
* @param {string} sku - The article SKU. * @param {string} sku - The article SKU.
* @param {object} patch - The update patch. * @param {object} patch - The update patch.
* @param {string} [patch.name] - The new article name. * @param {string} [patch.name] - The new article name.
* @param {string} [patch.description] - The article description. * @param {string} [patch.desc] - The article description text/HTML.
* @param {string} [patch.desc] - Alias for description. * @param {string} [patch.seo] - The article SEO text.
* @param {object|string} [patch.seo] - The SEO configuration or JSON string.
* @param {string} [patch.seoTitle] - The SEO title.
* @param {string} [patch.seoDescription] - The SEO meta description.
* @param {string} [patch.unitSi] - The new unit SI code. * @param {string} [patch.unitSi] - The new unit SI code.
* @param {number} [patch.unitamount] - The new unit amount (must be > 0). * @param {number} [patch.unitamount] - The new unit amount (must be > 0).
* @param {boolean|number} [patch.track_stock] - Whether inventory stock is tracked. * @param {boolean|number} [patch.track_stock] - Whether inventory stock is tracked.
@@ -63,15 +60,12 @@ export default function updateBySku(provider) {
const hasTrackStock = const hasTrackStock =
Object.prototype.hasOwnProperty.call(patch, 'track_stock') || Object.prototype.hasOwnProperty.call(patch, 'track_stock') ||
Object.prototype.hasOwnProperty.call(patch, 'trackStock'); Object.prototype.hasOwnProperty.call(patch, 'trackStock');
const hasDescription = const hasDesc =
Object.prototype.hasOwnProperty.call(patch, 'description') || Object.prototype.hasOwnProperty.call(patch, 'desc') ||
Object.prototype.hasOwnProperty.call(patch, 'desc'); Object.prototype.hasOwnProperty.call(patch, 'description');
const hasShortDescription = Object.prototype.hasOwnProperty.call(patch, 'shortDescription');
const hasSeo = Object.prototype.hasOwnProperty.call(patch, 'seo'); const hasSeo = Object.prototype.hasOwnProperty.call(patch, 'seo');
const hasSeoTitle = Object.prototype.hasOwnProperty.call(patch, 'seoTitle');
const hasSeoDescription = Object.prototype.hasOwnProperty.call(patch, 'seoDescription');
if (!hasName && !hasUnitamount && !hasUnitSi && !hasTrackStock && !hasDescription && !hasShortDescription && !hasSeo && !hasSeoTitle && !hasSeoDescription) { if (!hasName && !hasUnitamount && !hasUnitSi && !hasTrackStock && !hasDesc && !hasSeo) {
throw new Error('Name required'); throw new Error('Name required');
} }
@@ -155,16 +149,16 @@ export default function updateBySku(provider) {
); );
} }
} }
if (hasDescription) { if (hasDesc) {
const oldDesc = current.description ?? current.desc ?? ''; const oldDesc = current.desc ?? current.description ?? '';
const rawDesc = patch.description !== undefined ? patch.description : patch.desc; const rawDesc = patch.desc !== undefined ? patch.desc : patch.description;
const newDesc = rawDesc != null ? String(rawDesc) : ''; const newDesc = rawDesc != null ? String(rawDesc) : '';
if (oldDesc !== newDesc) { if (oldDesc !== newDesc) {
historyLines.push('Beschreibung geändert'); historyLines.push('Beschreibung geändert');
} }
} }
const needsTextUpdate = hasName || hasDescription || hasSeo || hasSeoTitle || hasSeoDescription; const needsTextUpdate = hasName || hasDesc || hasSeo;
if (needsTextUpdate) { if (needsTextUpdate) {
const finalName = hasName ? patch.name.trim() : (current.name || ''); const finalName = hasName ? patch.name.trim() : (current.name || '');
const slug = hasName const slug = hasName
@@ -176,37 +170,15 @@ export default function updateBySku(provider) {
}) })
: (current.slug || ''); : (current.slug || '');
let finalDesc = current.description ?? current.desc ?? null; let finalDesc = current.desc ?? current.description ?? null;
if (hasDescription) { if (hasDesc) {
const rawDesc = patch.description !== undefined ? patch.description : patch.desc; const rawDesc = patch.desc !== undefined ? patch.desc : patch.description;
finalDesc = rawDesc != null && rawDesc !== '' ? String(rawDesc) : null; finalDesc = rawDesc != null && rawDesc !== '' ? String(rawDesc) : null;
} }
let finalSeo = current.seo ?? null; let finalSeo = current.seo ?? null;
if (hasShortDescription) { if (hasSeo) {
finalSeo = patch.shortDescription != null && patch.shortDescription !== '' ? String(patch.shortDescription) : null; finalSeo = patch.seo != null && patch.seo !== '' ? String(patch.seo) : null;
} else if (hasSeo && typeof patch.seo === 'string') {
finalSeo = patch.seo !== '' ? patch.seo : null;
} else if (hasSeoDescription && !hasSeoTitle) {
finalSeo = patch.seoDescription != null && patch.seoDescription !== '' ? String(patch.seoDescription) : null;
} else if (hasSeo || hasSeoTitle || hasSeoDescription) {
let seoObj = {};
if (current.seo) {
try {
const parsed = typeof current.seo === 'string' ? JSON.parse(current.seo) : current.seo;
if (parsed && typeof parsed === 'object') seoObj = parsed;
} catch {}
}
if (hasSeo && patch.seo && typeof patch.seo === 'object') {
seoObj = { ...seoObj, ...patch.seo };
}
if (hasSeoTitle) {
seoObj.title = patch.seoTitle != null && patch.seoTitle !== '' ? String(patch.seoTitle) : '';
}
if (hasSeoDescription) {
seoObj.description = patch.seoDescription != null && patch.seoDescription !== '' ? String(patch.seoDescription) : '';
}
finalSeo = Object.keys(seoObj).length > 0 ? JSON.stringify(seoObj) : null;
} }
const update = await runner.query(updateTextSql, { const update = await runner.query(updateTextSql, {