diff --git a/api/api.js b/api/api.js index ce9674a..d630594 100644 --- a/api/api.js +++ b/api/api.js @@ -15,4 +15,8 @@ api.get( api.use('/players', playerApi) api.use('/maps', mapApi) +/** + * This module is the entrypoint for the API. + * @module api/api + */ export default api \ No newline at end of file diff --git a/api/maps.js b/api/maps.js index 93d5164..766cdd2 100644 --- a/api/maps.js +++ b/api/maps.js @@ -66,4 +66,8 @@ mapApi.get( } ) +/** + * This module handles all API actions related to maps. + * @module api/maps + */ export default mapApi \ No newline at end of file diff --git a/api/players.js b/api/players.js index cebacc5..b93dc86 100644 --- a/api/players.js +++ b/api/players.js @@ -67,4 +67,8 @@ playerApi.get( } ) +/** + * This module handles all API actions related to players. + * @module api/players + */ export default playerApi \ No newline at end of file diff --git a/index.js b/index.js index 57f9887..24c361a 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,9 @@ +/** + * This is the entrypoint for 'DDStats'. + * DDStats is a custom API that servers statistics from the DDRace Network- + * @author BurnyLlama + */ + import express from 'express' import dotenv from 'dotenv' import sqlite2mongo from './libs/database/sqlite2mongo.js' diff --git a/libs/database/init.js b/libs/database/init.js index db976f0..3141a2f 100644 --- a/libs/database/init.js +++ b/libs/database/init.js @@ -7,6 +7,10 @@ const log = initLog("database") export let sqlite = undefined +/** + * This initializes both the sqlite db and mongodb. + * @module libs/database/init + */ async function init() { log("Starting up databases...") diff --git a/libs/database/sqlite2mongo.js b/libs/database/sqlite2mongo.js index 0baabb3..01d6208 100644 --- a/libs/database/sqlite2mongo.js +++ b/libs/database/sqlite2mongo.js @@ -4,6 +4,11 @@ import postTasks from './sqlite2mongo/postTasks.js' const log = initLog("sqlite2mongo") +/** + * This function handles the sqlite database provided by DDNet and + * migrates the data to mongodb. + * @module libs/database/sqlite2mongo + */ async function sqlite2mongo() { log("Checking for additions to 'ddnet.sqlite'...") diff --git a/libs/database/sqlite2mongo/checks.js b/libs/database/sqlite2mongo/checks.js index 6656495..bd2b71e 100644 --- a/libs/database/sqlite2mongo/checks.js +++ b/libs/database/sqlite2mongo/checks.js @@ -7,7 +7,10 @@ import initLog from '../../utills/log.js' const log = initLog("sqlite2mongo") - +/** + * This for new maps from the sqlite db. If any are found it adds them to mongodb. + * @module libs/database/sqlite2mongo/checks + */ export async function checkForMaps() { log("Checking for new maps...") @@ -39,7 +42,10 @@ export async function checkForMaps() { } - +/** + * This checks for new players in the sqlite db. If any are found it adds them to mongodb. + * @module libs/database/sqlite2mongo/checks + */ export async function checkForPlayers() { log("Checking for new players...") @@ -47,7 +53,8 @@ export async function checkForPlayers() { const date = latestPlayer ? latestPlayer.firstFinish.toISOString().replace(/[TZ]/g, " ").replace(/\.[0-9\s]+/, "") : undefined const newPlayerAmount = (await sqlite.get(`select count(Name) FROM (SELECT Name, Timestamp FROM (SELECT Name, Timestamp FROM (SELECT * FROM race ORDER BY Timestamp ASC, Name ASC) GROUP BY Name) ${date ? `WHERE Timestamp > datetime('${date}')` : ''} ORDER BY Timestamp ASC)`))['count(Name)'] if (newPlayerAmount === 0) return log("No new players found...") - + + // Create a temporary table to prevent re-running CPU-intensive queries. log(`Found ${newPlayerAmount} new players!`) log("Importing new players...") await sqlite.exec("DROP TABLE IF EXISTS temp") @@ -78,7 +85,10 @@ export async function checkForPlayers() { } } - +/** + * This checks for new finishes in the sqlite db. If any are found it adds them to mongodb. + * @module libs/database/sqlite2mongo/checks + */ export async function checkForFinishes() { log("Checking for new finishes...") diff --git a/libs/database/sqlite2mongo/postTasks.js b/libs/database/sqlite2mongo/postTasks.js index baa6a07..7375fb2 100644 --- a/libs/database/sqlite2mongo/postTasks.js +++ b/libs/database/sqlite2mongo/postTasks.js @@ -6,6 +6,10 @@ import { sqlite } from '../init.js' const log = initLog("sqlite2mongo") +/** + * This handles some post-tasks that run after the initial checks. + * @module libs/database/sqlite2mongo/postTasks + */ export default async function postTasks() { log("Post tasks...") diff --git a/libs/utills/log.js b/libs/utills/log.js index 9b88482..478d63e 100644 --- a/libs/utills/log.js +++ b/libs/utills/log.js @@ -1,3 +1,13 @@ +/** + * This function creates a custom logging method that adds a prefix evrytime used. + * This is so that you can see what component has done what. + * Example: + * The database-component would log with the prefix 'database' + * + * @param {string} prefix The prefix for the logging-function. + * @returns {function} The created log function. + */ + export default function initLog(prefix) { return string => console.log(`${prefix} >>> ${string}`) } \ No newline at end of file diff --git a/schemas/Finish.js b/schemas/Finish.js index 15d2a4a..f3a4816 100644 --- a/schemas/Finish.js +++ b/schemas/Finish.js @@ -8,4 +8,8 @@ const Finish = new mongoose.Schema({ player: String }) +/** + * This cotains the mongoose 'Finish' model. + * @module schemas/Finish + */ export default mongoose.model("Finish", Finish) \ No newline at end of file diff --git a/schemas/Level.js b/schemas/Level.js index 4868369..6f8442e 100644 --- a/schemas/Level.js +++ b/schemas/Level.js @@ -9,4 +9,8 @@ const Level = new mongoose.Schema({ awardPoints: Number }) +/** + * This cotains the mongoose 'Level' (maps) model. + * @module schemas/Level + */ export default mongoose.model("Level", Level) \ No newline at end of file diff --git a/schemas/Player.js b/schemas/Player.js index e801751..53ab9ff 100644 --- a/schemas/Player.js +++ b/schemas/Player.js @@ -8,4 +8,8 @@ const Player = new mongoose.Schema({ firstFinish: Date }) +/** + * This cotains the mongoose 'Player' model. + * @module schemas/Player + */ export default mongoose.model("Player", Player) \ No newline at end of file diff --git a/schemas/TeamFinish.js b/schemas/TeamFinish.js index f05033a..2caee32 100644 --- a/schemas/TeamFinish.js +++ b/schemas/TeamFinish.js @@ -8,4 +8,8 @@ const TeamFinish = new mongoose.Schema({ players: [ String ] }) +/** + * This cotains the mongoose 'TeamFinish' model. + * @module schemas/TeamFinish + */ export default mongoose.model("TeamFinish", TeamFinish) \ No newline at end of file