providerrefactor part1

This commit is contained in:
seb
2026-09-21 03:33:55 +02:00
parent 53a20c4353
commit 4ed6260e91
57 changed files with 1662 additions and 145 deletions

View File

@@ -0,0 +1,41 @@
import * as source from '../../mssql/queries/category.js';
import { translateQueries } from './translate.js';
import { ARTICLE_LIST_COLUMNS, ARTICLE_LIST_JOINS } from './article.js';
const queries = translateQueries(source, 'category');
export const {
CREATE, DELETE, GET_BY_PARENT_AND_NAME,
GET_NEXT_SIBLING_SORT, IS_ANCESTOR, LIST_CHILD_IDS,
MOVE, RESOLVE_CATEGORY_ACCESS, UPDATE_SORT,
} = queries;
export const GET_CATEGORY_ARTICLES = `
SELECT ${ARTICLE_LIST_COLUMNS}
FROM categoryarticle ca
INNER JOIN article a ON a.id = ca.article_id
${ARTICLE_LIST_JOINS}
WHERE ca.category_id = @categoryId
ORDER BY a.id
`;
export const GET_TREE_FOR_COMPANY = `
WITH RECURSIVE tree AS (
SELECT id, parent_id, sort FROM category WHERE id = @rootId
UNION ALL
SELECT c.id, c.parent_id, c.sort
FROM category c INNER JOIN tree t ON c.parent_id = t.id
)
SELECT
t.id, t.parent_id AS parentId, t.sort, ct.name, ct.slug,
p.hash AS fullHash, p.thumbw AS thumbW, p.thumbh AS thumbH,
p.thumbhash AS thumbHash
FROM tree t
LEFT JOIN categorytext ct
ON ct.category_id = t.id AND ct.language_id = @languageId
LEFT JOIN pic p ON p.id = (
SELECT cp.pic_id FROM categorypic cp
WHERE cp.category_id = t.id
ORDER BY cp.sort, cp.id LIMIT 1
)
ORDER BY t.sort, t.id
`;