Stage after merging with project files
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { query } from '../db/pool.js';
|
||||
import { parseJsonColumn } from '../utils/json.js';
|
||||
|
||||
export async function getImageRules() {
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT
|
||||
code,
|
||||
name,
|
||||
allowed_mime_types_json AS allowedMimeTypes,
|
||||
max_file_size_bytes AS maxFileSizeBytes,
|
||||
max_width_px AS maxWidthPx,
|
||||
max_height_px AS maxHeightPx,
|
||||
jpeg_quality AS jpegQuality,
|
||||
oversize_behavior AS oversizeBehavior,
|
||||
max_attachments_per_field AS maxAttachmentsPerField
|
||||
FROM image_rules
|
||||
WHERE is_active = 1
|
||||
ORDER BY id DESC
|
||||
LIMIT 1
|
||||
`
|
||||
);
|
||||
|
||||
if (!rows.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
...rows[0],
|
||||
allowedMimeTypes: parseJsonColumn(rows[0].allowedMimeTypes, [])
|
||||
};
|
||||
}
|
||||
|
||||
export async function getExportProfile() {
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT
|
||||
code,
|
||||
name,
|
||||
zip_image_dir AS zipImageDir,
|
||||
excel_sheet_name AS excelSheetName,
|
||||
include_template_version AS includeTemplateVersion,
|
||||
include_export_timestamp AS includeExportTimestamp
|
||||
FROM export_profiles
|
||||
WHERE is_active = 1
|
||||
ORDER BY id DESC
|
||||
LIMIT 1
|
||||
`
|
||||
);
|
||||
|
||||
return rows.length ? rows[0] : null;
|
||||
}
|
||||
|
||||
export async function getAppConfig() {
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT
|
||||
config_key AS configKey,
|
||||
config_value_json AS configValue
|
||||
FROM app_config
|
||||
ORDER BY config_key ASC
|
||||
`
|
||||
);
|
||||
|
||||
return rows.map((row) => ({
|
||||
key: row.configKey,
|
||||
value: parseJsonColumn(row.configValue)
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { query } from '../db/pool.js';
|
||||
|
||||
function groupLookups(rows) {
|
||||
const lookups = new Map();
|
||||
|
||||
for (const row of rows) {
|
||||
if (!lookups.has(row.lookupCode)) {
|
||||
lookups.set(row.lookupCode, {
|
||||
code: row.lookupCode,
|
||||
name: row.lookupName,
|
||||
values: []
|
||||
});
|
||||
}
|
||||
|
||||
if (row.value !== null) {
|
||||
lookups.get(row.lookupCode).values.push({
|
||||
value: row.value,
|
||||
label: row.label,
|
||||
sortOrder: row.sortOrder,
|
||||
isDefault: Boolean(row.isDefault)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(lookups.values());
|
||||
}
|
||||
|
||||
export async function listLookups() {
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT
|
||||
ls.code AS lookupCode,
|
||||
ls.name AS lookupName,
|
||||
lv.value,
|
||||
lv.label,
|
||||
lv.sort_order AS sortOrder,
|
||||
lv.is_default AS isDefault
|
||||
FROM lookup_sets ls
|
||||
LEFT JOIN lookup_values lv
|
||||
ON lv.lookup_set_id = ls.id
|
||||
AND lv.is_active = 1
|
||||
WHERE ls.is_active = 1
|
||||
ORDER BY ls.code ASC, lv.sort_order ASC, lv.id ASC
|
||||
`
|
||||
);
|
||||
|
||||
return groupLookups(rows);
|
||||
}
|
||||
|
||||
export async function getLookup(lookupCode) {
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT
|
||||
ls.code AS lookupCode,
|
||||
ls.name AS lookupName,
|
||||
lv.value,
|
||||
lv.label,
|
||||
lv.sort_order AS sortOrder,
|
||||
lv.is_default AS isDefault
|
||||
FROM lookup_sets ls
|
||||
LEFT JOIN lookup_values lv
|
||||
ON lv.lookup_set_id = ls.id
|
||||
AND lv.is_active = 1
|
||||
WHERE ls.code = ?
|
||||
AND ls.is_active = 1
|
||||
ORDER BY lv.sort_order ASC, lv.id ASC
|
||||
`,
|
||||
[lookupCode]
|
||||
);
|
||||
|
||||
if (!rows.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return groupLookups(rows)[0];
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { query } from '../db/pool.js';
|
||||
import { parseJsonColumn } from '../utils/json.js';
|
||||
|
||||
function mapTemplateRow(row) {
|
||||
return {
|
||||
code: row.code,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
version: row.versionNumber,
|
||||
status: row.status,
|
||||
publishedAt: row.publishedAt,
|
||||
definition: parseJsonColumn(row.definitionJson)
|
||||
};
|
||||
}
|
||||
|
||||
export async function listTemplates() {
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT
|
||||
t.code,
|
||||
t.name,
|
||||
t.description,
|
||||
tv.version_number AS versionNumber,
|
||||
tv.status,
|
||||
tv.published_at AS publishedAt
|
||||
FROM templates t
|
||||
INNER JOIN template_versions tv
|
||||
ON tv.template_id = t.id
|
||||
AND tv.status = 'active'
|
||||
ORDER BY t.name ASC
|
||||
`
|
||||
);
|
||||
|
||||
return rows.map((row) => ({
|
||||
code: row.code,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
activeVersion: row.versionNumber,
|
||||
publishedAt: row.publishedAt
|
||||
}));
|
||||
}
|
||||
|
||||
export async function getActiveTemplate(templateCode) {
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT
|
||||
t.code,
|
||||
t.name,
|
||||
t.description,
|
||||
tv.version_number AS versionNumber,
|
||||
tv.status,
|
||||
tv.published_at AS publishedAt,
|
||||
tv.definition_json AS definitionJson
|
||||
FROM templates t
|
||||
INNER JOIN template_versions tv
|
||||
ON tv.template_id = t.id
|
||||
AND tv.status = 'active'
|
||||
WHERE t.code = ?
|
||||
LIMIT 1
|
||||
`,
|
||||
[templateCode]
|
||||
);
|
||||
|
||||
return rows.length ? mapTemplateRow(rows[0]) : null;
|
||||
}
|
||||
|
||||
export async function getTemplateVersion(templateCode, versionNumber) {
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT
|
||||
t.code,
|
||||
t.name,
|
||||
t.description,
|
||||
tv.version_number AS versionNumber,
|
||||
tv.status,
|
||||
tv.published_at AS publishedAt,
|
||||
tv.definition_json AS definitionJson
|
||||
FROM templates t
|
||||
INNER JOIN template_versions tv
|
||||
ON tv.template_id = t.id
|
||||
WHERE t.code = ?
|
||||
AND tv.version_number = ?
|
||||
LIMIT 1
|
||||
`,
|
||||
[templateCode, Number(versionNumber)]
|
||||
);
|
||||
|
||||
return rows.length ? mapTemplateRow(rows[0]) : null;
|
||||
}
|
||||
Reference in New Issue
Block a user