[questions][fix] re add filtering by content

pull/510/head
hpkoh 3 years ago
parent 59b1dc68f3
commit 81e24165a5

@ -0,0 +1,47 @@
/*
Warnings:
- You are about to drop the `QuestionQuestionTagEntry` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `QuestionTag` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "QuestionQuestionTagEntry" DROP CONSTRAINT "QuestionQuestionTagEntry_questionId_fkey";
-- DropForeignKey
ALTER TABLE "QuestionQuestionTagEntry" DROP CONSTRAINT "QuestionQuestionTagEntry_tagId_fkey";
-- DropTable
DROP TABLE "QuestionQuestionTagEntry";
-- DropTable
DROP TABLE "QuestionTag";
-- CreateTable
CREATE TABLE "QuestionsQuestionTag" (
"id" TEXT NOT NULL,
"tag" TEXT NOT NULL,
CONSTRAINT "QuestionsQuestionTag_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "QuestionsQuestionTagEntry" (
"id" TEXT NOT NULL,
"questionId" TEXT NOT NULL,
"tagId" TEXT NOT NULL,
CONSTRAINT "QuestionsQuestionTagEntry_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "QuestionsQuestionTag_tag_key" ON "QuestionsQuestionTag"("tag");
-- CreateIndex
CREATE UNIQUE INDEX "QuestionsQuestionTagEntry_questionId_tagId_key" ON "QuestionsQuestionTagEntry"("questionId", "tagId");
-- AddForeignKey
ALTER TABLE "QuestionsQuestionTagEntry" ADD CONSTRAINT "QuestionsQuestionTagEntry_questionId_fkey" FOREIGN KEY ("questionId") REFERENCES "QuestionsQuestion"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "QuestionsQuestionTagEntry" ADD CONSTRAINT "QuestionsQuestionTagEntry_tagId_fkey" FOREIGN KEY ("tagId") REFERENCES "QuestionsQuestionTag"("id") ON DELETE CASCADE ON UPDATE CASCADE;

@ -461,26 +461,26 @@ model QuestionsQuestion {
comments QuestionsQuestionComment[]
answers QuestionsAnswer[]
listQuestionEntries QuestionsListQuestionEntry[]
questionTagEntries QuestionQuestionTagEntry[]
questionTagEntries QuestionsQuestionTagEntry[]
@@index([lastSeenAt, id])
@@index([numEncounters, id])
@@index([upvotes, id])
}
model QuestionTag {
id String @id @default(cuid())
tag String @unique
questionTagEntries QuestionQuestionTagEntry[]
model QuestionsQuestionTag {
id String @id @default(cuid())
tag String @unique
questionTagEntries QuestionsQuestionTagEntry[]
}
model QuestionQuestionTagEntry {
model QuestionsQuestionTagEntry {
id String @id @default(cuid())
questionId String
tagId String
question QuestionsQuestion @relation(fields: [questionId], references: [id], onDelete: Cascade)
tag QuestionTag @relation(fields: [tagId], references: [id], onDelete: Cascade)
question QuestionsQuestion @relation(fields: [questionId], references: [id], onDelete: Cascade)
tag QuestionsQuestionTag @relation(fields: [tagId], references: [id], onDelete: Cascade)
@@unique([questionId, tagId])
}

@ -413,6 +413,9 @@ export const questionsQuestionRouter = createRouter()
orderBy: sortCondition,
take: input.limit + 1,
where: {
id: input.content !== "" ? {
in: relatedQuestionsIdArray,
} : undefined,
...(input.questionTypes.length > 0
? {
questionType: {

@ -8,7 +8,7 @@ export const questionsTagUserRouter = createProtectedRouter()
tag: z.string(),
}),
async resolve({ ctx, input }) {
return await ctx.prisma.questionTag.upsert({
return await ctx.prisma.questionsQuestionTag.upsert({
where: {
tag : input.tag,
},
@ -25,7 +25,7 @@ export const questionsTagUserRouter = createProtectedRouter()
tagId: z.string(),
}),
async resolve({ ctx, input }) {
return await ctx.prisma.questionQuestionTagEntry.create({
return await ctx.prisma.questionsQuestionTagEntry.create({
data: {
question:{
connect: {
@ -46,7 +46,7 @@ export const questionsTagUserRouter = createProtectedRouter()
id: z.string(),
}),
async resolve({ ctx, input }) {
return await ctx.prisma.questionQuestionTagEntry.delete({
return await ctx.prisma.questionsQuestionTagEntry.delete({
where: {
id: input.id,
},
@ -60,7 +60,7 @@ export const questionsTagUserRouter = createProtectedRouter()
}),
async resolve({ ctx, input }) {
return await ctx.prisma.$transaction(async (tx) => {
const questionTagsUpdated = await tx.questionQuestionTagEntry.updateMany({
const questionTagsUpdated = await tx.questionsQuestionTagEntry.updateMany({
where: {
tagId: input.tagToCombineId,
},
@ -69,7 +69,7 @@ export const questionsTagUserRouter = createProtectedRouter()
},
});
tx.questionTag.delete({
tx.questionsQuestionTag.delete({
where: {
id: input.tagToCombineId,
},

Loading…
Cancel
Save