This commit is contained in:
seb
2026-06-24 09:37:34 +02:00
parent 977ece3099
commit 185b68fe52
16 changed files with 1312 additions and 89 deletions

View File

@@ -0,0 +1,34 @@
import { getArticle } from '../../../services/article/getArticle.js';
/**
* Registers the full article lookup route backed by MSSQL.
* @param {import('express').Application} app - Express app
* @param {string} [basePath=''] - Optional URL prefix for all routes in this module
*/
export function register(app, basePath = '') {
/**
* @route GET /article/get
* @description Look up a single article by exact article number, EAN, or barcode.
* @query {string} target - Article number, packaging EAN, or barcode
* @returns {Object} 200 - `{ article }` with enriched article data
* @returns {Object} 400 - `{ error }` when target is missing
* @returns {Object} 404 - `{ error }` when no article matches
*/
app.get(`${basePath}/article/get`, async (req, res) => {
const target = req.query.target;
if (!target || !String(target).trim()) {
return res.status(400).json({ error: 'Query parameter "target" is required' });
}
try {
const article = await getArticle(String(target));
if (!article) {
return res.status(404).json({ error: 'Article not found' });
}
return res.status(200).json({ article });
} catch (error) {
return res.status(500).json({ error: error.message });
}
});
}