Skip to content

Commit

Permalink
Merge pull request #11 from Winguweb/add_extra_information
Browse files Browse the repository at this point in the history
send device name
  • Loading branch information
ximena-bogado authored Feb 27, 2024
2 parents 934ab21 + 602bb3e commit 72c1fe7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pages/api/external-samples/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const handler: NextApiHandler = async (req, res) => {

const sample = await createSample(device.id, device.samplingPointId, device.ownerId, body.latitude, body.longitude, body.measurementValues, body.takenAt);
if (sample) {
await onSampleUpload({ ...sample });
await onSampleUpload({ ...sample, name: device.name });
res.status(201).json(sample);
} else {
res.status(500).json({ error: 'Internal server error' });
Expand Down
9 changes: 4 additions & 5 deletions server/notifier/appNotifierService.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import axios from 'axios';
import { DeviceCoordinates } from './deviceCoordinates';

const http = axios.create({
baseURL: process.env.NOTIFIER_URL,
});

export async function onSampleUpload(coordinates: DeviceCoordinates) {
export async function onSampleUpload(sample: any) {
try {
const token = await authenticate();
const headers = { 'Authorization': 'Bearer ' + token };
const res = await http.post(
'/onUpdate',
coordinates,
sample,
{ headers: headers },
);
return res.data;
} catch (err: any) {
console.error('[NotifierService] error:', err.response.data.error);
console.error('[NotifierService] error:', err);
}
}

Expand All @@ -26,6 +25,6 @@ async function authenticate() {
const res = await http.post('/auth', body);
return res.data.token;
} catch (err: any) {
console.error('[NotifierService][Auth] error:', err.response.data.error);
console.error('[NotifierService][Auth] error:', err);
}
}

0 comments on commit 72c1fe7

Please sign in to comment.