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:
@@ -0,0 +1,32 @@
|
||||
import {ClimbingRouteRatingDB} from '../ClimbingRouteRating.db';
|
||||
import {RouteComment} from './RouteComment.interface';
|
||||
|
||||
/**
|
||||
* Fetches and returns all comments that belong to the given route
|
||||
* @return Promise<RouteComment[]> The comments
|
||||
*/
|
||||
export const findByRoute = async (route_id: string): Promise<RouteComment[]> => {
|
||||
let conn = ClimbingRouteRatingDB.getConnection();
|
||||
try {
|
||||
return await conn.query('SELECT comment_id, route_id, comment, timestamp FROM route_comments WHERE route_id = ?', route_id);
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new comment and returns the id of the created comment
|
||||
* @param route_id The id of the route to create the comment for
|
||||
* @param comment The comment
|
||||
* @return number The id of the comment
|
||||
*/
|
||||
export const createComment = async (route_id: string, comment: string): Promise<number> => {
|
||||
let conn = ClimbingRouteRatingDB.getConnection();
|
||||
try {
|
||||
let res = await conn.query('INSERT INTO route_comments (route_id, comment) VALUES (?, ?) RETURNING comment_id', [route_id, comment]);
|
||||
|
||||
return res[0].comment_id;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user