u
This commit is contained in:
@@ -1,26 +1,15 @@
|
||||
import { GET_CATEGORY_ID_BY_SKU } from '../../sql/article.js';
|
||||
import { ADD as ADD_ARTICLEPIC, GET_NEXT_SORT } from '../../sql/articlepic.js';
|
||||
import { CREATE as CREATE_PIC } from '../../sql/pic.js';
|
||||
import processAvifImage from '../../util/processAvifImage.js';
|
||||
import newFullHash from '../../util/newFullHash.js';
|
||||
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
|
||||
import request from '../request.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
|
||||
export default function addImage(pool) {
|
||||
const access = resolveCategoryAccess(pool);
|
||||
const resolve = resolveArticleBySku(pool);
|
||||
|
||||
return async (googleAuthId, sku, image) => {
|
||||
const categoryLookup = await pool
|
||||
.request()
|
||||
.input('sku', sku)
|
||||
.query(GET_CATEGORY_ID_BY_SKU);
|
||||
|
||||
const row = categoryLookup.recordset[0];
|
||||
if (!row?.categoryId || !row?.articleId) {
|
||||
throw new Error('Article not found');
|
||||
}
|
||||
|
||||
await access(googleAuthId, row.categoryId);
|
||||
const { articleId } = await resolve(googleAuthId, sku);
|
||||
|
||||
const processed = await processAvifImage(image);
|
||||
|
||||
@@ -29,7 +18,7 @@ export default function addImage(pool) {
|
||||
|
||||
try {
|
||||
const sortResult = await request(pool, tx)
|
||||
.input('articleId', row.articleId)
|
||||
.input('articleId', articleId)
|
||||
.query(GET_NEXT_SORT);
|
||||
|
||||
const sort = sortResult.recordset[0].sort;
|
||||
@@ -51,7 +40,7 @@ export default function addImage(pool) {
|
||||
const picId = picResult.recordset[0].id;
|
||||
|
||||
await request(pool, tx)
|
||||
.input('articleId', row.articleId)
|
||||
.input('articleId', articleId)
|
||||
.input('picId', picId)
|
||||
.input('sort', sort)
|
||||
.query(ADD_ARTICLEPIC);
|
||||
|
||||
Reference in New Issue
Block a user