feat(backend, frontend): Hinzufügen von Funktionen zur Verwaltung von Lagerbeständen im Falukant-System
- Implementierung von Methoden zur Hinzufügung und Abfrage von Lagerbeständen im AdminController und AdminService. - Erweiterung der Routen im AdminRouter zur Unterstützung der neuen Lagerverwaltungsfunktionen. - Anpassung der Benutzeroberfläche zur Integration eines Dialogs für die Lagerhinzufügung und zur Anzeige von Lagertypen. - Aktualisierung der Übersetzungen in den Sprachdateien für die neuen Funktionen und Fehlermeldungen.
This commit is contained in:
@@ -15,6 +15,8 @@ class AdminController {
|
||||
this.changeFalukantUser = this.changeFalukantUser.bind(this);
|
||||
this.getFalukantUserBranches = this.getFalukantUserBranches.bind(this);
|
||||
this.updateFalukantStock = this.updateFalukantStock.bind(this);
|
||||
this.addFalukantStock = this.addFalukantStock.bind(this);
|
||||
this.getFalukantStockTypes = this.getFalukantStockTypes.bind(this);
|
||||
this.getRoomTypes = this.getRoomTypes.bind(this);
|
||||
this.getGenderRestrictions = this.getGenderRestrictions.bind(this);
|
||||
this.getUserRights = this.getUserRights.bind(this);
|
||||
@@ -164,6 +166,29 @@ class AdminController {
|
||||
}
|
||||
}
|
||||
|
||||
async addFalukantStock(req, res) {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { branchId, stockTypeId, quantity } = req.body;
|
||||
const response = await AdminService.addFalukantStock(userId, branchId, stockTypeId, quantity);
|
||||
res.status(200).json(response);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(403).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async getFalukantStockTypes(req, res) {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const response = await AdminService.getFalukantStockTypes(userId);
|
||||
res.status(200).json(response);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(403).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async getRoomTypes(req, res) {
|
||||
try {
|
||||
const userId = req.headers.userid;
|
||||
|
||||
@@ -26,6 +26,8 @@ router.get('/falukant/getuser/:id', authenticate, adminController.getFalukantUse
|
||||
router.post('/falukant/edituser', authenticate, adminController.changeFalukantUser);
|
||||
router.get('/falukant/branches/:falukantUserId', authenticate, adminController.getFalukantUserBranches);
|
||||
router.put('/falukant/stock/:stockId', authenticate, adminController.updateFalukantStock);
|
||||
router.post('/falukant/stock', authenticate, adminController.addFalukantStock);
|
||||
router.get('/falukant/stock-types', authenticate, adminController.getFalukantStockTypes);
|
||||
|
||||
// --- Minigames Admin ---
|
||||
router.get('/minigames/match3/campaigns', authenticate, adminController.getMatch3Campaigns);
|
||||
|
||||
@@ -313,6 +313,62 @@ class AdminService {
|
||||
return stock;
|
||||
}
|
||||
|
||||
async addFalukantStock(userId, branchId, stockTypeId, quantity) {
|
||||
if (!(await this.hasUserAccess(userId, 'falukantusers'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
|
||||
// Prüfe ob Branch existiert
|
||||
const branch = await Branch.findByPk(branchId);
|
||||
if (!branch) {
|
||||
throw new Error('Branch not found');
|
||||
}
|
||||
|
||||
// Prüfe ob StockType existiert
|
||||
const stockType = await FalukantStockType.findByPk(stockTypeId);
|
||||
if (!stockType) {
|
||||
throw new Error('Stock type not found');
|
||||
}
|
||||
|
||||
// Prüfe ob bereits ein Stock dieses Typs für diesen Branch existiert
|
||||
const existingStock = await FalukantStock.findOne({
|
||||
where: {
|
||||
branchId: branchId,
|
||||
stockTypeId: stockTypeId
|
||||
}
|
||||
});
|
||||
|
||||
if (existingStock) {
|
||||
throw new Error('Stock of this type already exists for this branch');
|
||||
}
|
||||
|
||||
// Erstelle neuen Stock
|
||||
const newStock = await FalukantStock.create({
|
||||
branchId: branchId,
|
||||
stockTypeId: stockTypeId,
|
||||
quantity: quantity
|
||||
});
|
||||
|
||||
// Lade den neuen Stock mit allen Beziehungen
|
||||
const stockWithData = await FalukantStock.findByPk(newStock.id, {
|
||||
include: [{ model: FalukantStockType, as: 'stockType', attributes: ['labelTr'] }]
|
||||
});
|
||||
|
||||
return stockWithData;
|
||||
}
|
||||
|
||||
async getFalukantStockTypes(userId) {
|
||||
if (!(await this.hasUserAccess(userId, 'falukantusers'))) {
|
||||
throw new Error('noaccess');
|
||||
}
|
||||
|
||||
const stockTypes = await FalukantStockType.findAll({
|
||||
attributes: ['id', 'labelTr']
|
||||
});
|
||||
|
||||
return stockTypes;
|
||||
}
|
||||
|
||||
async changeFalukantUser(userId, falukantUserId, falukantData) {
|
||||
if (!(await this.hasUserAccess(userId, 'falukantusers'))) {
|
||||
throw new Error('noaccess');
|
||||
|
||||
Reference in New Issue
Block a user