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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export function register(app, basePath = '') {
|
||||
* @route POST /auth/login
|
||||
* @description Verifies a Google ID token, checks allowlist, and sets an HTTP-only `token` cookie.
|
||||
* @body {string} idToken - Google ID token from Google Identity Services
|
||||
* @returns {Object} 200 - `{ message, user }` with `{ id, email, picture? }` in `user`
|
||||
* @returns {Object} 200 - `{ message, user }` with `{ id, email, selectedCompanyId, picture? }` in `user`
|
||||
* @returns {Object} 400 - Missing token or Google client not configured
|
||||
* @returns {Object} 401 - Invalid Google token
|
||||
* @returns {Object} 403 - Email not on allowlist
|
||||
@@ -43,7 +43,7 @@ export function register(app, basePath = '') {
|
||||
return res.status(401).json({ error: 'Invalid Google account' });
|
||||
}
|
||||
|
||||
const allowed = db.getAllowedEmail(email);
|
||||
const allowed = await db.getAllowedEmail(email);
|
||||
if (!allowed) {
|
||||
console.warn(`Login rejected: email not authorized (${email})`);
|
||||
return res.status(403).json({ error: 'Email is not authorized' });
|
||||
@@ -52,6 +52,7 @@ export function register(app, basePath = '') {
|
||||
const user = {
|
||||
id: allowed.id,
|
||||
email: allowed.email,
|
||||
selectedCompanyId: allowed.selectedCompanyId,
|
||||
...(payload.picture && { picture: payload.picture }),
|
||||
};
|
||||
const token = jwt.sign(user, env.jwtSecret, { expiresIn: '1d' });
|
||||
|
||||
@@ -18,8 +18,8 @@ export function register(app, basePath = '') {
|
||||
if (token) {
|
||||
try {
|
||||
const decoded = jwt.verify(token, env.jwtSecret, { ignoreExpiration: true });
|
||||
if (decoded?.id) {
|
||||
clearCachedUser(decoded.id);
|
||||
if (decoded?.email) {
|
||||
clearCachedUser(decoded.email);
|
||||
}
|
||||
} catch {
|
||||
// Ignore errors during cache clearing on logout
|
||||
|
||||
@@ -9,11 +9,11 @@ export function register(app, basePath = '') {
|
||||
/**
|
||||
* @route GET /auth/me
|
||||
* @description Returns the authenticated user from `req.user` and the Google client ID.
|
||||
* @returns {Object} 200 - `{ user: { id, email, picture? }, googleClientId }`
|
||||
* @returns {Object} 200 - `{ user: { id, email, selectedCompanyId, picture? }, googleClientId }`
|
||||
*/
|
||||
app.get(`${basePath}/auth/me`, (req, res) => {
|
||||
const { id, email, picture } = req.user;
|
||||
const user = { id, email, ...(picture && { picture }) };
|
||||
const { id, email, selectedCompanyId, picture } = req.user;
|
||||
const user = { id, email, selectedCompanyId, ...(picture && { picture }) };
|
||||
meJson(res, 200, { user });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ensureConnection } from '../../db/client.js';
|
||||
import { ensureConnection } from '../../db/store.js';
|
||||
|
||||
/**
|
||||
* Registers a database connectivity health check route.
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { getCategories } from '../../../services/misc/getCategories.js';
|
||||
|
||||
/**
|
||||
* @param {import('express').Application} app
|
||||
* @param {string} [basePath='']
|
||||
*/
|
||||
export function register(app, basePath = '') {
|
||||
/**
|
||||
* @route GET /misc/getCategories
|
||||
* @returns {Object} 200 - `{ categories, tree }`
|
||||
*/
|
||||
app.get(`${basePath}/misc/getCategories`, async (_req, res) => {
|
||||
try {
|
||||
const result = await getCategories();
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { getSteuer } from '../../../services/misc/getSteuer.js';
|
||||
|
||||
/**
|
||||
* @param {import('express').Application} app
|
||||
* @param {string} [basePath='']
|
||||
*/
|
||||
export function register(app, basePath = '') {
|
||||
/**
|
||||
* @route GET /misc/getSteuer
|
||||
* @returns {Object} 200 - `{ steuerklassen }`
|
||||
*/
|
||||
app.get(`${basePath}/misc/getSteuer`, async (_req, res) => {
|
||||
try {
|
||||
res.status(200).json(await getSteuer());
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user