-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from bos-sci/feature/ads-794
feature/ads-794 Present carbon data
- Loading branch information
Showing
13 changed files
with
1,848 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { MongoClient } from 'mongodb'; | ||
import { CarbonRecord } from '../../src/shared/types/docs'; | ||
|
||
// eslint-disable-next-line import/no-anonymous-default-export | ||
export default async () => { | ||
const uri = process.env.MONGO_CONNECTION as string; | ||
const client = new MongoClient(uri); | ||
try { | ||
const database = client.db('carbon-metrics'); | ||
const carbon = database.collection<CarbonRecord>('metrics'); | ||
const cursor = carbon.find().sort({ date: 1 }); | ||
const allData = await cursor.toArray(); | ||
return Response.json(allData); | ||
} catch (error) { | ||
return Response.json(error); | ||
} finally { | ||
client.close(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { MongoClient } from 'mongodb'; | ||
import { CarbonRecord } from '../../src/shared/types/docs'; | ||
import { URL } from 'url'; | ||
|
||
// eslint-disable-next-line import/no-anonymous-default-export | ||
export default async (req: Request) => { | ||
const params = {}; | ||
new URL(req.url).searchParams.forEach((value, key) => (params[key] = value)); | ||
console.log(params); | ||
const uri = process.env.MONGO_CONNECTION as string; | ||
const client = new MongoClient(uri); | ||
try { | ||
const database = client.db('carbon-metrics'); | ||
const carbon = database.collection<CarbonRecord>('metrics'); | ||
const cursor = carbon.find(params).sort({ date: 1 }); | ||
const allData = await cursor.toArray(); | ||
return Response.json(allData); | ||
} catch (error) { | ||
return Response.json(error); | ||
} finally { | ||
client.close(); | ||
} | ||
}; |
Oops, something went wrong.