Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed passenger updateability #19

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' });
}
};
Loading