add service to table only have videoID

This commit is contained in:
Haidang666
2021-09-30 13:56:55 +07:00
parent 99d72b92e4
commit 356974b478
18 changed files with 188 additions and 60 deletions

View File

@@ -2,18 +2,20 @@ import { db } from "../databases/databases";
import { Logger } from "../utils/logger";
import { Request, Response } from "express";
import { Category, VideoID } from "../types/segments.model";
import { getService } from "../utils/getService";
export async function getLockCategories(req: Request, res: Response): Promise<Response> {
const videoID = req.query.videoID as VideoID;
const service = getService(req.query.service as string);
if (videoID == undefined) {
//invalid request
return res.sendStatus(400);
}
console.log(service);
try {
// Get existing lock categories markers
const row = await db.prepare("all", 'SELECT "category", "reason" from "lockCategories" where "videoID" = ?', [videoID]) as {category: Category, reason: string}[];
const row = await db.prepare("all", 'SELECT "category", "reason" from "lockCategories" where "videoID" = ? AND "service" = ?', [videoID, service]) as {category: Category, reason: string}[];
// map categories to array in JS becaues of SQL incompatibilities
const categories = row.map(item => item.category);
if (categories.length === 0 || !categories[0]) return res.sendStatus(404);