Units are isolated per company; article detail exposes full unit shape, and unused units can be deleted safely via FK NO ACTION.
72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
import {
|
|
GET_CATEGORY_IDS_BY_ARTICLE_ID,
|
|
GET_DETAIL_BY_ARTICLE_ID,
|
|
GET_EANS_BY_ARTICLE_ID,
|
|
GET_PHOTOS_BY_ARTICLE_ID,
|
|
GET_PRICES_BY_ARTICLE_ID,
|
|
} from '../../sql/articleDetail.js';
|
|
|
|
function shapeArticleDetail(row, categoryIds, photos, eans, prices) {
|
|
return {
|
|
id: row.id,
|
|
sku: row.sku,
|
|
name: row.name,
|
|
slug: row.slug,
|
|
unitamount: row.unitamount,
|
|
weight: row.weight,
|
|
unit: {
|
|
si: row.unitSi,
|
|
basesi: row.unitBasesi,
|
|
basesifactor: row.unitBasesifactor,
|
|
symbol: row.unitSymbol ?? null,
|
|
name: row.unitName ?? null,
|
|
},
|
|
brand: row.brandName
|
|
? {
|
|
name: row.brandName,
|
|
thumbW: row.brandThumbW,
|
|
thumbH: row.brandThumbH,
|
|
thumbHash: row.brandThumbHash,
|
|
}
|
|
: null,
|
|
categoryIds: categoryIds.map((r) => r.categoryId),
|
|
photos,
|
|
eans: eans.map((r) => r.ean),
|
|
prices,
|
|
optionsCount: row.optionsCount,
|
|
articleListCount: row.articleListCount,
|
|
childCount: row.childCount,
|
|
fatherArticleId: row.fatherArticleId,
|
|
fatherSku: row.fatherSku,
|
|
};
|
|
}
|
|
|
|
export default function queryBySku(pool) {
|
|
return async (articleId, languageId) => {
|
|
const [detail, categories, photos, eans, prices] = await Promise.all([
|
|
pool
|
|
.request()
|
|
.input('articleId', articleId)
|
|
.input('languageId', languageId)
|
|
.query(GET_DETAIL_BY_ARTICLE_ID),
|
|
pool.request().input('articleId', articleId).query(GET_CATEGORY_IDS_BY_ARTICLE_ID),
|
|
pool.request().input('articleId', articleId).query(GET_PHOTOS_BY_ARTICLE_ID),
|
|
pool.request().input('articleId', articleId).query(GET_EANS_BY_ARTICLE_ID),
|
|
pool.request().input('articleId', articleId).query(GET_PRICES_BY_ARTICLE_ID),
|
|
]);
|
|
|
|
const row = detail.recordset[0];
|
|
if (!row) {
|
|
return null;
|
|
}
|
|
|
|
return shapeArticleDetail(
|
|
row,
|
|
categories.recordset,
|
|
photos.recordset,
|
|
eans.recordset,
|
|
prices.recordset,
|
|
);
|
|
};
|
|
}
|