Merge branch 'main' into 766_admin_enhancement

This commit is contained in:
notmd
2023-01-20 23:12:43 +07:00
63 changed files with 874 additions and 225 deletions
+11
View File
@@ -0,0 +1,11 @@
import { withoutRole } from "src/lib/auth";
import { oasstApiClient } from "src/lib/oasst_api_client";
import { getBackendUserCore } from "src/lib/users";
const handler = withoutRole("banned", async (req, res, token) => {
const user = await getBackendUserCore(token.sub);
const availableTasks = await oasstApiClient.fetch_available_tasks(user);
res.status(200).json(availableTasks);
});
export default handler;
@@ -1,6 +1,7 @@
import { withoutRole } from "src/lib/auth";
import { oasstApiClient } from "src/lib/oasst_api_client";
import prisma from "src/lib/prismadb";
import { getBackendUserCore } from "src/lib/users";
/**
* Returns a new task created from the Task Backend. We do a few things here:
@@ -14,9 +15,10 @@ const handler = withoutRole("banned", async (req, res, token) => {
// Fetch the new task.
const { task_type } = req.query;
const user = await getBackendUserCore(token.sub);
let task;
try {
task = await oasstApiClient.fetchTask(task_type as string, token);
task = await oasstApiClient.fetchTask(task_type as string, user);
} catch (err) {
console.error(err);
res.status(500).json(err);
+3 -1
View File
@@ -2,6 +2,7 @@ import { Prisma } from "@prisma/client";
import { withoutRole } from "src/lib/auth";
import { oasstApiClient } from "src/lib/oasst_api_client";
import prisma from "src/lib/prismadb";
import { getBackendUserCore } from "src/lib/users";
/**
* Stores the task interaction with the Task Backend and then returns the next task generated.
@@ -39,9 +40,10 @@ const handler = withoutRole("banned", async (req, res, token) => {
},
});
const user = await getBackendUserCore(token.sub);
let newTask;
try {
newTask = await oasstApiClient.interactTask(update_type, taskId, frontendId, interaction.id, content, token);
newTask = await oasstApiClient.interactTask(update_type, taskId, frontendId, interaction.id, content, user);
} catch (err) {
console.error(JSON.stringify(err));
return res.status(500).json(err);