u
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import { parseFilter, searchArticles } from '../../../services/article/searchArticles.js';
|
||||
|
||||
/**
|
||||
* Registers the article search 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/search
|
||||
* @description Search articles by partial match on name, number, EAN, barcode, or supplier number.
|
||||
* @query {string} target - Space-separated search terms
|
||||
* @query {string} [filter] - Optional comma-separated category filter IDs (empty = all)
|
||||
* @query {number} [offset=0] - Number of results to skip
|
||||
* @query {number} [maxCount=10] - Maximum number of results to return
|
||||
* @returns {Object} 200 - `{ categories, length, recordset }`
|
||||
* @returns {Object} 400 - `{ error }` when target is missing
|
||||
*/
|
||||
app.get(`${basePath}/article/search`, 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 filter = parseFilter(req.query.filter);
|
||||
const offset = req.query.offset !== undefined ? Number(req.query.offset) : 0;
|
||||
const maxCount = req.query.maxCount !== undefined ? Number(req.query.maxCount) : 10;
|
||||
const result = await searchArticles(String(target), filter, offset, maxCount);
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
return res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user