This commit is contained in:
seb
2026-08-01 01:36:44 +02:00
parent 9582370b0b
commit 6d720d34ed
6 changed files with 79 additions and 5 deletions

View File

@@ -10,6 +10,24 @@ export function primaryPhoto(article) {
return photos[0] ?? null;
}
/** Map POST /api/article/:sku/image → photos[] entry shape. */
export function photoFromUploadedImage(image) {
return {
sort: image.sort,
thumbW: image.thumb.w,
thumbH: image.thumb.h,
thumbHash: image.thumbHash,
};
}
export function articleWithUploadedPhoto(article, image) {
const photo = photoFromUploadedImage(image);
const photos = sortedPhotos(article).filter((row) => row.sort !== photo.sort);
photos.push(photo);
photos.sort((a, b) => a.sort - b.sort);
return { ...article, photos };
}
export function primaryPrice(article) {
if (!Array.isArray(article?.prices) || article.prices.length === 0) return null;
return article.prices.find((row) => row.minmultiplier === 1) ?? article.prices[0];