This is the code that runs https://bandolier.learnjsthehardway.com/ for you to review. It uses the https://git.learnjsthehardway.com/learn-javascript-the-hard-way/bandolier-template to create the documentation for the project.
https://bandolier.learnjsthehardway.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
847 B
29 lines
847 B
2 years ago
|
import { Media } from "../lib/models.js";
|
||
|
import { knex } from "../lib/ormish.js";
|
||
|
import logging from '../lib/logging.js';
|
||
|
import assert from 'assert';
|
||
|
import { API } from '../lib/api.js';
|
||
|
|
||
|
const log = logging.create(import.meta.url);
|
||
|
|
||
|
export const get = async (req, res) => {
|
||
|
const api = new API(req, res);
|
||
|
try {
|
||
|
const { media_id, really } = req.query;
|
||
|
|
||
|
assert(media_id !== undefined, "media_id required");
|
||
|
assert(really === "true" || really === "false", "really required");
|
||
|
|
||
|
if(really === "true") {
|
||
|
await knex(Media.table_name).increment('likes').where({id: media_id});
|
||
|
} else {
|
||
|
await knex(Media.table_name).increment('dislikes').where({id: media_id});
|
||
|
}
|
||
|
|
||
|
api.reply(200, {message: "OK" });
|
||
|
} catch (error) {
|
||
|
log.error(error);
|
||
|
api.error(500, error.message || "Internal Server Error");
|
||
|
}
|
||
|
}
|