u
This commit is contained in:
@@ -33,6 +33,11 @@ export default function createUnderParent(provider) {
|
||||
* @param {number} input.googleAuthId - The id of the Google auth user.
|
||||
* @param {number} input.parentId - The id of the parent category.
|
||||
* @param {string} input.name - The article name.
|
||||
* @param {string} [input.description] - The article description.
|
||||
* @param {string} [input.desc] - Alias for description.
|
||||
* @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 {object} [tx] - Optional transaction to run within.
|
||||
* @returns {Promise<{id: number, parentId: number, name: string, sku: string, track_stock: boolean}>} The created article.
|
||||
@@ -41,7 +46,7 @@ export default function createUnderParent(provider) {
|
||||
* const article = await store.article.createUnderParent({ googleAuthId: 42, parentId: 5, name: 'Cola' });
|
||||
* // => { id, parentId, name, sku, track_stock }
|
||||
*/
|
||||
return async ({ googleAuthId, parentId, name, track_stock, trackStock, sku: inputSku }, tx) => {
|
||||
return async ({ googleAuthId, parentId, name, description, desc, shortDescription, seo, seoTitle, seoDescription, track_stock, trackStock, sku: inputSku }, tx) => {
|
||||
const rawTrack = track_stock ?? trackStock;
|
||||
const finalTrackStock = rawTrack == null ? 1 : (rawTrack ? 1 : 0);
|
||||
|
||||
@@ -80,11 +85,31 @@ export default function createUnderParent(provider) {
|
||||
articleId: id,
|
||||
});
|
||||
|
||||
const rawDesc = description !== undefined ? description : desc;
|
||||
const finalDesc = rawDesc != null && rawDesc !== '' ? String(rawDesc) : null;
|
||||
let finalSeo = 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, {
|
||||
articleId: id,
|
||||
languageId,
|
||||
name,
|
||||
slug,
|
||||
desc: finalDesc,
|
||||
seo: finalSeo,
|
||||
});
|
||||
|
||||
await runner.query(insertHistorySql, {
|
||||
|
||||
Reference in New Issue
Block a user