All checks were successful
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>
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import {ClimbingRouteRatingDB} from '../ClimbingRouteRating.db';
|
|
import {ClimbingGym} from './ClimbingGym.interface';
|
|
|
|
/**
|
|
* Fetches and returns all known climbing gyms
|
|
* @return Promise<ClimbingHall[]> The climbing halls
|
|
*/
|
|
export const findAll = async (): Promise<ClimbingGym[]> => {
|
|
let conn = ClimbingRouteRatingDB.getConnection();
|
|
try {
|
|
return await conn.query('SELECT gym_id, name, city, verified FROM climbing_gyms');
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Creates a climbing gym and returns the id of the created gym
|
|
* @param name The name of the climbing hall
|
|
* @param city The city of the climbing hall
|
|
* @return number The id of the climbing hall
|
|
*/
|
|
export const createGym = async (name: string, city: string): Promise<number> => {
|
|
let conn = ClimbingRouteRatingDB.getConnection();
|
|
|
|
try {
|
|
let res = await conn.query('INSERT INTO climbing_gyms (name, city) VALUES (?, ?) RETURNING gym_id', [name, city]);
|
|
|
|
return res[0].hall_id;
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
};
|