diff --git a/apps/studio/prisma/generated/generatedTypes.ts b/apps/studio/prisma/generated/generatedTypes.ts index f22c5a2048..0542052e17 100644 --- a/apps/studio/prisma/generated/generatedTypes.ts +++ b/apps/studio/prisma/generated/generatedTypes.ts @@ -15,24 +15,12 @@ export type Footer = { id: string name: string siteId: string - contactUsLink: string | null - feedbackFormLink: string | null - privacyStatementLink: string | null - termsOfUseLink: string | null + content: unknown } export type Navbar = { id: string - name: string - url: string - description: string siteId: string -} -export type NavbarItems = { - id: string - name: string - url: string - description: string - navbarId: string + content: unknown } export type Permission = { id: string @@ -73,7 +61,6 @@ export type DB = { Blob: Blob Footer: Footer Navbar: Navbar - NavbarItems: NavbarItems Permission: Permission Resource: Resource Site: Site diff --git a/apps/studio/prisma/migrations/20240624071353_update_to_blob/migration.sql b/apps/studio/prisma/migrations/20240624071353_update_to_blob/migration.sql new file mode 100644 index 0000000000..a7c56be9d2 --- /dev/null +++ b/apps/studio/prisma/migrations/20240624071353_update_to_blob/migration.sql @@ -0,0 +1,33 @@ +/* + Warnings: + + - You are about to drop the column `contactUsLink` on the `Footer` table. All the data in the column will be lost. + - You are about to drop the column `feedbackFormLink` on the `Footer` table. All the data in the column will be lost. + - You are about to drop the column `privacyStatementLink` on the `Footer` table. All the data in the column will be lost. + - You are about to drop the column `termsOfUseLink` on the `Footer` table. All the data in the column will be lost. + - You are about to drop the column `description` on the `Navbar` table. All the data in the column will be lost. + - You are about to drop the column `name` on the `Navbar` table. All the data in the column will be lost. + - You are about to drop the column `url` on the `Navbar` table. All the data in the column will be lost. + - You are about to drop the `NavbarItems` table. If the table is not empty, all the data it contains will be lost. + - Added the required column `content` to the `Footer` table without a default value. This is not possible if the table is not empty. + - Added the required column `content` to the `Navbar` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropForeignKey +ALTER TABLE "NavbarItems" DROP CONSTRAINT "NavbarItems_navbarId_fkey"; + +-- AlterTable +ALTER TABLE "Footer" DROP COLUMN "contactUsLink", +DROP COLUMN "feedbackFormLink", +DROP COLUMN "privacyStatementLink", +DROP COLUMN "termsOfUseLink", +ADD COLUMN "content" JSONB NOT NULL; + +-- AlterTable +ALTER TABLE "Navbar" DROP COLUMN "description", +DROP COLUMN "name", +DROP COLUMN "url", +ADD COLUMN "content" JSONB NOT NULL; + +-- DropTable +DROP TABLE "NavbarItems"; diff --git a/apps/studio/prisma/schema.prisma b/apps/studio/prisma/schema.prisma index 518a5d2889..e76d9106af 100644 --- a/apps/studio/prisma/schema.prisma +++ b/apps/studio/prisma/schema.prisma @@ -78,33 +78,18 @@ model Site { } model Navbar { - id String @id @default(cuid()) - name String - url String - description String - siteId String @unique - site Site @relation(fields: [siteId], references: [id]) - items NavbarItems[] -} - -model NavbarItems { - id String @id @default(cuid()) - name String - url String - description String - navbar Navbar @relation(fields: [navbarId], references: [id]) - navbarId String + id String @id @default(cuid()) + siteId String @unique + site Site @relation(fields: [siteId], references: [id]) + content Json } model Footer { - id String @id @default(cuid()) - name String - siteId String @unique - site Site @relation(fields: [siteId], references: [id]) - contactUsLink String? - feedbackFormLink String? - privacyStatementLink String? - termsOfUseLink String? + id String @id @default(cuid()) + name String + siteId String @unique + site Site @relation(fields: [siteId], references: [id]) + content Json } model Blob { diff --git a/apps/studio/src/server/modules/resource/resource.service.ts b/apps/studio/src/server/modules/resource/resource.service.ts index e54047b289..6dce68de39 100644 --- a/apps/studio/src/server/modules/resource/resource.service.ts +++ b/apps/studio/src/server/modules/resource/resource.service.ts @@ -1,4 +1,5 @@ import { db } from '../database' +import { type Footer, type Navbar } from './resource.types' export const getPages = () => { return ( @@ -39,25 +40,24 @@ export const getPageById = (id: string) => { } // TODO: should be selecting from new table -export const getNavBar = (siteId: string) => { - return ( - db - .selectFrom('Navbar') - .where('siteId', '=', siteId) - .innerJoin('NavbarItems', 'id', 'NavbarItems.navbarId') - .selectAll() - // NOTE: Throwing here is acceptable because each site should have a navbar - .executeTakeFirstOrThrow() - ) +export const getNavBar = async (siteId: string) => { + const { content, ...rest } = await db + .selectFrom('Navbar') + .where('siteId', '=', siteId) + .selectAll() + // NOTE: Throwing here is acceptable because each site should have a navbar + .executeTakeFirstOrThrow() + + return { ...rest, content: content as Navbar } } -export const getFooter = (siteId: string) => { - return ( - db - .selectFrom('Footer') - .where('siteId', '=', siteId) - .selectAll() - // NOTE: Throwing here is acceptable because each site should have a footer - .executeTakeFirstOrThrow() - ) +export const getFooter = async (siteId: string) => { + const { content, ...rest } = await db + .selectFrom('Footer') + .where('siteId', '=', siteId) + .selectAll() + // NOTE: Throwing here is acceptable because each site should have a footer + .executeTakeFirstOrThrow() + + return { ...rest, content: content as Footer } } diff --git a/apps/studio/src/server/modules/resource/resource.types.ts b/apps/studio/src/server/modules/resource/resource.types.ts new file mode 100644 index 0000000000..0a828a01df --- /dev/null +++ b/apps/studio/src/server/modules/resource/resource.types.ts @@ -0,0 +1,17 @@ +export interface NavbarItem { + name: string + url: string + description: string +} + +export interface Navbar extends NavbarItem { + items: NavbarItem[] +} + +export interface Footer { + name: string + contactUsLink?: string + feedbackFormLink?: string + privacyStatementLink?: string + termsOfUseLink?: string +}