Added JSDoc comments.
This commit is contained in:
parent
07dc061c3c
commit
0058b6eed2
|
@ -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
|
|
@ -66,4 +66,8 @@ mapApi.get(
|
|||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* This module handles all API actions related to maps.
|
||||
* @module api/maps
|
||||
*/
|
||||
export default mapApi
|
|
@ -67,4 +67,8 @@ playerApi.get(
|
|||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* This module handles all API actions related to players.
|
||||
* @module api/players
|
||||
*/
|
||||
export default playerApi
|
6
index.js
6
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 <xmpp:burnyllama@qwik.space>
|
||||
*/
|
||||
|
||||
import express from 'express'
|
||||
import dotenv from 'dotenv'
|
||||
import sqlite2mongo from './libs/database/sqlite2mongo.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...")
|
||||
|
||||
|
|
|
@ -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'...")
|
||||
|
||||
|
|
|
@ -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...")
|
||||
|
||||
|
@ -48,6 +54,7 @@ export async function checkForPlayers() {
|
|||
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...")
|
||||
|
||||
|
|
|
@ -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...")
|
||||
|
||||
|
|
|
@ -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}`)
|
||||
}
|
|
@ -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)
|
|
@ -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)
|
|
@ -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)
|
|
@ -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)
|
Loading…
Reference in New Issue
Block a user