diff --git a/src/commands/admin.ts b/src/commands/admin.ts index f6c6b9e..d88067b 100644 --- a/src/commands/admin.ts +++ b/src/commands/admin.ts @@ -47,6 +47,28 @@ const performPistokoe = async (ctx: ActionContext | CommandContext) => { await ctx.replyWithPhoto(entry?.fileId, validationKeyboard); }; +export const validate = async (ctx: CommandContext) => { + if (!admins.has(ctx.from.id)) return; + + const args = ctx.message.text.split(" "); + + if (args.length <= 1) + return ctx.reply( + "Please give the id of entry to validate as an argument (eg. /validate 10)", + ); + + const possibleNum = Number.parseInt(args[1]); + + if(Number.isNaN(possibleNum)) return ctx.reply("Given id is not a number!"); + + const entry = await getEntry(possibleNum); + if (!entry) return ctx.reply("No such entry"); + + underValidation.set(ctx.chat.id, entry.id); + await ctx.replyWithHTML(formatEntryWithUser(entry as unknown as EntryWithUser)); + await ctx.replyWithPhoto(entry.fileId, validationKeyboard); +} + export const notValidated = async (ctx: ActionContext | CommandContext) => { const notValidated = await amountToValidate(); await ctx.reply(`Number of entries not validated: ${notValidated}`); @@ -113,7 +135,7 @@ export const adminLogin = async ( const userId = ctx.message.from.id; admins.add(userId); await ctx.reply( - "You are now an admin! \n/csv - get all entries in csv \n/pistokoe - validate entries \n/remove [entry id] - remove one entry \n/numtovalidate - number of entries not yet validated \n/allphotos [user id or username] - gets all uploaded photos by user \n/updatedistance [entry id] [distance] - sets a new distance on an entry \n/resetvalidation [entry id] - resets the validation of entry", + "You are now an admin! \n/csv - get all entries in csv \n/pistokoe - validate entries \n/remove [entry id] - remove one entry \n/numtovalidate - number of entries not yet validated \n/allphotos [user id or username] - gets all uploaded photos by user \n/updatedistance [entry id] [distance] - sets a new distance on an entry \n/resetvalidation [entry id] - resets the validation of entry \n/validate [entry id] - starts validation from specific entry", ); return next(); }; diff --git a/src/entries.ts b/src/entries.ts index 880fe16..769d408 100644 --- a/src/entries.ts +++ b/src/entries.ts @@ -48,7 +48,7 @@ const getRandomNotValidEntry = async () => { }; const getEntry = (id: number) => - prisma.entry.findUniqueOrThrow({ where: { id }, include: { user: true } }); + prisma.entry.findUnique({ where: { id }, include: { user: true } }); const removeEntry = (id: number) => prisma.entry.delete({ diff --git a/src/index.ts b/src/index.ts index b3ba81a..6616db6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,7 @@ import { stopValidation, valid1x, valid2x, + validate, } from "./commands/admin"; import entries from "./commands/entries"; import entry from "./commands/entry"; @@ -74,6 +75,7 @@ bot.command("remove", remove); bot.command("allphotos", allPhotosFromUser); bot.command("resetvalidation", resetValidation); bot.command("updatedistance", setDistance); +bot.command("validate", validate); bot.action("invalid", invalid); bot.action("valid1x", valid1x);