getLockCategories

- add insertLock
This commit is contained in:
Michael C
2023-09-28 23:44:14 -04:00
parent 53e5dcb2f0
commit f72b1abf41
2 changed files with 139 additions and 194 deletions

View File

@@ -2,6 +2,9 @@ import { IDatabase } from "../../src/databases/IDatabase";
import { HashedUserID } from "../../src/types/user.model";
import { User, userArray, usernameUserArray } from "./genUser";
import { Feature } from "../../src/types/user.model";
import { ActionType, Category, Service, VideoIDHash } from "../../src/types/segments.model";
import { genRandomValue } from "./getRandom";
import { getHash } from "../../src/utils/getHash";
// segments
export { insertSegment } from "./segmentQueryGen";
@@ -46,6 +49,28 @@ export const insertVideoInfo = async (db: IDatabase, videoID: string, channelID:
await db.prepare("run", query, [videoID, channelID, title, published]);
};
interface lockParams {
videoID?: string,
userID?: HashedUserID | "",
actionType?: ActionType | string,
category?: Category | string,
hashedVideoID?: VideoIDHash | "",
reason?: string,
service?: Service | string
}
export const insertLock = async(db: IDatabase, overrides: lockParams = {}) => {
const query = 'INSERT INTO "lockCategories" ("videoID", "userID", "actionType", "category", "hashedVideoID", "reason", "service") VALUES (?, ?, ?, ?, ?, ?, ?)';
const identifier = "lock";
const defaults = {
videoID: genRandomValue("video", identifier), userID: genRandomValue("user", identifier),
actionType: "skip", category: "sponsor", hashedVideoID: "", reason: "", service: Service.YouTube
};
const params = { ...defaults, ...overrides };
params.hashedVideoID = getHash(params.videoID);
await db.prepare("run", query, Object.values(params));
};
// warning
type warningParams = {
userID?: HashedUserID,