Skip to content

Commit

Permalink
Fixed passenger updateability
Browse files Browse the repository at this point in the history
  • Loading branch information
zszul committed Nov 3, 2024
1 parent d42332d commit 48af0ec
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/controllers/Passenger.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,34 +297,39 @@ export const updatePassenger = async (req: Request, res: Response) => {
'Household Income': Joi.number().optional(),
'Household Size': Joi.number().optional(),
'Marital Status': Joi.string().optional(),
Employment: Joi.string().optional,
Employment: Joi.string().optional(),
'Military Service': Joi.string().optional(),
'Military Member': Joi.array().optional(),
Gender: Joi.string().optional(),
'Date of Birth': Joi.string().optional(),
});

if (schema.validate(passengerData).error) {
return res.status(400).send({ error: 'Invalid passenger data' });
const { error } = schema.validate(passengerData.records[0].fields);

if (error) {
console.error('Validation error:', JSON.stringify(error, null, 2));
return res
.status(400)
.send({ error: 'Invalid passenger data', details: error.details });
}

const base = new Airtable({
apiKey: process.env.AIRTABLE_API_KEY || '',
}).base('appwPsfAb6U8CV3mf');

try {
// make a call to AirTable to update the passenger
await base('Passengers').update(
[{ id, fields: passengerData }],
passengerData.records,
async (err, records) => {
if (err) {
logger.error(err);
return;
console.error('Airtable update error:', err);
return res.status(500).json({ error: 'Error updating passenger data' });
}
res.status(200).send(records);
}
);
} catch (err: any) {
// if that fails return a 500
logger.error(err);
return res.status(500).json({ error: 'Error updating' });
console.error('Unexpected error:', err);
return res.status(500).json({ error: 'Unexpected error while updating' });
}
};

0 comments on commit 48af0ec

Please sign in to comment.