[questions][chore] update naming

pull/412/head
hpkoh 3 years ago
parent 3d70ca3b87
commit fdbc04a475

@ -1,5 +1,5 @@
-- AlterTable -- AlterTable
ALTER TABLE "QuestionsQuestion" ADD COLUMN "contentSearch" TSVECTOR ALTER TABLE "QuestionsQuestion" ADD COLUMN "contentSearch" TSVECTOR
GENERATED ALWAYS AS GENERATED ALWAYS AS
to_tsvector('english', coalesce(content, '')) to_tsvector('english', coalesce(content, ''))
STORED; STORED;

@ -224,14 +224,17 @@ export const questionsQuestionRouter = createProtectedRouter()
.split(/\s+/) .split(/\s+/)
.join(" | "); .join(" | ");
const res = await ctx.prisma.$queryRaw` const relatedQuestions = await ctx.prisma.$queryRaw`
SELECT content FROM "Post" SELECT content FROM "QuestionsQuestion"
WHERE WHERE
"contentSearch" @@ to_tsquery('english', ${query}) "contentSearch" @@ to_tsquery('english', ${query})
ORDER BY ts_rank("textSearch", to_tsquery('english', ${query})) DESC ORDER BY ts_rank("textSearch", to_tsquery('english', ${query})) DESC
LIMIT 10; LIMIT 10;
`; `;
return relatedQuestions;
} }
}) })
.mutation('create', { .mutation('create', {
input: z.object({ input: z.object({
@ -454,7 +457,7 @@ export const questionsQuestionRouter = createProtectedRouter()
const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1; const incrementValue = voteToDelete.vote === Vote.UPVOTE ? -1 : 1;
const [questionVote] = await ctx.prisma.$transaction([ const [ questionVote ] = await ctx.prisma.$transaction([
ctx.prisma.questionsQuestionVote.delete({ ctx.prisma.questionsQuestionVote.delete({
where: { where: {
id: input.id, id: input.id,

Loading…
Cancel
Save