import FalukantService from '../services/falukantService.js'; class FalukantController { constructor() { this.getUser = this.getUser.bind(this); this.createUser = this.createUser.bind(this); this.randomFirstName = this.randomFirstName.bind(this); this.randomLastName = this.randomLastName.bind(this); 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.getAllDirectors = this.getAllDirectors.bind(this); this.setSetting = this.setSetting.bind(this); this.getFamily = this.getFamily.bind(this); this.acceptMarriageProposal = this.acceptMarriageProposal.bind(this); this.getGifts = this.getGifts.bind(this); this.sendGift = this.sendGift.bind(this); this.getHouseTypes = this.getHouseTypes.bind(this); this.getTitelsOfNobility = this.getTitelsOfNobility.bind(this); this.getMoodAffect = this.getMoodAffect.bind(this); this.getCharacterAffect = this.getCharacterAffect.bind(this); this.getUserHouse = this.getUserHouse.bind(this); this.getBuyableHouses = this.getBuyableHouses.bind(this); this.buyUserHouse = this.buyUserHouse.bind(this); this.getPartyTypes = this.getPartyTypes.bind(this); this.createParty = this.createParty.bind(this); this.getParties = this.getParties.bind(this); this.getNotBaptisedChildren = this.getNotBaptisedChildren.bind(this); this.baptise = this.baptise.bind(this); this.getEducation = this.getEducation.bind(this); this.getChildren = this.getChildren.bind(this); this.sendToSchool = this.sendToSchool.bind(this); this.getBankOverview = this.getBankOverview.bind(this); this.getBankCredits = this.getBankCredits.bind(this); this.takeBankCredits = this.takeBankCredits.bind(this); this.getNobility = this.getNobility.bind(this); this.advanceNobility = this.advanceNobility.bind(this); this.getHealth = this.getHealth.bind(this); this.healthActivity = this.healthActivity.bind(this); this.getPoliticsOverview = this.getPoliticsOverview.bind(this); this.getOpenPolitics = this.getOpenPolitics.bind(this); this.getElections = this.getElections.bind(this); this.vote = this.vote.bind(this); this.getOpenPolitics = this.getOpenPolitics.bind(this); this.applyForElections = this.applyForElections.bind(this); this.getRegions = this.getRegions.bind(this); this.renovate = this.renovate.bind(this); this.renovateAll = this.renovateAll.bind(this); this.createBranch = this.createBranch.bind(this); } async getUser(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getUser(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async createUser(req, res) { try { const { userid: hashedUserId } = req.headers; const { gender, firstname: firstName, lastname: lastName } = req.body; console.log(req.body); const result = await FalukantService.createUser(hashedUserId, gender, firstName, lastName); res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async randomFirstName(req, res) { try { const { gender } = req.params; const result = await FalukantService.randomFirstName(gender); res.status(200).json({ name: result }); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async randomLastName(req, res) { try { const result = await FalukantService.randomLastName(); res.status(200).json({ name: result }); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getInfo(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getInfo(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getBranches(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getBranches(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async createBranch(req, res) { try { const { userid: hashedUserId } = req.headers; const { cityId, branchTypeId } = req.body; const result = await FalukantService.createBranch(hashedUserId, cityId, branchTypeId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getBranchTypes(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getBranchTypes(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getBranch(req, res) { try { const { userid: hashedUserId } = req.headers; const { branch: branchId } = req.params; console.log(branchId, req.params); const result = await FalukantService.getBranch(hashedUserId, branchId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async createProduction(req, res) { try { const { userid: hashedUserId } = req.headers; const { branchId, productId, quantity } = req.body; const result = await FalukantService.createProduction(hashedUserId, branchId, productId, quantity); res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getProduction(req, res) { try { const { userid: hashedUserId } = req.headers; const { branchId } = req.params; const result = await FalukantService.getProduction(hashedUserId, branchId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getStock(req, res) { try { const { userid: hashedUserId } = req.headers; const { branchId } = req.params || null; const result = await FalukantService.getStock(hashedUserId, branchId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async createStock(req, res) { console.log('build stock'); try { const { userid: hashedUserId } = req.headers; const { branchId, stockTypeId, stockSize } = req.body; const result = await FalukantService.createStock(hashedUserId, branchId, stockTypeId, stockSize); res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getProducts(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getProducts(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getInventory(req, res) { try { const { userid: hashedUserId } = req.headers; const { branchId } = req.params; const result = await FalukantService.getInventory(hashedUserId, branchId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async sellProduct(req, res) { try { const { userid: hashedUserId } = req.headers; const { branchId, productId, quality, quantity } = req.body; const result = await FalukantService.sellProduct(hashedUserId, branchId, productId, quality, quantity); res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } 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 }); console.log(error); } } 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 }); console.log(error); } } 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) { console.log(error.message, error.stack); 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); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); } } async getAllDirectors(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getAllDirectors(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); } } async updateDirector(req, res) { try { const { userid: hashedUserId } = req.headers; const { directorId, income } = req.body; const result = await FalukantService.updateDirector(hashedUserId, directorId, income); 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); } } async getFamily(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getFamily(hashedUserId); if (!result) { res.status(404).json({ error: 'No family data found' }); } res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async acceptMarriageProposal(req, res) { try { const { userid: hashedUserId } = req.headers; const { proposalId } = req.body; const result = await FalukantService.acceptMarriageProposal(hashedUserId, proposalId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getGifts(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getGifts(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getChildren(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getChildren(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async sendGift(req, res) { try { const { userid: hashedUserId } = req.headers; const { giftId } = req.body; const result = await FalukantService.sendGift(hashedUserId, giftId); res.status(200).json(result); } catch (error) { const status = error.status === 412 ? 412 : 500; res.status(status).json({ error: error.message }); console.error(error); } } async getTitelsOfNobility(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getTitlesOfNobility(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getHouseTypes(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getHouseTypes(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getMoodAffect(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getMoodAffect(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getCharacterAffect(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getCharacterAffect(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getUserHouse(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getUserHouse(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getBuyableHouses(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getBuyableHouses(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async buyUserHouse(req, res) { try { const { userid: hashedUserId } = req.headers; const { houseId } = req.body; const result = await FalukantService.buyUserHouse(hashedUserId, houseId); res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getPartyTypes(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getPartyTypes(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async createParty(req, res) { try { const { userid: hashedUserId } = req.headers; const { partyTypeId, musicId, banquetteId, nobilityIds, servantRatio } = req.body; const result = await FalukantService.createParty(hashedUserId, partyTypeId, musicId, banquetteId, nobilityIds, servantRatio); res.status(201).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getParties(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getParties(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getNotBaptisedChildren(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getNotBaptisedChildren(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async baptise(req, res) { try { const { userid: hashedUserId } = req.headers; const { characterId: childId, firstName } = req.body; const result = await FalukantService.baptise(hashedUserId, childId, firstName); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getEducation(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getEducation(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async sendToSchool(req, res) { try { const { userid: hashedUserId } = req.headers; const { item, student, studentId } = req.body; const result = await FalukantService.sendToSchool(hashedUserId, item, student, studentId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getBankOverview(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getBankOverview(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getBankCredits(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getBankCredits(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async takeBankCredits(req, res) { try { const { userid: hashedUserId } = req.headers; const { height } = req.body; const result = await FalukantService.takeBankCredits(hashedUserId, height); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getNobility(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getNobility(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async advanceNobility(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.advanceNobility(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getHealth(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getHealth(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async healthActivity(req, res) { try { const { userid: hashedUserId } = req.headers; const { measureTr: activity } = req.body; const result = await FalukantService.healthActivity(hashedUserId, activity); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getPoliticsOverview(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getPoliticsOverview(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getOpenPolitics(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getOpenPolitics(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getElections(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getElections(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async vote(req, res) { try { const { userid: hashedUserId } = req.headers; const { votes } = req.body; const result = await FalukantService.vote(hashedUserId, votes); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getOpenPolitics(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getOpenPolitics(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async applyForElections(req, res) { try { const { userid: hashedUserId } = req.headers; const { electionIds } = req.body; const result = await FalukantService.applyForElections(hashedUserId, electionIds); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async getRegions(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.getRegions(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async renovate(req, res) { try { const { userid: hashedUserId } = req.headers; const { element } = req.body; const result = await FalukantService.renovate(hashedUserId, element); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } async renovateAll(req, res) { try { const { userid: hashedUserId } = req.headers; const result = await FalukantService.renovateAll(hashedUserId); res.status(200).json(result); } catch (error) { res.status(500).json({ error: error.message }); console.log(error); } } } export default FalukantController;