import {ClimbingRouteRatingDB} from '../ClimbingRouteRating.db'; import {ClimbingGym} from './ClimbingGym.interface'; /** * Fetches and returns all known climbing gyms * @return Promise The climbing halls */ export const findAll = async (): Promise => { 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 => { 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; } };