29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
import {
|
|
DELETE_BY_ARTICLE_AND_PROPERTY_ID as MSSQL_DELETE,
|
|
} from '../../providers/mssql/queries/articleproperty.js';
|
|
import {
|
|
DELETE_BY_ARTICLE_AND_PROPERTY_ID as SQLITE_DELETE,
|
|
} from '../../providers/sqlite3/queries/articleproperty.js';
|
|
import resolveArticleBySku from '../article/resolveArticleBySku.js';
|
|
import makeRunner from '../runner.js';
|
|
|
|
export default function deleteArticleProperty(provider) {
|
|
const resolve = resolveArticleBySku(provider);
|
|
const deleteSql = provider?.dialect === 'sqlite3' ? SQLITE_DELETE : MSSQL_DELETE;
|
|
|
|
/**
|
|
* Deletes a property from an article by SKU and propertyId.
|
|
*
|
|
* @param {number} googleAuthId - The id of the Google auth user.
|
|
* @param {string} sku - The article SKU.
|
|
* @param {number} propertyId - The property id.
|
|
* @param {object} [tx] - Optional transaction.
|
|
* @returns {Promise<void>}
|
|
*/
|
|
return async (googleAuthId, sku, propertyId, tx) => {
|
|
const runner = makeRunner(provider, tx);
|
|
const { articleId } = await resolve(googleAuthId, sku, runner);
|
|
await runner.query(deleteSql, { articleId, propertyId });
|
|
};
|
|
}
|