Refactor Dewar service methods and improve field handling

Updated Dewar API methods to use protected endpoints for enhanced security and consistency. Added `pgroups` handling in various frontend components and modified the LogisticsView contact field for clarity. Simplified backend router imports for better readability.
This commit is contained in:
GotthardG
2025-01-30 13:39:49 +01:00
parent 44582cf38e
commit c2215860bf
20 changed files with 304 additions and 262 deletions

View File

@ -31,6 +31,7 @@ const SpreadsheetTable = ({
fileBlob,
selectedShipment,
addinfo,
activePgroup,
}) => {
const [localErrors, setLocalErrors] = useState(errors || []);
const [editingCell, setEditingCell] = useState({});
@ -59,17 +60,14 @@ const SpreadsheetTable = ({
console.log("Addinfo:", addinfo);
}, [correctionMetadata, addinfo]);
const initialNewDewarState = {
pgroups: activePgroup,
number_of_pucks: 0,
number_of_samples: 0,
ready_date: null,
shipping_date: null,
arrival_date: null,
returning_date: null,
contact_id: selectedShipment?.contact?.id,
return_address_id: selectedShipment?.return_address?.id,
dewar_name: '',
tracking_number: 'UNKNOWN',
status: 'In preparation',
status: 'active',
pucks: [] // Ensure 'pucks' array exists
};
@ -242,7 +240,7 @@ const SpreadsheetTable = ({
try {
// Fetch dewars related to the current shipment via API
const shipDewars = await ShipmentsService.getDewarsByShipmentIdShipmentsShipmentIdDewarsGet(selectedShipment.id);
const shipDewars = await ShipmentsService.getDewarsByShipmentIdProtectedShipmentsShipmentIdDewarsGet(selectedShipment.id);
// Search for dewar by name within the shipment
const existingDewar = shipDewars.find((d) => d.dewar_name === dewarName);
@ -258,8 +256,8 @@ const SpreadsheetTable = ({
}
};
const createOrUpdateDewarsFromSheet = async (data, contactPerson, returnAddress) => {
if (!contact?.id || !returnAddress?.id) {
const createOrUpdateDewarsFromSheet = async (data, contact, address) => {
if (!contact?.id || !address?.id) {
console.error('contact_id or return_address_id is missing');
return null;
}
@ -287,9 +285,10 @@ const SpreadsheetTable = ({
// Initialize new dewar object
dewar = {
...initialNewDewarState,
pgroups: activePgroup,
dewar_name: dewarName,
contact_id: contactPerson.id,
return_address_id: returnAddress.id,
contact_id: contact.id,
return_address_id: address.id,
pucks: [],
};
dewars.set(dewarName, dewar);
@ -442,7 +441,7 @@ const SpreadsheetTable = ({
const { number_of_pucks, number_of_samples, ...payload } = dewar;
// Attempt to create or update a dewar
await DewarsService.createOrUpdateDewarDewarsPost(selectedShipment.id, payload);
await DewarsService.createOrUpdateDewarProtectedDewarsPost(selectedShipment.id, payload);
console.log(`Dewar "${dewar.dewar_name}" created/updated successfully.`);
} catch (error: any) {