Azure function for handling stats
Creates a statistics document in {system}-collection in statistics database
See the example below for required fields. You can add as many optional fields as you like in addition to the required fields.
Example payload
{
"system": "Acos", // Required when not using system in param (url). System name. New system creates a new collection
"engine": "azf-acos-interact v1", // Required. e.g. from package json
"county": "VTFK", // Optional. If missing autogenerated from DEFAULT_COUNTY environment variable
"company": "SMM", // Required. Sector
"department": "Graveteam", // Optional. If missing, company will be set here.
"description": "Arkivering av gravesøknad og opprettelse av et listeelement i SP. Oppdaterer også kontaktobjektet i 360", // Required. A description of what the statistic element represents
"projectId": "Prosjekt ID (Hvis det er en kobling til innovasjonsløypa)", // Optional. If not set, will be set to "ingen prosjekttilknytning"
"type": "SMM - Gravesoknad", // Required. A short searchable type-name that distinguishes the statistic element
"externalId": "refId fra Acos", // Optional. ID in the external {system}
// optional fields:
"optionalField": "23/45678-3", // Optional. anything you like
"optionalField2": 4567895, // Optional. anything you like
...
"anotherLastOptionalkField": true, // Optional. anything you like
}
Example payload - system from url will be used as "system" property and collection in stats db
{
"engine": "azf-acos-interact v1", // Required. e.g. from package json
"county": "VTFK", // Optional. If missing autogenerated from DEFAULT_COUNTY environment variable
"company": "SMM", // Required. Sector
"department": "Graveteam", // Optional. If missing, company will be set here.
"description": "Arkivering av gravesøknad og opprettelse av et listeelement i SP. Oppdaterer også kontaktobjektet i 360", // Required. A description of what the statistic element represents
"projectId": "Prosjekt ID (Hvis det er en kobling til innovasjonsløypa)", // Optional. If not set, will be set to "ingen prosjekttilknytning"
"type": "SMM - Gravesoknad", // Required. A short searchable type-name that distinguishes the statistic element
"externalId": "refId fra Acos", // Optional. ID in the external {system}
// optional fields:
"optionalField": "23/45678-3", // Optional. anything you like
"optionalField2": 4567895, // Optional. anything you like
...
"anotherLastOptionalkField": true, // Optional. anything you like
}
Returns a list of all systemnames (collections) in the statistics db
Example request
GET https://{statsurl}/api/Systems
Example return value
[
"publish-teams-document",
"vigo-isi-arkiv",
"import-files-p360",
"tullball",
"Masseutsendelse",
"littasystem",
"IOP",
"onbaording",
"Digitroll",
"MinElev",
"hei med mellomrom",
"Acos skjema",
"onboarding",
"dos-arkivaros"
]
Returns stats for {system}
Example request
GET https://{statsurl}/api/Stats/Acos%20skjema
Example return value
[
{
"_id": "655f398962f1958a50d4eec5",
"system": "Acos skjema",
"engine": "azf-acos-interact 1.9.1",
"createdTimestamp": "2023-11-23T11:37:45.025Z",
"county": "VFK",
"company": "Opplæring",
"department": "EKSAMEN",
"description": "Sender til elevmappe",
"projectId": "ingen prosjekttilknytning",
"externalId": "1287555",
"type": "Søknad om tilrettelegging på fag, svenne eller kompetanseprøve",
"documentNumber": "24/00001-12"
},
{
"_id": "655f511e62f1958a50d4eec6",
"system": "Acos skjema",
"engine": "azf-acos-interact 1.9.1",
"createdTimestamp": "2023-11-23T13:18:22.648Z",
"county": "VFK",
"company": "HRMU",
"department": "Mestring og utvikling",
"description": "Arkivering av henvendelse til mobbeombud. Skal opprettes en ny sak pr skjema",
"projectId": "ingen prosjekttilknytning",
"externalId": "1287567",
"type": "Henvendelse til mobbeombud",
"documentNumber": "25/00098-3",
"skole": "Hedrum barneskole"
}
]
?count=true only returns the count of returned documents
Example request
GET https://{statsurl}/api/Stats/Acos%20skjema?count=true
Example response
156
?filter={filter} only returns documents that match the filter
Supported logical operators:
- and
- or
- not
- nor
Supported comparison operators:
- eq
- gt
- gte
- lt
- lte
- ne (Not implemented until we need it: in, nin)
When using several logical operators on one level - you must use parenthesis
Comparisons must be on the format
Examples
GET https://{statsurl}/api/Stats/Acos%20skjema?filter=createdTimestamp gt 2024-01-01 and createdTimestamp lt 2025-01-01
GET https://{statsurl}/api/Stats/Acos%20skjema?filter=createdTimestamp gt 2024-01-01 and createdTimestamp lt 2025-01-01 and (type eq 'type 1' or type ne type2)
GET https://{statsurl}/api/Stats/Acos%20skjema?filter=createdTimestamp gt 2024-01-01 and createdTimestamp lt 2025-01-01 and (type eq 'type 1' or type ne type2)&count=true
can be combined with query param "count"
The filter is parsed by the horrific function in parse-query.js
- Clone the repo
- Make sure you have azure function core tools installed
npm i
- Create a local.settings.json file
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"MONGO_STATISTICS_CONNECTION_STRING": "connectionstring",
"MONGO_DB_STATISTICS_DATABASE": "statistics db name",
"DEFAULT_COUNTY": "county name"
}
}
func start