-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: faq sort + feat: faq-delete + fix: faq create after edit bug #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "faq_categories" ADD COLUMN "sortOrder" INTEGER NOT NULL DEFAULT 0; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "faqs" ADD COLUMN "sortOrder" INTEGER NOT NULL DEFAULT 0; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| model FaqCategory { | ||
| id String @id @default(uuid(7)) | ||
| name String | ||
| id String @id @default(uuid(7)) | ||
| name String | ||
| sortOrder Int @default(0) | ||
|
|
||
| unterveranstaltungId String | ||
| unterveranstaltung Unterveranstaltung @relation(fields: [unterveranstaltungId], references: [id]) | ||
|
|
@@ -11,9 +12,10 @@ model FaqCategory { | |
| } | ||
|
|
||
| model Faq { | ||
| id String @id @default(uuid(7)) | ||
| question String | ||
| answer String | ||
| id String @id @default(uuid(7)) | ||
| question String | ||
| answer String | ||
| sortOrder Int @default(0) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ich würde den default auf
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vorher wurde beim list kein Alsoo entweder wir setzen für die existierenden Daten die |
||
|
|
||
| categoryId String | ||
| category FaqCategory @relation(fields: [categoryId], references: [id]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,22 @@ export const faqCreateProcedure = defineProtectedMutateProcedure({ | |
| faq: faqSchema, | ||
| }), | ||
| handler: async ({ input: { faq, unterveranstaltungId } }) => { | ||
| const [maxCategoryOrder, maxFaqOrder] = await Promise.all([ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ich habe ein Reordering schon für Custom Fields gebaut, da kannst du dir das meiste abschauen. Sollte einheitlich sein.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, ich seh, dass dort eine weitere Tabelle hinter "Reihenfolge ändern" steckt, wo man die via buttons nach oben und unten bewegen kann. Man könnte überlegen das Drag-n-Drop feature via ein "Reihenfolge ändern" button/toggle ein/ausschalten. |
||
| prisma.faqCategory.aggregate({ | ||
| where: { unterveranstaltungId }, | ||
| _max: { sortOrder: true }, | ||
| }), | ||
| prisma.faq.aggregate({ | ||
| where: { category: { unterveranstaltungId } }, | ||
| _max: { sortOrder: true }, | ||
| }), | ||
| ]) | ||
|
|
||
| await prisma.faq.create({ | ||
| data: { | ||
| question: faq.question, | ||
| answer: faq.answer, | ||
| sortOrder: (maxFaqOrder._max.sortOrder ?? -1) + 1, | ||
| unterveranstaltung: { | ||
| connect: { | ||
| id: unterveranstaltungId, | ||
|
|
@@ -26,6 +38,7 @@ export const faqCreateProcedure = defineProtectedMutateProcedure({ | |
| create: { | ||
| name: faq.category, | ||
| unterveranstaltungId, | ||
| sortOrder: (maxCategoryOrder._max.sortOrder ?? -1) + 1, | ||
| }, | ||
| where: { | ||
| name_unterveranstaltungId: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import z from 'zod' | ||
|
|
||
| import prisma from '../../prisma.js' | ||
| import { defineProtectedMutateProcedure } from '../../types/defineProcedure.js' | ||
|
|
||
| export const faqReorderProcedure = defineProtectedMutateProcedure({ | ||
| key: 'reorder', | ||
| roleIds: ['ADMIN', 'GLIEDERUNG_ADMIN'], | ||
| inputSchema: z.strictObject({ | ||
| faqOrder: z.array( | ||
| z.strictObject({ | ||
| id: z.string().uuid(), | ||
| sortOrder: z.number().int().min(0), | ||
| categoryId: z.string().uuid(), | ||
| }) | ||
| ), | ||
| categoryOrder: z.array( | ||
| z.strictObject({ | ||
| id: z.string().uuid(), | ||
| sortOrder: z.number().int().min(0), | ||
| }) | ||
| ), | ||
| }), | ||
| handler: async ({ input: { faqOrder, categoryOrder } }) => { | ||
| await prisma.$transaction([ | ||
| ...faqOrder.map(({ id, sortOrder, categoryId }) => | ||
| prisma.faq.update({ | ||
| where: { id }, | ||
| data: { sortOrder, categoryId }, | ||
| }) | ||
| ), | ||
| ...categoryOrder.map(({ id, sortOrder }) => | ||
| prisma.faqCategory.update({ | ||
| where: { id }, | ||
| data: { sortOrder }, | ||
| }) | ||
| ), | ||
| ]) | ||
|
supermomme marked this conversation as resolved.
Outdated
|
||
| }, | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.