Skip to content

Commit

Permalink
Adds /students path (minor)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Dec 21, 2019
1 parent 03efc7e commit 280cfa8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ Get number of logs in queue

Get stats for number of kopiPrPost yff-bekreftelse-bedrift

### ```GET /stats/students```

Get the total number of students (from tjommi)

## Development

Add a local .env file

```
MONGODB_CONNECTION=mongodb-connection-string
MONGODB_COLLECTION=mongodb-collection-name
MONGODB_COLLECTION_TJOMMI=mongodb-collection-name-tjommi
MONGODB_NAME=mongodb-db-name
```

Expand All @@ -102,7 +107,7 @@ $ npm run deploy
## Related

- [minelev-web](https://github.com/telemark/minelev-web) web frontend for MinElev
- [minelev-buddy](https://github.com/telemark/minelev-buddy) buddy service for MinElev
- [minelev-tjommi-api](https://github.com/telemark/minelev-tjommi-api) tjommi service for MinElev
- [minelev-notifications](https://github.com/telemark/minelev-notifications) notifications service for MinElev
- [minelev-leder](https://github.com/telemark/minelev-leder) web frontend for MinElev - school administration
- [minelev-logs](https://github.com/telemark/minelev-logs) logs service for MinElev
Expand Down
17 changes: 17 additions & 0 deletions api/students-total.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongo = require('../lib/mongo')
const logger = require('../lib/logger')

module.exports = async (request, response) => {
const db = await mongo()
const tjommi = db.collection(process.env.MONGODB_COLLECTION_TJOMMI)
logger('info', ['handle-stats', 'action', 'students'])
try {
const count = await tjommi.countDocuments({ type: 'student' })
logger('info', ['handle-stats', 'action', 'students', 'success', 'found', count])
response.json({ total: count })
} catch (error) {
logger('error', ['handle-stats', 'action', 'students', error])
response.status(500)
response.send(error)
}
}
1 change: 1 addition & 0 deletions now-demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"NODE_ENV": "production",
"MONGODB_CONNECTION": "@db-cosmos-dev-connection-read",
"MONGODB_COLLECTION": "logs",
"MONGODB_COLLECTION_TJOMMI": "tjommi",
"MONGODB_NAME": "minelev"
},
"builds": [
Expand Down
9 changes: 9 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"NODE_ENV": "production",
"MONGODB_CONNECTION": "@db-cosmos-prod-connection-read",
"MONGODB_COLLECTION": "@db-cosmos-prod-collection-logs-name",
"MONGODB_COLLECTION_TJOMMI": "@db-cosmos-prod-collection-tjommi-name",
"MONGODB_NAME": "@db-cosmos-prod-db-name"
},
"builds": [
Expand Down Expand Up @@ -158,6 +159,14 @@
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept"
}
},
{
"src": "/stats/students",
"dest": "/api/students-total.js",
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept"
}
},
{
"src": "/stats/(.*)",
"dest": "/README.html"
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 280cfa8

Please sign in to comment.