Skip to content

Commit

Permalink
400 code for duplicate upload
Browse files Browse the repository at this point in the history
  • Loading branch information
solderq35 committed May 7, 2024
1 parent 16df611 commit 2c502ba
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion backend/app/meter.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,18 @@ exports.upload = async (event, context) => {
if (meter_type === 'solar') {
query_string = `INSERT INTO Solar_Meters (\`time\`, \`time_seconds\`, \`energy_change\`, \`MeterID\`, \`MeterName\`) VALUES ('${meter_data.time}', '${meter_data.time_seconds}', '${meter_data.totalYieldYesterday}', '${meter_data.meterID}', '${meter_data.meterName}');`
} else if (meter_type === 'pacific_power') {
query_string = `INSERT INTO pacific_power_data (\`time\`, \`time_seconds\`, \`accumulated_real\`, \`pacific_power_meter_id\`) VALUES ('${meter_data.time}', '${meter_data.time_seconds}', '${meter_data.usage_kwh}', '${meter_data.pp_meter_id}');`
let final_redundant_check = await DB.query(
'SELECT * FROM pacific_power_data WHERE pacific_power_meter_id = ? AND time_seconds = ?',
[meter_data.pp_meter_id, meter_data.time_seconds]
)
console.log(final_redundant_check.length)
if (final_redundant_check.length === 0) {
query_string = `INSERT INTO pacific_power_data (\`time\`, \`time_seconds\`, \`accumulated_real\`, \`pacific_power_meter_id\`) VALUES ('${meter_data.time}', '${meter_data.time_seconds}', '${meter_data.usage_kwh}', '${meter_data.pp_meter_id}');`
} else {
response.statusCode = 400
response.body = 'redundant upload detected, skipping'
return response
}
}

try {
Expand Down

0 comments on commit 2c502ba

Please sign in to comment.