Skip to content

Commit

Permalink
Minor fix to vehicle page
Browse files Browse the repository at this point in the history
  • Loading branch information
Delaney H committed Apr 14, 2024
1 parent 25f5612 commit a82e3ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
26 changes: 11 additions & 15 deletions backend-lambda/updateMaintenanceHistory/index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MongoClient, ServerApiVersion } from "mongodb";
import {MongoClient, ServerApiVersion} from "mongodb";
import 'dotenv/config';
import jwt from 'jsonwebtoken';

Expand All @@ -13,9 +13,11 @@ export const handler = async (event, context) => {
}
}
);
console.log(event);
const authorization = event.headers['Authorization'];
const config_id = event['queryStringParameters'].config_id;
const data = JSON.parse(event.body);
console.log(data);
const values = {
old_type: data.old_type,
old_date: data.old_date,
Expand All @@ -41,7 +43,8 @@ export const handler = async (event, context) => {

const database = client.db("vehicleDB");
const garage = database.collection("user_vehicle_info");
const update = await garage.updateOne(
console.log("EMAIL " + decoded.email + " CONFIG_ID " + config_id + " MAINTENANCE " + values);
return await garage.updateOne(
{
email: decoded.email,
config_id: parseInt(config_id),
Expand All @@ -58,19 +61,12 @@ export const handler = async (event, context) => {
"completed_maintenance.$.cost": parseInt(values.new_cost)
}
});
if (update.modifiedCount === 1) {
return {
statusCode: 200,
body: JSON.stringify({message: `Maintenance history updated for vehicle with config ${config_id}`})
};
}
else {
return {
statusCode: 400,
body: JSON.stringify({message: `Maintenance history not updated for vehicle with config ${config_id}`})
};
}

}).then(res => {
console.log(res);
return {
statusCode: 200,
body: JSON.stringify({message: res})
};
}).catch(err => {
return {
statusCode: 500,
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/pages/vehicle/VehicleHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ function UpdateMaintenanceHistory(props) {
redirect: 'follow'
};

fetch("/api/update-maintenance-history?configId="+props.configId, reqOptions)
.then((res) =>
res.json())
fetch("/api/update-maintenance-history?config_id="+props.configId, reqOptions)
.then((res) => res.text())
.then((result) => {
console.log(result);
setRefreshData(!refreshData);
Expand Down

0 comments on commit a82e3ce

Please sign in to comment.