From 41a457cab261bb30b56ed35e59f4c755461224bb Mon Sep 17 00:00:00 2001 From: edinstance Date: Sat, 19 Oct 2024 17:06:05 +0100 Subject: [PATCH 1/2] feat: updated prompt mutations to use admin mutations --- app/prompts/[promptId]/page.tsx | 2 +- convex/prompts.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/prompts/[promptId]/page.tsx b/app/prompts/[promptId]/page.tsx index e3ca053..1764719 100644 --- a/app/prompts/[promptId]/page.tsx +++ b/app/prompts/[promptId]/page.tsx @@ -16,7 +16,7 @@ export default function editPromtPage({ const prompt = useQuery(api.prompts.getPromptById, { promptId: params.promptId, }); - console.log(prompt); + const updatePrompt = useMutation(api.prompts.updatePrompt); const isAdmin = useQuery(api.users.isAdmin); diff --git a/convex/prompts.ts b/convex/prompts.ts index a76469e..3f5d9e8 100644 --- a/convex/prompts.ts +++ b/convex/prompts.ts @@ -1,6 +1,7 @@ import { v } from "convex/values"; import { internalMutation, mutation, query } from "./_generated/server"; import { Id } from "./_generated/dataModel"; +import { adminMutationBuilder } from "./users"; const defaultPrompt = ` Your task is to play a game. We will give you a 2d array of characters that represent the game board. Before the game starts, you have these two tasks: @@ -106,7 +107,7 @@ export const getAllPrompts = query({ }, }); -export const createPrompt = mutation({ +export const createPrompt = adminMutationBuilder({ args: { promptName: v.string(), prompt: v.string(), @@ -121,7 +122,7 @@ export const createPrompt = mutation({ }, }); -export const updatePrompt = mutation({ +export const updatePrompt = adminMutationBuilder({ args: { promptId: v.id("prompts"), promptName: v.string(), @@ -135,7 +136,7 @@ export const updatePrompt = mutation({ }, }); -export const deletePrompt = mutation({ +export const deletePrompt = adminMutationBuilder({ args: { promptId: v.id("prompts"), }, @@ -144,7 +145,7 @@ export const deletePrompt = mutation({ }, }); -export const enablePrompt = mutation({ +export const enablePrompt = adminMutationBuilder({ args: { promptId: v.id("prompts"), }, From 19010c930e1f56cee6e7bc8b2e136e1dc8e51cde Mon Sep 17 00:00:00 2001 From: edinstance Date: Sat, 19 Oct 2024 17:07:48 +0100 Subject: [PATCH 2/2] feat: updated ranking schemas --- convex/leaderboard.ts | 12 ++++++------ convex/schema.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/convex/leaderboard.ts b/convex/leaderboard.ts index 3ee50e1..1c6239f 100644 --- a/convex/leaderboard.ts +++ b/convex/leaderboard.ts @@ -4,7 +4,7 @@ import { api } from "./_generated/api"; export const getGlobalRankings = query({ handler: async ({ db }) => { - const res = await db.query("globalrankings").collect(); + const res = await db.query("globalRankings").collect(); // Sort the results by wins/losses ratio const sortedResults = res.sort((a, b) => { @@ -23,7 +23,7 @@ export const getGlobalRankings = query({ export const getLevelRankings = query({ handler: async ({ db }) => { - const res = await db.query("levelrankings").collect(); + const res = await db.query("levelRankings").collect(); const sortedResults = res.sort((a, b) => { if (a.level < b.level) { @@ -53,14 +53,14 @@ export const updateRankings = internalMutation({ } const globalRanking = await ctx.db - .query("globalrankings") + .query("globalRankings") .withIndex("by_modelId_promptId", (q) => q.eq("modelId", args.modelId).eq("promptId", activePrompt._id), ) .first(); const levelRanking = await ctx.db - .query("levelrankings") + .query("levelRankings") .withIndex("by_modelId_level_promptId", (q) => q .eq("modelId", args.modelId) @@ -70,7 +70,7 @@ export const updateRankings = internalMutation({ .first(); if (!globalRanking) { - await ctx.db.insert("globalrankings", { + await ctx.db.insert("globalRankings", { modelId: args.modelId, wins: args.isWin ? 1 : 0, losses: args.isWin ? 0 : 1, @@ -84,7 +84,7 @@ export const updateRankings = internalMutation({ } if (!levelRanking) { - await ctx.db.insert("levelrankings", { + await ctx.db.insert("levelRankings", { modelId: args.modelId, level: args.level, wins: args.isWin ? 1 : 0, diff --git a/convex/schema.ts b/convex/schema.ts index af5b813..0afd5ab 100644 --- a/convex/schema.ts +++ b/convex/schema.ts @@ -42,13 +42,13 @@ export default defineSchema({ }) .index("by_gameId_level", ["gameId", "level"]) .index("by_status", ["status"]), - globalrankings: defineTable({ + globalRankings: defineTable({ modelId: v.string(), wins: v.number(), losses: v.number(), promptId: v.optional(v.id("prompts")), }).index("by_modelId_promptId", ["modelId", "promptId"]), - levelrankings: defineTable({ + levelRankings: defineTable({ modelId: v.string(), level: v.number(), wins: v.number(),