-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
529 additions
and
521 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
const publicDocTypes = require('../lib/public-doctypes') | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
const query = { documentCategory: { $in: publicDocTypes } } | ||
logs.aggregate([{ $match: query }, { $group: { _id: '$documentCategory', total: { $sum: 1 } } }]) | ||
.sort({ total: -1 }).toArray((error, data) => { | ||
if (error) { | ||
logger('error', ['handle-stats', 'action', 'categories', error]) | ||
response.status(500) | ||
response.send(error) | ||
} else { | ||
logger('info', ['handle-stats', 'action', 'categories', 'success']) | ||
response.json(data) | ||
} | ||
}) | ||
} |
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,29 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
|
||
function getParams (url) { | ||
const list = url.split('/') | ||
return { | ||
category: list[4] | ||
} | ||
} | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
const params = getParams(request.url) | ||
const { category } = params | ||
const query = { documentCategory: category } | ||
logger('info', ['routes', 'categoryClasses', 'category', category]) | ||
logs.aggregate([{ $match: query }, { $group: { _id: '$studentMainGroupName', total: { $sum: 1 } } }]) | ||
.sort({ total: -1 }).toArray((error, data) => { | ||
if (error) { | ||
logger('error', ['handle-stats', 'action', 'categoryClasses', error]) | ||
response.status(500) | ||
response.send(error) | ||
} else { | ||
logger('info', ['handle-stats', 'action', 'categoryClasses', 'success']) | ||
response.json(data) | ||
} | ||
}) | ||
} |
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,29 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
|
||
function getParams (url) { | ||
const list = url.split('/') | ||
return { | ||
category: list[4] | ||
} | ||
} | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
const params = getParams(request.url) | ||
const { category } = params | ||
const query = { documentCategory: category } | ||
logger('info', ['routes', 'categorySchools', 'category', category]) | ||
logs.aggregate([{ $match: query }, { $group: { _id: '$schoolName', total: { $sum: 1 } } }]) | ||
.sort({ total: -1 }).toArray((error, data) => { | ||
if (error) { | ||
logger('error', ['handle-stats', 'action', 'categorySchools', error]) | ||
response.status(500) | ||
response.send(error) | ||
} else { | ||
logger('info', ['handle-stats', 'action', 'categorySchools', 'success']) | ||
response.json(data) | ||
} | ||
}) | ||
} |
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,27 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
|
||
function getParams (url) { | ||
const list = url.split('/') | ||
return { | ||
category: list[4] | ||
} | ||
} | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
const params = getParams(request.url) | ||
const { category } = params | ||
const query = { documentCategory: category } | ||
logger('info', ['routes', 'categoryTotal', 'category', category]) | ||
try { | ||
const count = await logs.countDocuments(query) | ||
logger('info', ['routes', 'categoryTotal', 'success', count]) | ||
response.json({ total: count }) | ||
} catch (error) { | ||
logger('error', ['routes', 'categoryTotal', error]) | ||
response.status(500) | ||
response.send(error) | ||
} | ||
} |
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,22 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
logger('info', ['handle-stats', 'action', 'email']) | ||
const query = { | ||
documentType: 'yff', | ||
documentCategory: 'yff-bekreftelse-bedrift', | ||
kopiPrEpost: { $exists: true, $ne: '' } | ||
} | ||
try { | ||
const count = await logs.countDocuments(query) | ||
logger('info', ['handle-stats', 'action', 'email', 'success', 'found', count]) | ||
response.json({ total: count }) | ||
} catch (error) { | ||
logger('error', ['handle-stats', 'action', 'email', error]) | ||
response.status(500) | ||
response.send(error) | ||
} | ||
} |
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,30 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
const publicDocTypes = require('../lib/public-doctypes') | ||
|
||
function getParams (url) { | ||
const list = url.split('/') | ||
return { | ||
type: list[3] | ||
} | ||
} | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
const params = getParams(request.url) | ||
const { type } = params | ||
const query = type ? { documentType: type, documentCategory: { $in: publicDocTypes } } : { documentCategory: { $in: publicDocTypes } } | ||
logger('info', ['routes', 'groups', 'type', type || 'any']) | ||
logs.aggregate([{ $match: query }, { $group: { _id: '$studentMainGroupName', total: { $sum: 1 } } }]) | ||
.sort({ total: -1 }).toArray((error, data) => { | ||
if (error) { | ||
logger('error', ['handle-stats', 'action', 'groups', error]) | ||
response.status(500) | ||
response.send(error) | ||
} else { | ||
logger('info', ['handle-stats', 'action', 'groups', 'success']) | ||
response.json(data) | ||
} | ||
}) | ||
} |
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,17 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
logger('info', ['handle-stats', 'action', 'queue']) | ||
try { | ||
const count = await logs.countDocuments({ isQueued: true }) | ||
logger('info', ['handle-stats', 'action', 'queue', 'success', 'found', count]) | ||
response.json({ queue: count }) | ||
} catch (error) { | ||
logger('error', ['handle-stats', 'action', 'queue', error]) | ||
response.status(500) | ||
response.send(error) | ||
} | ||
} |
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,30 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
const publicDocTypes = require('../lib/public-doctypes') | ||
|
||
function getParams (url) { | ||
const list = url.split('/') | ||
return { | ||
type: list[3] | ||
} | ||
} | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
const params = getParams(request.url) | ||
const { type } = params | ||
const query = type ? { documentType: type, documentCategory: { $in: publicDocTypes } } : { documentCategory: { $in: publicDocTypes } } | ||
logger('info', ['routes', 'schools', 'type', type || 'any']) | ||
logs.aggregate([{ $match: query }, { $group: { _id: '$schoolName', total: { $sum: 1 } } }]) | ||
.sort({ total: -1 }).toArray((error, data) => { | ||
if (error) { | ||
logger('error', ['handle-stats', 'action', 'schools', error]) | ||
response.status(500) | ||
response.send(error) | ||
} else { | ||
logger('info', ['handle-stats', 'action', 'schools', 'success']) | ||
response.json(data) | ||
} | ||
}) | ||
} |
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,43 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
const publicDocTypes = require('../lib/public-doctypes') | ||
|
||
function getParams (url) { | ||
const list = url.split('/') | ||
return { | ||
type: list[3], | ||
category: list[4] | ||
} | ||
} | ||
|
||
module.exports = async (request, response) => { | ||
logger('info', ['handle-stats', 'action', 'time']) | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
const params = getParams(request.url) | ||
const { type, category } = params | ||
const query = type ? { documentType: type, documentCategory: { $in: category ? [category] : publicDocTypes } } : { documentCategory: { $in: category ? [category] : publicDocTypes } } | ||
logs.find(query, { skjemaUtfyllingStart: 1, skjemaUtfyllingStop: 1 }).toArray((error, data) => { | ||
if (error) { | ||
logger('error', ['handle-stats', 'action', 'time', error]) | ||
response.status(500) | ||
response.send(error) | ||
} else { | ||
logger('info', ['handle-stats', 'action', 'time', 'success']) | ||
let count = 0 | ||
const time = data.map(item => { | ||
let ms = 0 | ||
if (item.skjemaUtfyllingStop && item.skjemaUtfyllingStart) { | ||
count++ | ||
ms = parseInt(item.skjemaUtfyllingStop, 10) - parseInt(item.skjemaUtfyllingStart, 10) | ||
} | ||
return ms | ||
}) | ||
const total = time.reduce((prev, curr) => { | ||
prev += curr | ||
return prev | ||
}, 0) | ||
response.json({ total: total, count: count }) | ||
} | ||
}) | ||
} |
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,29 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
const publicDocTypes = require('../lib/public-doctypes') | ||
|
||
function getParams (url) { | ||
const list = url.split('/') | ||
return { | ||
type: list[3], | ||
category: list[4] | ||
} | ||
} | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
const params = getParams(request.url) | ||
const { type, category } = params | ||
const query = type ? { documentType: type, documentCategory: { $in: category ? [category] : publicDocTypes } } : { documentCategory: { $in: category ? [category] : publicDocTypes } } | ||
logger('info', ['routes', 'total', 'type', type || 'any']) | ||
try { | ||
const count = await logs.countDocuments(query) | ||
logger('info', ['routes', 'total', 'success', count]) | ||
response.json({ total: count }) | ||
} catch (error) { | ||
logger('error', ['routes', 'total', error]) | ||
response.status(500) | ||
response.send(error) | ||
} | ||
} |
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,29 @@ | ||
const mongo = require('../lib/mongo') | ||
const logger = require('../lib/logger') | ||
const publicDocTypes = require('../lib/public-doctypes') | ||
|
||
function getParams (url) { | ||
const list = url.split('/') | ||
return { | ||
type: list[3] | ||
} | ||
} | ||
|
||
module.exports = async (request, response) => { | ||
const db = await mongo() | ||
const logs = db.collection(process.env.MONGODB_COLLECTION) | ||
const params = getParams(request.url) | ||
const { type } = params | ||
const query = type ? { documentType: type, documentCategory: { $in: publicDocTypes } } : { documentCategory: { $in: publicDocTypes } } | ||
logger('info', ['routes', 'usage', 'type', type || 'any']) | ||
logs.distinct('userName', query, (error, data) => { | ||
if (error) { | ||
logger('error', ['handle-stats', 'action', 'usage', error]) | ||
response.status(500) | ||
response.send(error) | ||
} else { | ||
logger('info', ['handle-stats', 'action', 'usage', 'success']) | ||
response.json({ total: data.length }) | ||
} | ||
}) | ||
} |
Oops, something went wrong.