mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-27 16:10:30 +08:00
Logging interactions to tasks
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
.venv
|
||||
*.pyc
|
||||
*.swp
|
||||
|
||||
@@ -12,11 +12,17 @@ export default async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const { id, rating } = await JSON.parse(req.body);
|
||||
const { id, content } = await JSON.parse(req.body);
|
||||
|
||||
const registeredTask = await prisma.registeredTask.findUnique({
|
||||
where: { id },
|
||||
select: { task: true },
|
||||
const interaction = await prisma.taskInteraction.create({
|
||||
data: {
|
||||
content,
|
||||
task: {
|
||||
connect: {
|
||||
id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const interactionRes = await fetch(
|
||||
@@ -28,21 +34,21 @@ export default async (req, res) => {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: "text_reply_to_post",
|
||||
type: "post_rating",
|
||||
user: {
|
||||
id: session.user.id,
|
||||
display_name: session.user.name,
|
||||
auth_method: "local",
|
||||
},
|
||||
post_id: id,
|
||||
user_post_id: "1234",
|
||||
text: rating,
|
||||
user_post_id: interaction.id,
|
||||
...content,
|
||||
}),
|
||||
}
|
||||
);
|
||||
console.log(interactionRes.status);
|
||||
const interaction = await interactionRes.json();
|
||||
console.log(interaction);
|
||||
const newTask = await interactionRes.json();
|
||||
console.log(newTask);
|
||||
|
||||
res.status(200).end();
|
||||
res.status(200).json(newTask);
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@ async function sendRequest(url, { arg }) {
|
||||
}
|
||||
|
||||
export default function NewPage() {
|
||||
const [done, setDone] = useState(false);
|
||||
const responseEl = useRef(null);
|
||||
const {
|
||||
data: registeredTask,
|
||||
@@ -24,13 +25,22 @@ export default function NewPage() {
|
||||
} = useSWRImmutable("/api/new_task", fetcher);
|
||||
const { trigger, isMutating } = useSWRMutation(
|
||||
"/api/update_task",
|
||||
sendRequest
|
||||
sendRequest,
|
||||
{
|
||||
onSuccess: async (data) => {
|
||||
const newTask = await data.json();
|
||||
console.log(newTask);
|
||||
setDone(true);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const submitResponse = () => {
|
||||
trigger({
|
||||
id: registeredTask.id,
|
||||
rating: responseEl.current.value,
|
||||
content: {
|
||||
rating: responseEl.current.value,
|
||||
},
|
||||
});
|
||||
};
|
||||
if (isLoading) {
|
||||
@@ -48,6 +58,7 @@ export default function NewPage() {
|
||||
</div>
|
||||
<input type="text" ref={responseEl} />
|
||||
<button onClick={submitResponse}>Submit Response</button>
|
||||
{done && <div>Done!</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,4 +61,15 @@ model RegisteredTask {
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId String
|
||||
|
||||
interaction TaskInteraction[]
|
||||
}
|
||||
|
||||
model TaskInteraction {
|
||||
id String @id @default(uuid())
|
||||
|
||||
content Json
|
||||
|
||||
task RegisteredTask @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
||||
taskId String
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user