Compare commits

...

10 Commits

Author SHA1 Message Date
Nicolai Ort bfa5550e52
Added license 2023-04-25 20:57:35 +02:00
Nicolai Ort 28e161269c
Added extra info to package 2023-04-25 20:57:12 +02:00
Nicolai Ort dbe38c28f2
Added sample env 2023-04-25 20:55:50 +02:00
Nicolai Ort 81eb83547e
Added readme 2023-04-25 20:55:24 +02:00
Nicolai Ort 5dd86a81aa
Added readme 2023-04-25 20:53:49 +02:00
Nicolai Ort 5e2e633b81
reorganize 2023-04-25 20:49:16 +02:00
Nicolai Ort 002f28237b
Extracted login to shared package 2023-04-25 20:49:10 +02:00
Nicolai Ort 0018ea2bb1
Rename to conform to naming scheme 2023-04-25 19:45:03 +02:00
Nicolai Ort ea3d757988
Changes in org 2023-04-25 19:44:42 +02:00
Nicolai Ort afaaaa4e91
missing rename 2023-04-25 19:40:23 +02:00
7 changed files with 107 additions and 37 deletions

3
.env.example Normal file
View File

@ -0,0 +1,3 @@
BASE_URL=https://dev.lauf-fuer-kaya.de
USER=demo
PASSWORD=demo

8
LICENSE Normal file
View File

@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright © 2023 ODIT.Services UG (haftungsbeschränkts) - info@odit.services
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

23
README.md Normal file
View File

@ -0,0 +1,23 @@
# @lfk/scripts
Some fun little scripts to automate tasks regarding the LfK Läufersystem.
## Setup 🛠️
```bash
pnpm i
```
## Scrips
> All of the current scripts - explained
### Shared
#### Login
* Description: Authenticates the user against the backend while setting the OPENAPI objects properties
* Use-case: Used in all other scripts to reduce code duplication
* Config: Set the env vars
* Run: `node ./src/shared/login.js`
### Scans
#### Create fixed scans for group
* Description: Creates distance scans for all runners of a team or org
* Use-case: Schools that get their walk to the event location added to their total distance
* Config: Just set the org id or team id in the first lines of the script
* Run: `node ./src/scans/createFixedScansForGroup.js`

View File

@ -1,7 +1,34 @@
{
"dependencies": {
"@odit/lfk-client-node": "^1.1.1",
"dotenv": "^16.0.3"
"name": "@lfk/scripts",
"private": false,
"license": "MIT",
"repository": "https://git.odit.services/lfk/scripts",
"author": {
"name": "ODIT.Services",
"email": "info@odit.services",
"url": "https://odit.services"
},
"type": "module"
"contributors": [
{
"name": "Nicolai Ort",
"email": "info@nicolai-ort.com",
"url": "https://nicolai-ort.com"
},
{
"name": "Philipp Dormann",
"email": "philipp@philippdormann.de",
"url": "https://philippdormann.de"
}
],
"dependencies": {
"@odit/lfk-client-node": "1.1.1",
"dotenv": "s16.0.3"
},
"type": "module",
"volta": {
"node": "19.9.0"
},
"engines": {
"pnpm": "8"
}
}

View File

@ -1,33 +0,0 @@
import { AuthService, OpenAPI, RunnerOrganizationService, RunnerService, RunnerTeamService, ScanService } from "@odit/lfk-client-node";
import * as dotenv from 'dotenv';
dotenv.config()
const groupID = 3;
const orgID = -1;
const distanceMeter = 69;
OpenAPI.BASE = process.env.BASE_URL;
const user = process.env.USER;
const password = process.env.PASSWORD;
if(!user || !password || !OpenAPI.BASE){
process.exit(1)
}
const auth = await AuthService.authControllerLogin({ username: user, password });
OpenAPI.TOKEN = auth.access_token;
console.log("Logged in")
const runners = await RunnerService.runnerControllerGetAll();
let filteredRunners = [];
if(groupID !== -1){
filteredRunners = runners.filter((r) => r.group.id == groupID);
} else{
filteredRunners = runners.filter((r) => r.group.id == orgID || r.group.parentGroup?.id == orgID);
}
const scans = [];
for (const runner of groupRunners) {
scans.push(ScanService.scanControllerPost({ distance: distanceMeter, runner: runner.id, valid: true }))
}
await Promise.all(scans);

View File

@ -0,0 +1,23 @@
import { RunnerService, ScanService } from "@odit/lfk-client-node";
import { login } from "../shared/login";
const teamID = 79;
const orgID = -1;
const distanceMeter = 3300;
await login();
const runners = await RunnerService.runnerControllerGetAll();
let filteredRunners = [];
if (teamID !== -1) {
filteredRunners = runners.filter((r) => r.group.id == teamID);
} else {
filteredRunners = runners.filter((r) => r.group.id == orgID || r.group.parentGroup?.id == orgID);
}
const scans = [];
for (const runner of filteredRunners) {
scans.push(ScanService.scanControllerPost({ distance: distanceMeter, runner: runner.id, valid: true }))
}
await Promise.all(scans);

19
src/shared/login.js Normal file
View File

@ -0,0 +1,19 @@
import { AuthService, OpenAPI } from "@odit/lfk-client-node";
import * as dotenv from 'dotenv';
dotenv.config()
export async function login() {
OpenAPI.BASE = process.env.BASE_URL;
const user = process.env.USER;
const password = process.env.PASSWORD;
if (!user || !password || !OpenAPI.BASE) {
process.exit(1)
}
const auth = await AuthService.authControllerLogin({ username: user, password });
OpenAPI.TOKEN = auth.access_token;
console.log("Logged in");
return auth;
}