u
This commit is contained in:
66
src/store/article/queryBySku.js
Normal file
66
src/store/article/queryBySku.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
GET_CATEGORY_IDS_BY_ARTICLE_ID,
|
||||
GET_DETAIL_BY_SKU,
|
||||
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 },
|
||||
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 (sku, languageId) => {
|
||||
const detail = await pool
|
||||
.request()
|
||||
.input('sku', sku)
|
||||
.input('languageId', languageId)
|
||||
.query(GET_DETAIL_BY_SKU);
|
||||
|
||||
const row = detail.recordset[0];
|
||||
if (!row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [categories, photos, eans, prices] = await Promise.all([
|
||||
pool.request().input('articleId', row.id).query(GET_CATEGORY_IDS_BY_ARTICLE_ID),
|
||||
pool.request().input('articleId', row.id).query(GET_PHOTOS_BY_ARTICLE_ID),
|
||||
pool.request().input('articleId', row.id).query(GET_EANS_BY_ARTICLE_ID),
|
||||
pool.request().input('articleId', row.id).query(GET_PRICES_BY_ARTICLE_ID),
|
||||
]);
|
||||
|
||||
return shapeArticleDetail(
|
||||
row,
|
||||
categories.recordset,
|
||||
photos.recordset,
|
||||
eans.recordset,
|
||||
prices.recordset,
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user