mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-04 14:59:24 -05:00
Add backend support for setting compatibility answers
This commit is contained in:
@@ -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]) => {
|
||||
|
||||
34
backend/api/src/set-compatibility-answer.ts
Normal file
34
backend/api/src/set-compatibility-answer.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user