Director hiring added

This commit is contained in:
Torsten Schulz
2025-01-09 15:31:55 +01:00
parent 6f7d97672e
commit 2f60741116
30 changed files with 2368 additions and 751 deletions

View File

@@ -9,6 +9,18 @@ class FalukantController {
this.getInfo = this.getInfo.bind(this);
this.getInventory = this.getInventory.bind(this);
this.sellProduct = this.sellProduct.bind(this);
this.sellAllProducts = this.sellAllProducts.bind(this);
this.moneyHistory = this.moneyHistory.bind(this);
this.getStorage = this.getStorage.bind(this);
this.buyStorage = this.buyStorage.bind(this);
this.sellStorage = this.sellStorage.bind(this);
this.getStockTypes = this.getStockTypes.bind(this);
this.getStockOverview = this.getStockOverview.bind(this);
this.getAllProductions = this.getAllProductions.bind(this);
this.getDirectorProposals = this.getDirectorProposals.bind(this);
this.convertProposalToDirector = this.convertProposalToDirector.bind(this);
this.getDirectorForBranch = this.getDirectorForBranch.bind(this);
this.setSetting = this.setSetting.bind(this);
}
async getUser(req, res) {
@@ -118,6 +130,7 @@ class FalukantController {
}
async createStock(req, res) {
console.log('build stock');
try {
const { userid: hashedUserId } = req.headers;
const { branchId, stockTypeId, stockSize } = req.body;
@@ -159,6 +172,146 @@ class FalukantController {
res.status(500).json({ error: error.message });
}
}
async sellAllProducts(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { branchId } = req.body;
const result = await FalukantService.sellAllProducts(hashedUserId, branchId);
res.status(201).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
async moneyHistory(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { page, filter } = req.body;
if (!page) {
page = 1;
}
const result = await FalukantService.moneyHistory(hashedUserId, page, filter);
res.status(201).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
async getStorage(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { branchId } = req.params;
const result = await FalukantService.getStorage(hashedUserId, branchId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message});
console.log(error);
}
}
async buyStorage(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { branchId, amount, stockTypeId } = req.body;
const result = await FalukantService.buyStorage(hashedUserId, branchId, amount, stockTypeId);
res.status(201).json(result);
} catch (error) {
res.status(500).json({ error: error.message});
console.log(error);
}
}
async sellStorage(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { branchId, amount, stockTypeId } = req.body;
const result = await FalukantService.sellStorage(hashedUserId, branchId, amount, stockTypeId);
res.status(202).json(result);
} catch (error) {
res.status(500).json({ error: error.message});
console.log(error);
}
}
async getStockTypes(req, res) {
console.log('load stock');
try {
const result = await FalukantService.getStockTypes();
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
console.log(error);
}
}
async getStockOverview(req, res) {
try {
const result = await FalukantService.getStockOverview();
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
async getAllProductions(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const result = await FalukantService.getAllProductions(hashedUserId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
async getDirectorProposals(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { branchId } = req.body;
const result = await FalukantService.getDirectorProposals(hashedUserId, branchId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
async convertProposalToDirector(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { proposalId } = req.body;
const result = await FalukantService.convertProposalToDirector(hashedUserId, proposalId);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
async getDirectorForBranch(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { branchId } = req.params;
const result = await FalukantService.getDirectorForBranch(hashedUserId, branchId);
if (!result) {
return res.status(404).json({ message: 'No director found for this branch' });
}
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
async setSetting(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { branchId, directorId, settingKey, value } = req.body;
const result = await FalukantService.setSetting(hashedUserId, branchId, directorId, settingKey, value);
res.status(200).json(result);
} catch (error) {
res.status(500).json({ error: error.message });
console.log(error);
}
}
}
export default FalukantController;