API-37: Adding endpoints for climbing route rating app (!16)
Jenkins Production Deployment

Co-authored-by: Patrick Mueller <patrick@mueller-patrick.tech>
Reviewed-on: #16
Co-authored-by: Patrick Müller <patrick@plutodev.de>
Co-committed-by: Patrick Müller <patrick@plutodev.de>
This commit was merged in pull request #16.
This commit is contained in:
Paddy committed 2022-01-08 22:21:19 +00:00
1 parent b4d5bdd0b6
commit 25a66b060c
18 files changed
+4267 -26

No files matched your search

@@ -0,0 +1,59 @@
import {ClimbingRouteRatingDB} from '../ClimbingRouteRating.db';
import {ClimbingRoute} from './ClimbingRoute.interface';
import random from 'random-words';
/**
* Fetches and returns all known climbing routes
* @return Promise<ClimbingRoute[]> The climbing routes
*/
export const findAll = async (): Promise<ClimbingRoute[]> => {
let conn = ClimbingRouteRatingDB.getConnection();
try {
return await conn.query('SELECT route_id, gym_id, name, difficulty, route_setting_date FROM climbing_routes');
} catch (err) {
throw err;
}
};
/**
* Fetches and returns information about the given route
* @param route_id The id of the route
* @return Promise<ClimbingRoute> The climbing route
*/
export const findById = async (route_id: string): Promise<ClimbingRoute> => {
let conn = ClimbingRouteRatingDB.getConnection();
try {
return await conn.query('SELECT route_id, gym_id, name, difficulty, route_setting_date FROM climbing_routes WHERE route_id = ?', route_id);
} catch (err) {
throw err;
}
};
/**
* Creates a new route and returns the id of the created route
* @param gym_id The id of the climbing gym that the route belongs to
* @param name The name of the climbing route
* @param difficulty The difficulty of the climbing route
* @return string The id of the created route
*/
export const createRoute = async (gym_id: number, name: string, difficulty: string): Promise<string> => {
let conn = ClimbingRouteRatingDB.getConnection();
// Generate route id
let route_id = '';
let randWords = random(3);
for (let i = 0; i <= 2; i++) {
route_id += randWords[i];
if (i < 2) {
route_id += '-';
}
}
try {
await conn.query('INSERT INTO climbing_routes (route_id, gym_id, name, difficulty) VALUES (?, ?, ?, ?)', [route_id, gym_id, name, difficulty]);
return route_id;
} catch (err) {
throw err;
}
};