From f00aa6d9d8b56efd5ec07ec047c95433e6e50ed0 Mon Sep 17 00:00:00 2001 From: Niko Date: Mon, 28 Feb 2022 22:05:18 +0100 Subject: [PATCH] Basic code added for sending quizs. TODO: check quiz is valid, it hasn't been responded yet, and is owned by the actor responding + create Note with the response for activitypub + create federation INBOX event for parsing responses --- api/src/api/me.js | 4 ++++ api/src/server.js | 4 +++- web/src/app/js/pages/quiz.js | 13 ++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/api/src/api/me.js b/api/src/api/me.js index c3976d4..7be2250 100644 --- a/api/src/api/me.js +++ b/api/src/api/me.js @@ -116,6 +116,10 @@ module.exports = { return res.json({ error: 'unknown_error' }) return res.json(data) }], + post: [auth.enforceSession, async (req, res) => { + console.log(req.body) + return res.json({}) + }], }, pending_follows: { get: [auth.enforceSession, async (req, res) => { diff --git a/api/src/server.js b/api/src/server.js index e2ee5aa..faf4638 100644 --- a/api/src/server.js +++ b/api/src/server.js @@ -68,7 +68,9 @@ app.on('apex-inbox', activity.federation.inbox) /* POST */ app.route(api.v1('/auth/login')).post(api.auth.login.post) /* GET */ app.route(api.v1('/feed/meet')).get(api.feed.meet.get) /* GET */ app.route(api.v1('/me/pending_follows')).get(api.me.pending_follows.get) -/* GET */ app.route(api.v1('/me/quizs')).get(api.me.quizs.get) +/* ALL */ app.route(api.v1('/me/quizs')) + .get(api.me.quizs.get) + .post(api.me.quizs.post) /* POST */ app.route(api.v1('/accounts/follow')).post(api.accounts.follow.post) /* POST */ app.route(api.v1('/accounts/unfollow')).post(api.accounts.unfollow.post) /* POST */ app.route(api.v1('/accounts/block')).post(api.accounts.block.post) diff --git a/web/src/app/js/pages/quiz.js b/web/src/app/js/pages/quiz.js index 78511e8..ded1fed 100644 --- a/web/src/app/js/pages/quiz.js +++ b/web/src/app/js/pages/quiz.js @@ -157,7 +157,18 @@ app.pages.quiz = { }); }, send: function() { - console.log('SEND'); + const form = document.querySelector('form#quiz'); + var data = { quiz_id: page().data.id }; + for (var i = 0; i < page().data.content.length; i++) { + const key = 'question_'+page().data.content[i].index; + const value = form[key].value.trim(); + if (value === '') + return app.toast.error('TODO: translate: you must fill all quiz questions before sending it'); + data[key] = value; + } + http.post('/api/v1/me/quizs', data, function(json) { + console.log(json); + }); }, }, }