u
This commit is contained in:
@@ -2,6 +2,7 @@ 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';
|
||||
|
||||
@@ -32,12 +33,13 @@ export default function addImage(pool) {
|
||||
.query(GET_NEXT_SORT);
|
||||
|
||||
const sort = sortResult.recordset[0].sort;
|
||||
const fullHash = newFullHash();
|
||||
|
||||
const picResult = await request(pool, tx)
|
||||
.input('w', processed.full.w)
|
||||
.input('h', processed.full.h)
|
||||
.input('size', processed.full.size)
|
||||
.input('hash', processed.full.hash)
|
||||
.input('hash', fullHash)
|
||||
.input('thumbw', processed.thumb.w)
|
||||
.input('thumbh', processed.thumb.h)
|
||||
.input('thumbhash', processed.thumb.hash)
|
||||
@@ -68,7 +70,7 @@ export default function addImage(pool) {
|
||||
w: processed.thumb.w,
|
||||
h: processed.thumb.h,
|
||||
},
|
||||
fullHash: processed.full.hash,
|
||||
fullHash,
|
||||
thumbHash: processed.thumb.hash,
|
||||
};
|
||||
} catch (err) {
|
||||
|
||||
88
src/store/article/delete.js
Normal file
88
src/store/article/delete.js
Normal file
@@ -0,0 +1,88 @@
|
||||
import {
|
||||
DELETE_ARTICLELIST,
|
||||
DELETE_BY_ID,
|
||||
DELETE_OPTIONSLIST,
|
||||
DELETE_PICS_BY_ARTICLE,
|
||||
DETACH_MANIFEST_ARTICLES,
|
||||
GET_CHILD_COUNT,
|
||||
GET_LIST_IDS,
|
||||
GET_NAME_FOR_DELETE,
|
||||
} from '../../sql/articleDelete.js';
|
||||
import resolveArticleBySku from './resolveArticleBySku.js';
|
||||
import request from '../request.js';
|
||||
|
||||
export default function del(pool) {
|
||||
const resolve = resolveArticleBySku(pool);
|
||||
|
||||
return async (googleAuthId, sku) => {
|
||||
const { articleId, languageId } = await resolve(googleAuthId, sku);
|
||||
|
||||
const childCount = await pool
|
||||
.request()
|
||||
.input('articleId', articleId)
|
||||
.query(GET_CHILD_COUNT);
|
||||
|
||||
if (childCount.recordset[0].count > 0) {
|
||||
throw new Error('Article has children');
|
||||
}
|
||||
|
||||
const nameResult = await pool
|
||||
.request()
|
||||
.input('articleId', articleId)
|
||||
.input('languageId', languageId)
|
||||
.query(GET_NAME_FOR_DELETE);
|
||||
|
||||
const name = nameResult.recordset[0]?.name ?? sku;
|
||||
const suffix = `article ${name} deleted`;
|
||||
|
||||
const listIds = await pool
|
||||
.request()
|
||||
.input('articleId', articleId)
|
||||
.query(GET_LIST_IDS);
|
||||
|
||||
const { articlelistId, optionslistId } = listIds.recordset[0] ?? {};
|
||||
|
||||
const tx = pool.transaction();
|
||||
await tx.begin();
|
||||
|
||||
try {
|
||||
await request(pool, tx)
|
||||
.input('articleId', articleId)
|
||||
.input('suffix', suffix)
|
||||
.query(DETACH_MANIFEST_ARTICLES);
|
||||
|
||||
await request(pool, tx)
|
||||
.input('articleId', articleId)
|
||||
.query(DELETE_PICS_BY_ARTICLE);
|
||||
|
||||
const deleted = await request(pool, tx)
|
||||
.input('articleId', articleId)
|
||||
.query(DELETE_BY_ID);
|
||||
|
||||
if (!deleted.rowsAffected[0]) {
|
||||
throw new Error('Article not found');
|
||||
}
|
||||
|
||||
if (articlelistId != null) {
|
||||
await request(pool, tx)
|
||||
.input('id', articlelistId)
|
||||
.query(DELETE_ARTICLELIST);
|
||||
}
|
||||
|
||||
if (optionslistId != null) {
|
||||
await request(pool, tx)
|
||||
.input('id', optionslistId)
|
||||
.query(DELETE_OPTIONSLIST);
|
||||
}
|
||||
|
||||
await tx.commit();
|
||||
} catch (err) {
|
||||
try {
|
||||
await tx.rollback();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -15,11 +15,12 @@ export default function resolveArticleBySku(pool) {
|
||||
throw new Error('Article not found');
|
||||
}
|
||||
|
||||
await access(googleAuthId, row.categoryId);
|
||||
const { languageId } = await access(googleAuthId, row.categoryId);
|
||||
|
||||
return {
|
||||
articleId: row.articleId,
|
||||
categoryId: row.categoryId,
|
||||
languageId,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user