u
This commit is contained in:
34
src/store/articleattributevalue/listByArticleSku.js
Normal file
34
src/store/articleattributevalue/listByArticleSku.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { LIST_BY_ARTICLE_ID as MSSQL_QUERY } from '../../providers/mssql/queries/articleattributevalue.js';
|
||||
import { LIST_BY_ARTICLE_ID as SQLITE_QUERY } from '../../providers/sqlite3/queries/articleattributevalue.js';
|
||||
import resolveArticleBySku from '../article/resolveArticleBySku.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function listByArticleSku(provider) {
|
||||
const resolve = resolveArticleBySku(provider);
|
||||
const sql = provider?.dialect === 'sqlite3' ? SQLITE_QUERY : MSSQL_QUERY;
|
||||
|
||||
/**
|
||||
* Lists the attribute values assigned to an article by its SKU.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {string} sku - The article SKU.
|
||||
* @param {object} [tx] - Optional transaction.
|
||||
* @returns {Promise<Array<{id: number, articleId: number, attributeId: number, attributeName: string, exclusive: boolean, attributeValueId: number, value: string, sort: number}>>}
|
||||
*/
|
||||
return async (googleAuthId, sku, tx) => {
|
||||
const runner = makeRunner(provider, tx);
|
||||
const { articleId } = await resolve(googleAuthId, sku, runner);
|
||||
|
||||
const result = await runner.query(sql, { articleId });
|
||||
return result.rows.map((row) => ({
|
||||
id: row.id,
|
||||
articleId: row.articleId,
|
||||
attributeId: row.attributeId,
|
||||
attributeName: row.attributeName,
|
||||
exclusive: Boolean(row.exclusive),
|
||||
attributeValueId: row.attributeValueId,
|
||||
value: row.value,
|
||||
sort: row.sort,
|
||||
}));
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user