Add backend support for setting compatibility answers

This commit is contained in:
MartinBraquet
2025-10-24 02:09:46 +02:00
parent e904a7949c
commit e49a7b0bb4
4 changed files with 61 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ import {blockUser, unblockUser} from './block-user'
import {getCompatibleProfilesHandler} from './compatible-profiles'
import {createComment} from './create-comment'
import {createCompatibilityQuestion} from './create-compatibility-question'
import {setCompatibilityAnswer} from './set-compatibility-answer'
import {createProfile} from './create-profile'
import {createUser} from './create-user'
import {getCompatibilityQuestions} from './get-compatibililty-questions'
@@ -170,6 +171,7 @@ const handlers: { [k in APIPath]: APIHandler<k> } = {
'create-comment': createComment,
'hide-comment': hideComment,
'create-compatibility-question': createCompatibilityQuestion,
'set-compatibility-answer': setCompatibilityAnswer,
'create-vote': createVote,
'vote': vote,
'contact': contact,
@@ -188,7 +190,7 @@ const handlers: { [k in APIPath]: APIHandler<k> } = {
'set-last-online-time': setLastOnlineTime,
'save-subscription': saveSubscription,
'create-bookmarked-search': createBookmarkedSearch,
'delete-bookmarked-search': deleteBookmarkedSearch,
'delete-bookmarked-search': deleteBookmarkedSearch,
}
Object.entries(handlers).forEach(([path, handler]) => {

View File

@@ -0,0 +1,34 @@
import {APIHandler} from './helpers/endpoint'
import {createSupabaseDirectClient} from 'shared/supabase/init'
import {Row} from 'common/supabase/utils'
export const setCompatibilityAnswer: APIHandler<'set-compatibility-answer'> = async (
{questionId, multipleChoice, prefChoices, importance, explanation},
auth
) => {
const pg = createSupabaseDirectClient()
const result = await pg.one<Row<'compatibility_answers'>>({
text: `
INSERT INTO compatibility_answers
(creator_id, question_id, multiple_choice, pref_choices, importance, explanation)
VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT (question_id, creator_id)
DO UPDATE SET multiple_choice = EXCLUDED.multiple_choice,
pref_choices = EXCLUDED.pref_choices,
importance = EXCLUDED.importance,
explanation = EXCLUDED.explanation
RETURNING *
`,
values: [
auth.uid,
questionId,
multipleChoice,
prefChoices,
importance,
explanation ?? null,
],
})
return result
}