fix permissions
This commit is contained in:
@@ -361,6 +361,96 @@ async function getAssignableMembers() {
|
||||
}
|
||||
}
|
||||
|
||||
async function getIssueCounts() {
|
||||
try {
|
||||
const result = await pool.query(
|
||||
`SELECT status, COUNT(*)::int AS count FROM issues GROUP BY status`
|
||||
);
|
||||
const counts: Record<string, number> = { offen: 0, in_bearbeitung: 0, erledigt: 0, abgelehnt: 0 };
|
||||
for (const row of result.rows) {
|
||||
counts[row.status] = row.count;
|
||||
}
|
||||
return counts;
|
||||
} catch (error) {
|
||||
logger.error('IssueService.getIssueCounts failed', { error });
|
||||
throw new Error('Issue-Counts konnten nicht geladen werden');
|
||||
}
|
||||
}
|
||||
|
||||
async function getStatusmeldungen() {
|
||||
try {
|
||||
const result = await pool.query(
|
||||
`SELECT * FROM issue_statusmeldungen WHERE aktiv = true ORDER BY created_at DESC`
|
||||
);
|
||||
return result.rows;
|
||||
} catch (error) {
|
||||
logger.error('IssueService.getStatusmeldungen failed', { error });
|
||||
throw new Error('Statusmeldungen konnten nicht geladen werden');
|
||||
}
|
||||
}
|
||||
|
||||
async function createStatusmeldung(
|
||||
data: { titel: string; inhalt?: string; schwere?: string },
|
||||
userId: string
|
||||
) {
|
||||
try {
|
||||
const result = await pool.query(
|
||||
`INSERT INTO issue_statusmeldungen (titel, inhalt, schwere, erstellt_von)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING *`,
|
||||
[data.titel, data.inhalt ?? null, data.schwere ?? 'info', userId]
|
||||
);
|
||||
return result.rows[0];
|
||||
} catch (error) {
|
||||
logger.error('IssueService.createStatusmeldung failed', { error });
|
||||
throw new Error('Statusmeldung konnte nicht erstellt werden');
|
||||
}
|
||||
}
|
||||
|
||||
async function updateStatusmeldung(
|
||||
id: number,
|
||||
data: { titel?: string; inhalt?: string; schwere?: string; aktiv?: boolean }
|
||||
) {
|
||||
try {
|
||||
const setClauses: string[] = [];
|
||||
const values: any[] = [];
|
||||
let idx = 1;
|
||||
|
||||
if (data.titel !== undefined) { setClauses.push(`titel = $${idx}`); values.push(data.titel); idx++; }
|
||||
if ('inhalt' in data) { setClauses.push(`inhalt = $${idx}`); values.push(data.inhalt ?? null); idx++; }
|
||||
if (data.schwere !== undefined) { setClauses.push(`schwere = $${idx}`); values.push(data.schwere); idx++; }
|
||||
if (data.aktiv !== undefined) { setClauses.push(`aktiv = $${idx}`); values.push(data.aktiv); idx++; }
|
||||
|
||||
if (setClauses.length === 0) {
|
||||
const r = await pool.query(`SELECT * FROM issue_statusmeldungen WHERE id = $1`, [id]);
|
||||
return r.rows[0] || null;
|
||||
}
|
||||
|
||||
values.push(id);
|
||||
const result = await pool.query(
|
||||
`UPDATE issue_statusmeldungen SET ${setClauses.join(', ')} WHERE id = $${idx} RETURNING *`,
|
||||
values
|
||||
);
|
||||
return result.rows[0] || null;
|
||||
} catch (error) {
|
||||
logger.error('IssueService.updateStatusmeldung failed', { error, id });
|
||||
throw new Error('Statusmeldung konnte nicht aktualisiert werden');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteStatusmeldung(id: number) {
|
||||
try {
|
||||
const result = await pool.query(
|
||||
`DELETE FROM issue_statusmeldungen WHERE id = $1 RETURNING id`,
|
||||
[id]
|
||||
);
|
||||
return result.rows.length > 0;
|
||||
} catch (error) {
|
||||
logger.error('IssueService.deleteStatusmeldung failed', { error, id });
|
||||
throw new Error('Statusmeldung konnte nicht gelöscht werden');
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
getIssues,
|
||||
getIssueById,
|
||||
@@ -374,5 +464,10 @@ export default {
|
||||
updateType,
|
||||
deactivateType,
|
||||
getAssignableMembers,
|
||||
getIssueCounts,
|
||||
getStatusmeldungen,
|
||||
createStatusmeldung,
|
||||
updateStatusmeldung,
|
||||
deleteStatusmeldung,
|
||||
UNASSIGN,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user