fix(incidents): persist assignee correctly via assigned_users
- map form field `assigned_to` to backend field `assigned_users` - ensure assignee is stored when creating or updating incidents - keep `assigned_to` for backward compatibility
This commit is contained in:
@@ -22,7 +22,7 @@ export const updateIncidentStatus = async (id: string, status: string): Promise<
|
|||||||
|
|
||||||
console.log(`Incident ${id} status updated successfully to ${status}`);
|
console.log(`Incident ${id} status updated successfully to ${status}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating incident status:', error);
|
console.error('Error updating incident status:', error);ok gib mir die
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -56,7 +56,9 @@ export const createIncident = async (data: CreateIncidentInput): Promise<void> =
|
|||||||
affected_systems: data.affected_systems,
|
affected_systems: data.affected_systems,
|
||||||
priority: data.priority.toLowerCase(),
|
priority: data.priority.toLowerCase(),
|
||||||
service_id: data.service_id || '',
|
service_id: data.service_id || '',
|
||||||
assigned_to: data.assigned_to || '', // Direct user ID assignment
|
//assigned_to: data.assigned_to || '', // Direct user ID assignment
|
||||||
|
//2025-08-18: // map UI field -> server schema
|
||||||
|
assigned_users: typeof data.assigned_to === 'string' ? data.assigned_to : '',
|
||||||
root_cause: data.root_cause || '',
|
root_cause: data.root_cause || '',
|
||||||
resolution_steps: data.resolution_steps || '',
|
resolution_steps: data.resolution_steps || '',
|
||||||
lessons_learned: data.lessons_learned || '',
|
lessons_learned: data.lessons_learned || '',
|
||||||
@@ -82,28 +84,41 @@ export const createIncident = async (data: CreateIncidentInput): Promise<void> =
|
|||||||
export const updateIncident = async (id: string, data: Partial<IncidentItem>): Promise<void> => {
|
export const updateIncident = async (id: string, data: Partial<IncidentItem>): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
console.log(`Updating incident ${id} with:`, data);
|
console.log(`Updating incident ${id} with:`, data);
|
||||||
|
|
||||||
// Make sure impact and priority are lowercase
|
const payload: Record<string, any> = {
|
||||||
const payload = {
|
|
||||||
...data,
|
...data,
|
||||||
impact: data.impact?.toLowerCase(),
|
...(data.impact ? { impact: data.impact.toLowerCase() } : {}),
|
||||||
priority: data.priority?.toLowerCase(),
|
...(data.priority ? { priority: data.priority.toLowerCase() } : {}),
|
||||||
status: data.status ? formatStatus(data.status) : undefined,
|
...(data.status
|
||||||
impact_status: data.status ? data.status.toLowerCase() : undefined,
|
? {
|
||||||
...(data.status?.toLowerCase() === 'resolved' && !data.resolution_time
|
status: formatStatus(data.status),
|
||||||
? { resolution_time: new Date().toISOString() }
|
impact_status: data.status.toLowerCase(),
|
||||||
: {})
|
}
|
||||||
|
: {}),
|
||||||
|
// set only if assigned_to was provided
|
||||||
|
...(typeof data.assigned_to === 'string'
|
||||||
|
? {
|
||||||
|
assigned_users: data.assigned_to, // server field
|
||||||
|
assigned_to: data.assigned_to, // legacy field for backward compatibility
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
// add resolution_time only if status changes to resolved
|
||||||
|
...((data.status?.toLowerCase() === 'resolved' && !data.resolution_time)
|
||||||
|
? { resolution_time: new Date().toISOString() }
|
||||||
|
: {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("Final payload for update:", payload);
|
console.log("Final payload for update:", payload);
|
||||||
await pb.collection('incidents').update(id, payload);
|
await pb.collection('incidents').update(id, payload);
|
||||||
|
|
||||||
// Invalidate cache after update
|
// Invalidate cache after update
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
|
|
||||||
console.log(`Incident ${id} updated successfully`);
|
console.log(`Incident ${id} updated successfully`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating incident:', error);
|
console.error('Error updating incident:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user