Initial commit
This commit is contained in:
94
Docker Backend/src/api/routes/order-routes.js
Normal file
94
Docker Backend/src/api/routes/order-routes.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const multer = require('multer');
|
||||
const orderController = require('../controllers/order-controller');
|
||||
const { authenticateApiToken } = require('../middleware/auth');
|
||||
|
||||
// Multer konfigurieren für Datei-Uploads (temporär im Speicher)
|
||||
const upload = multer({
|
||||
storage: multer.memoryStorage(),
|
||||
limits: {
|
||||
fileSize: 10 * 1024 * 1024, // 10MB max
|
||||
},
|
||||
fileFilter: (req, file, cb) => {
|
||||
// Erlaubte Dateitypen
|
||||
const allowedTypes = ['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml', 'application/pdf'];
|
||||
const allowedExts = ['.png', '.jpg', '.jpeg', '.webp', '.svg', '.pdf'];
|
||||
|
||||
const ext = file.originalname.toLowerCase().substring(file.originalname.lastIndexOf('.'));
|
||||
|
||||
if (allowedTypes.includes(file.mimetype) || allowedExts.includes(ext)) {
|
||||
cb(null, true);
|
||||
} else {
|
||||
cb(new Error('Nur PNG, JPG, WEBP, SVG und PDF Dateien sind erlaubt'), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/order/finalize
|
||||
* Finalize order by copying cached previews to output directory
|
||||
*
|
||||
* Request body:
|
||||
* {
|
||||
* sessionId: string,
|
||||
* orderNumber: string
|
||||
* }
|
||||
*
|
||||
* Response:
|
||||
* {
|
||||
* orderNumber: string,
|
||||
* outputPath: string,
|
||||
* files: string[],
|
||||
* timestamp: string
|
||||
* }
|
||||
*/
|
||||
router.post('/finalize', authenticateApiToken, orderController.finalizeOrder);
|
||||
|
||||
/**
|
||||
* POST /api/order/generate
|
||||
* Generate order from scratch without using cache
|
||||
*
|
||||
* Request body:
|
||||
* {
|
||||
* orderNumber: string,
|
||||
* letters: [
|
||||
* {
|
||||
* text: string,
|
||||
* format: 'a4' | 'a6p' | 'a6l' | 'c6' | 'din_lang',
|
||||
* font: 'tilda' | 'alva' | 'ellie',
|
||||
* type?: 'letter' | 'envelope',
|
||||
* envelopeType?: 'recipient' | 'custom',
|
||||
* placeholders?: { [key: string]: string }
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*
|
||||
* Response:
|
||||
* {
|
||||
* orderNumber: string,
|
||||
* outputPath: string,
|
||||
* files: string[],
|
||||
* timestamp: string
|
||||
* }
|
||||
*/
|
||||
router.post('/generate', authenticateApiToken, orderController.generateOrder);
|
||||
|
||||
/**
|
||||
* POST /api/order/motif
|
||||
* Upload a motif image for an order
|
||||
*
|
||||
* Request: multipart/form-data
|
||||
* - motif: file (PNG, JPG, WEBP, SVG, PDF)
|
||||
* - orderNumber: string
|
||||
*
|
||||
* Response:
|
||||
* {
|
||||
* success: boolean,
|
||||
* filename: string,
|
||||
* path: string
|
||||
* }
|
||||
*/
|
||||
router.post('/motif', authenticateApiToken, upload.single('motif'), orderController.uploadMotif);
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user