import { DELETE_BY_ARTICLE_AND_HASH } from '../../providers/mssql/queries/pic.js'; import resolveArticleBySku from './resolveArticleBySku.js'; export default function deleteImage(pool) { const resolve = resolveArticleBySku(pool); /** * Deletes an image from an article by its SKU and full image hash. * * @param {number} googleAuthId - The id of the Google auth user. * @param {string} sku - The article SKU. * @param {string} fullHash - The full image hash to delete. * @returns {Promise} * @throws {Error} If the image is not found. * * @example * await store.article.deleteImage(42, 'SKU-1', 'abc123'); */ return async (googleAuthId, sku, fullHash) => { const { articleId } = await resolve(googleAuthId, sku); const result = await pool .request() .input('articleId', articleId) .input('fullHash', fullHash) .query(DELETE_BY_ARTICLE_AND_HASH); if (!result.rowsAffected[0]) { throw new Error('Image not found'); } }; }