more club funtions, fix for team edit
This commit is contained in:
93
backend/controllers/clubInvoiceController.js
Normal file
93
backend/controllers/clubInvoiceController.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import clubInvoiceService from '../services/clubInvoiceService.js';
|
||||
|
||||
class ClubInvoiceController {
|
||||
async listClubInvoices(req, res) {
|
||||
try {
|
||||
const { clubId } = req.params;
|
||||
const payload = await clubInvoiceService.listClubInvoices(Number(clubId));
|
||||
res.json(payload);
|
||||
} catch (error) {
|
||||
console.error('[listClubInvoices] - Error:', error);
|
||||
res.status(error?.status || 500).json({ error: error?.message || 'Rechnungen konnten nicht geladen werden.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createInvoiceParty(req, res) {
|
||||
try {
|
||||
const { clubId } = req.params;
|
||||
const party = await clubInvoiceService.createInvoiceParty(Number(clubId), req.body || {});
|
||||
res.status(201).json({ party });
|
||||
} catch (error) {
|
||||
console.error('[createInvoiceParty] - Error:', error);
|
||||
res.status(error?.status || 500).json({ error: error?.message || 'Rechnungspartei konnte nicht gespeichert werden.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateInvoiceParty(req, res) {
|
||||
try {
|
||||
const { clubId, partyId } = req.params;
|
||||
const party = await clubInvoiceService.updateInvoiceParty(Number(clubId), Number(partyId), req.body || {});
|
||||
res.json({ party });
|
||||
} catch (error) {
|
||||
console.error('[updateInvoiceParty] - Error:', error);
|
||||
res.status(error?.status || 500).json({ error: error?.message || 'Rechnungspartei konnte nicht gespeichert werden.' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteInvoiceParty(req, res) {
|
||||
try {
|
||||
const { clubId, partyId } = req.params;
|
||||
await clubInvoiceService.deleteInvoiceParty(Number(clubId), Number(partyId));
|
||||
res.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('[deleteInvoiceParty] - Error:', error);
|
||||
res.status(error?.status || 500).json({ error: error?.message || 'Rechnungspartei konnte nicht gelöscht werden.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createInvoice(req, res) {
|
||||
try {
|
||||
const { clubId } = req.params;
|
||||
const invoice = await clubInvoiceService.createInvoice(Number(clubId), req.user?.id || null, req.body || {});
|
||||
res.status(201).json({ invoice });
|
||||
} catch (error) {
|
||||
console.error('[createInvoice] - Error:', error);
|
||||
res.status(error?.status || 500).json({ error: error?.message || 'Rechnung konnte nicht gespeichert werden.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateInvoice(req, res) {
|
||||
try {
|
||||
const { clubId, invoiceId } = req.params;
|
||||
const invoice = await clubInvoiceService.updateInvoice(Number(clubId), Number(invoiceId), req.body || {});
|
||||
res.json({ invoice });
|
||||
} catch (error) {
|
||||
console.error('[updateInvoice] - Error:', error);
|
||||
res.status(error?.status || 500).json({ error: error?.message || 'Rechnung konnte nicht gespeichert werden.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateInvoiceStatus(req, res) {
|
||||
try {
|
||||
const { clubId, invoiceId } = req.params;
|
||||
const invoice = await clubInvoiceService.updateInvoiceStatus(Number(clubId), Number(invoiceId), String(req.body?.status || ''));
|
||||
res.json({ invoice });
|
||||
} catch (error) {
|
||||
console.error('[updateInvoiceStatus] - Error:', error);
|
||||
res.status(error?.status || 500).json({ error: error?.message || 'Rechnungsstatus konnte nicht gespeichert werden.' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteInvoice(req, res) {
|
||||
try {
|
||||
const { clubId, invoiceId } = req.params;
|
||||
await clubInvoiceService.deleteInvoice(Number(clubId), Number(invoiceId));
|
||||
res.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('[deleteInvoice] - Error:', error);
|
||||
res.status(error?.status || 500).json({ error: error?.message || 'Rechnung konnte nicht gelöscht werden.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new ClubInvoiceController();
|
||||
@@ -67,7 +67,11 @@ export const updateClubSettings = async (req, res) => {
|
||||
autoFetchRankings,
|
||||
countryCode,
|
||||
stateCode,
|
||||
memberDataQualityRequirements
|
||||
memberDataQualityRequirements,
|
||||
outgoingInvoicePrefix,
|
||||
outgoingInvoiceNextNumber,
|
||||
incomingInvoicePrefix,
|
||||
incomingInvoiceNextNumber
|
||||
} = req.body;
|
||||
const updated = await ClubService.updateClubSettings(token, clubid, {
|
||||
greetingText,
|
||||
@@ -76,7 +80,11 @@ export const updateClubSettings = async (req, res) => {
|
||||
autoFetchRankings,
|
||||
countryCode,
|
||||
stateCode,
|
||||
memberDataQualityRequirements
|
||||
memberDataQualityRequirements,
|
||||
outgoingInvoicePrefix,
|
||||
outgoingInvoiceNextNumber,
|
||||
incomingInvoicePrefix,
|
||||
incomingInvoiceNextNumber
|
||||
});
|
||||
res.status(200).json(updated);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user