Compare commits
10 Commits
169c302864
...
bfa5550e52
Author | SHA1 | Date |
---|---|---|
Nicolai Ort | bfa5550e52 | |
Nicolai Ort | 28e161269c | |
Nicolai Ort | dbe38c28f2 | |
Nicolai Ort | 81eb83547e | |
Nicolai Ort | 5dd86a81aa | |
Nicolai Ort | 5e2e633b81 | |
Nicolai Ort | 002f28237b | |
Nicolai Ort | 0018ea2bb1 | |
Nicolai Ort | ea3d757988 | |
Nicolai Ort | afaaaa4e91 |
|
@ -0,0 +1,3 @@
|
|||
BASE_URL=https://dev.lauf-fuer-kaya.de
|
||||
USER=demo
|
||||
PASSWORD=demo
|
|
@ -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.
|
|
@ -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`
|
35
package.json
35
package.json
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
|
@ -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);
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue