diff --git a/prisma/db.sqlite b/prisma/db.sqlite new file mode 100644 index 0000000..9ed7538 Binary files /dev/null and b/prisma/db.sqlite differ diff --git a/prisma/db.sqlite-journal b/prisma/db.sqlite-journal new file mode 100644 index 0000000..6842cb0 Binary files /dev/null and b/prisma/db.sqlite-journal differ diff --git a/prisma/migrations/20230925103252_init/migration.sql b/prisma/migrations/20230925103252_init/migration.sql deleted file mode 100644 index 29f7487..0000000 --- a/prisma/migrations/20230925103252_init/migration.sql +++ /dev/null @@ -1,24 +0,0 @@ --- CreateTable -CREATE TABLE `User` ( - `id` VARCHAR(191) NOT NULL, - `username` VARCHAR(191) NOT NULL, - `email` VARCHAR(191) NOT NULL, - `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), - `updatedAt` DATETIME(3) NOT NULL, - `deletedAt` DATETIME(3) NULL, - - UNIQUE INDEX `User_username_key`(`username`), - UNIQUE INDEX `User_email_key`(`email`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateTable -CREATE TABLE `Password` ( - `hash` VARCHAR(191) NOT NULL, - `userId` VARCHAR(191) NOT NULL, - - UNIQUE INDEX `Password_userId_key`(`userId`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- AddForeignKey -ALTER TABLE `Password` ADD CONSTRAINT `Password_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20231001005812_project/migration.sql b/prisma/migrations/20231001005812_project/migration.sql deleted file mode 100644 index 0ce3bd5..0000000 --- a/prisma/migrations/20231001005812_project/migration.sql +++ /dev/null @@ -1,32 +0,0 @@ --- CreateTable -CREATE TABLE `Project` ( - `id` VARCHAR(191) NOT NULL, - `name` VARCHAR(100) NOT NULL, - `description` VARCHAR(255) NOT NULL, - `visibility` ENUM('PUBLIC', 'PRIVATE') NOT NULL DEFAULT 'PRIVATE', - `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), - `updatedAt` DATETIME(3) NOT NULL, - `deletedAt` DATETIME(3) NULL, - `creatorId` VARCHAR(191) NOT NULL, - - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateTable -CREATE TABLE `ProjectMember` ( - `id` VARCHAR(191) NOT NULL, - `userId` VARCHAR(191) NOT NULL, - `projectId` VARCHAR(191) NOT NULL, - `role` ENUM('Owner', 'Maintainer', 'Developer', 'Viewer') NOT NULL, - - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- AddForeignKey -ALTER TABLE `Project` ADD CONSTRAINT `Project_creatorId_fkey` FOREIGN KEY (`creatorId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `ProjectMember` ADD CONSTRAINT `ProjectMember_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `ProjectMember` ADD CONSTRAINT `ProjectMember_projectId_fkey` FOREIGN KEY (`projectId`) REFERENCES `Project`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20231004084305_project_relation/migration.sql b/prisma/migrations/20231004084305_project_relation/migration.sql deleted file mode 100644 index 8109884..0000000 --- a/prisma/migrations/20231004084305_project_relation/migration.sql +++ /dev/null @@ -1,22 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `deletedAt` on the `Project` table. All the data in the column will be lost. - - You are about to alter the column `name` on the `Project` table. The data in that column could be lost. The data in that column will be cast from `VarChar(100)` to `VarChar(50)`. - -*/ --- DropForeignKey -ALTER TABLE `ProjectMember` DROP FOREIGN KEY `ProjectMember_projectId_fkey`; - --- DropForeignKey -ALTER TABLE `ProjectMember` DROP FOREIGN KEY `ProjectMember_userId_fkey`; - --- AlterTable -ALTER TABLE `Project` DROP COLUMN `deletedAt`, - MODIFY `name` VARCHAR(50) NOT NULL; - --- AddForeignKey -ALTER TABLE `ProjectMember` ADD CONSTRAINT `ProjectMember_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `ProjectMember` ADD CONSTRAINT `ProjectMember_projectId_fkey` FOREIGN KEY (`projectId`) REFERENCES `Project`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20231009054458_api/migration.sql b/prisma/migrations/20231009054458_api/migration.sql deleted file mode 100644 index 91a9158..0000000 --- a/prisma/migrations/20231009054458_api/migration.sql +++ /dev/null @@ -1,42 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `creatorId` on the `Project` table. All the data in the column will be lost. - - A unique constraint covering the columns `[userId,projectId]` on the table `ProjectMember` will be added. If there are existing duplicate values, this will fail. - -*/ --- DropForeignKey -ALTER TABLE `Project` DROP FOREIGN KEY `Project_creatorId_fkey`; - --- AlterTable -ALTER TABLE `Project` DROP COLUMN `creatorId`; - --- CreateTable -CREATE TABLE `Api` ( - `id` VARCHAR(191) NOT NULL, - `name` VARCHAR(100) NOT NULL DEFAULT '', - `description` VARCHAR(255) NOT NULL DEFAULT '', - `endpoint` VARCHAR(255) NOT NULL, - `method` ENUM('GET', 'PUT', 'DELETE', 'POST', 'HEAD', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH', 'CUSTOM') NOT NULL, - `params` JSON NOT NULL, - `body` JSON NOT NULL, - `headers` JSON NOT NULL, - `authorization` JSON NOT NULL, - `preRequestScript` VARCHAR(191) NOT NULL, - `postResponseScript` VARCHAR(191) NOT NULL, - `tags` JSON NOT NULL, - `versions` JSON NOT NULL, - `order` INTEGER NOT NULL, - `status` ENUM('DRAFT', 'PUBLISHED') NOT NULL DEFAULT 'DRAFT', - `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), - `updatedAt` DATETIME(3) NOT NULL, - `projectId` VARCHAR(191) NOT NULL, - - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateIndex -CREATE UNIQUE INDEX `ProjectMember_userId_projectId_key` ON `ProjectMember`(`userId`, `projectId`); - --- AddForeignKey -ALTER TABLE `Api` ADD CONSTRAINT `Api_projectId_fkey` FOREIGN KEY (`projectId`) REFERENCES `Project`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20231012093339_user_avatar/migration.sql b/prisma/migrations/20231012093339_user_avatar/migration.sql deleted file mode 100644 index 771e835..0000000 --- a/prisma/migrations/20231012093339_user_avatar/migration.sql +++ /dev/null @@ -1,12 +0,0 @@ -/* - Warnings: - - - Added the required column `avatar` to the `User` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE `Api` MODIFY `preRequestScript` VARCHAR(191) NOT NULL DEFAULT '', - MODIFY `postResponseScript` VARCHAR(191) NOT NULL DEFAULT ''; - --- AlterTable -ALTER TABLE `User` ADD COLUMN `avatar` VARCHAR(191) NOT NULL; diff --git a/prisma/migrations/20231013035744_team/migration.sql b/prisma/migrations/20231013035744_team/migration.sql deleted file mode 100644 index 3bbdbbf..0000000 --- a/prisma/migrations/20231013035744_team/migration.sql +++ /dev/null @@ -1,27 +0,0 @@ --- CreateTable -CREATE TABLE `Team` ( - `id` VARCHAR(191) NOT NULL, - `name` VARCHAR(100) NOT NULL DEFAULT '', - `description` VARCHAR(255) NOT NULL DEFAULT '', - `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), - `updatedAt` DATETIME(3) NOT NULL, - - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateTable -CREATE TABLE `TeamMember` ( - `id` VARCHAR(191) NOT NULL, - `role` ENUM('Owner', 'Maintainer', 'Developer', 'Viewer') NOT NULL, - `userId` VARCHAR(191) NOT NULL, - `teamId` VARCHAR(191) NOT NULL, - - UNIQUE INDEX `TeamMember_userId_teamId_key`(`userId`, `teamId`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- AddForeignKey -ALTER TABLE `TeamMember` ADD CONSTRAINT `TeamMember_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `TeamMember` ADD CONSTRAINT `TeamMember_teamId_fkey` FOREIGN KEY (`teamId`) REFERENCES `Team`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20231013051930_team_relation/migration.sql b/prisma/migrations/20231013051930_team_relation/migration.sql deleted file mode 100644 index 3216655..0000000 --- a/prisma/migrations/20231013051930_team_relation/migration.sql +++ /dev/null @@ -1,11 +0,0 @@ -/* - Warnings: - - - Added the required column `teamId` to the `Project` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE `Project` ADD COLUMN `teamId` VARCHAR(191) NOT NULL; - --- AddForeignKey -ALTER TABLE `Project` ADD CONSTRAINT `Project_teamId_fkey` FOREIGN KEY (`teamId`) REFERENCES `Team`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/20231016164156_collection/migration.sql b/prisma/migrations/20231016164156_collection/migration.sql deleted file mode 100644 index 7092852..0000000 --- a/prisma/migrations/20231016164156_collection/migration.sql +++ /dev/null @@ -1,30 +0,0 @@ --- DropForeignKey -ALTER TABLE `Project` DROP FOREIGN KEY `Project_teamId_fkey`; - --- AlterTable -ALTER TABLE `Api` ADD COLUMN `collectionId` VARCHAR(191) NULL; - --- CreateTable -CREATE TABLE `Collection` ( - `id` VARCHAR(191) NOT NULL, - `pid` VARCHAR(191) NULL, - `title` VARCHAR(191) NOT NULL, - `order` INTEGER NOT NULL, - `createdAt` TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), - `updatedAt` TIMESTAMP(3) NOT NULL, - `projectId` VARCHAR(191) NOT NULL, - - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- AddForeignKey -ALTER TABLE `Project` ADD CONSTRAINT `Project_teamId_fkey` FOREIGN KEY (`teamId`) REFERENCES `Team`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `Collection` ADD CONSTRAINT `Collection_pid_fkey` FOREIGN KEY (`pid`) REFERENCES `Collection`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `Collection` ADD CONSTRAINT `Collection_projectId_fkey` FOREIGN KEY (`projectId`) REFERENCES `Project`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `Api` ADD CONSTRAINT `Api_collectionId_fkey` FOREIGN KEY (`collectionId`) REFERENCES `Collection`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/20231017041831_rename_collection_title_name/migration.sql b/prisma/migrations/20231017041831_rename_collection_title_name/migration.sql deleted file mode 100644 index 492cb4b..0000000 --- a/prisma/migrations/20231017041831_rename_collection_title_name/migration.sql +++ /dev/null @@ -1,10 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `title` on the `Collection` table. All the data in the column will be lost. - - Added the required column `name` to the `Collection` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE `Collection` DROP COLUMN `title`, - ADD COLUMN `name` VARCHAR(191) NOT NULL; diff --git a/prisma/migrations/20231113032008_team_invite/migration.sql b/prisma/migrations/20231113032008_team_invite/migration.sql deleted file mode 100644 index d5b567f..0000000 --- a/prisma/migrations/20231113032008_team_invite/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE `TeamMember` ADD COLUMN `status` ENUM('Pending', 'Success', 'Reject') NOT NULL DEFAULT 'Success'; diff --git a/prisma/migrations/20231122082949_visited_history/migration.sql b/prisma/migrations/20231122082949_visited_history/migration.sql deleted file mode 100644 index 8679529..0000000 --- a/prisma/migrations/20231122082949_visited_history/migration.sql +++ /dev/null @@ -1,14 +0,0 @@ --- CreateTable -CREATE TABLE `VisitedHisotry` ( - `id` VARCHAR(191) NOT NULL, - `projectId` VARCHAR(191) NOT NULL, - `userId` VARCHAR(191) NOT NULL, - - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- AddForeignKey -ALTER TABLE `VisitedHisotry` ADD CONSTRAINT `VisitedHisotry_projectId_fkey` FOREIGN KEY (`projectId`) REFERENCES `Project`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `VisitedHisotry` ADD CONSTRAINT `VisitedHisotry_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20231122091108_visited_proeject_date/migration.sql b/prisma/migrations/20231122091108_visited_proeject_date/migration.sql deleted file mode 100644 index d227380..0000000 --- a/prisma/migrations/20231122091108_visited_proeject_date/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE `VisitedHisotry` ADD COLUMN `date` VARCHAR(191) NOT NULL DEFAULT ''; diff --git a/prisma/migrations/20240204053459_init/migration.sql b/prisma/migrations/20240204053459_init/migration.sql new file mode 100644 index 0000000..57a7334 --- /dev/null +++ b/prisma/migrations/20240204053459_init/migration.sql @@ -0,0 +1,122 @@ +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL PRIMARY KEY, + "username" TEXT NOT NULL, + "email" TEXT NOT NULL, + "avatar" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "deletedAt" DATETIME +); + +-- CreateTable +CREATE TABLE "Password" ( + "hash" TEXT NOT NULL, + "userId" TEXT NOT NULL, + CONSTRAINT "Password_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "Team" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL DEFAULT '', + "description" TEXT NOT NULL DEFAULT '', + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); + +-- CreateTable +CREATE TABLE "TeamMember" ( + "id" TEXT NOT NULL PRIMARY KEY, + "role" TEXT NOT NULL DEFAULT 'MEMBER', + "userId" TEXT NOT NULL, + "teamId" TEXT NOT NULL, + "status" TEXT NOT NULL DEFAULT 'Success', + CONSTRAINT "TeamMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "TeamMember_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "Project" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL, + "description" TEXT NOT NULL, + "visibility" TEXT NOT NULL DEFAULT 'PRIVATE', + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "teamId" TEXT NOT NULL, + CONSTRAINT "Project_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "ProjectMember" ( + "id" TEXT NOT NULL PRIMARY KEY, + "role" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "projectId" TEXT NOT NULL, + CONSTRAINT "ProjectMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "ProjectMember_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "Collection" ( + "id" TEXT NOT NULL PRIMARY KEY, + "pid" TEXT, + "name" TEXT NOT NULL, + "order" INTEGER NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "projectId" TEXT NOT NULL, + CONSTRAINT "Collection_pid_fkey" FOREIGN KEY ("pid") REFERENCES "Collection" ("id") ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT "Collection_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "Api" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL DEFAULT '', + "description" TEXT NOT NULL DEFAULT '', + "endpoint" TEXT NOT NULL, + "method" TEXT NOT NULL, + "params" TEXT NOT NULL, + "body" TEXT NOT NULL, + "headers" TEXT NOT NULL, + "authorization" TEXT NOT NULL, + "preRequestScript" TEXT NOT NULL DEFAULT '', + "postResponseScript" TEXT NOT NULL DEFAULT '', + "tags" TEXT NOT NULL, + "versions" TEXT NOT NULL, + "order" INTEGER NOT NULL, + "status" TEXT NOT NULL DEFAULT 'DRAFT', + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "projectId" TEXT NOT NULL, + "collectionId" TEXT, + CONSTRAINT "Api_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "Api_collectionId_fkey" FOREIGN KEY ("collectionId") REFERENCES "Collection" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "VisitedHistory" ( + "id" TEXT NOT NULL PRIMARY KEY, + "projectId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "date" TEXT NOT NULL DEFAULT '', + CONSTRAINT "VisitedHistory_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "VisitedHistory_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "Password_userId_key" ON "Password"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "TeamMember_userId_teamId_key" ON "TeamMember"("userId", "teamId"); + +-- CreateIndex +CREATE UNIQUE INDEX "ProjectMember_userId_projectId_key" ON "ProjectMember"("userId", "projectId"); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml index e5a788a..e5e5c47 100644 --- a/prisma/migrations/migration_lock.toml +++ b/prisma/migrations/migration_lock.toml @@ -1,3 +1,3 @@ # Please do not edit this file manually # It should be added in your version-control system (i.e. Git) -provider = "mysql" \ No newline at end of file +provider = "sqlite" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 89109e2..51c6953 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -6,7 +6,7 @@ generator client { } datasource db { - provider = "mysql" + provider = "sqlite" url = env("DATABASE_URL") } @@ -21,7 +21,7 @@ model User { password Password? ProjectMember ProjectMember[] TeamMember TeamMember[] - VisitedHisotry VisitedHisotry[] + VisitedHistory VisitedHistory[] ProjectCollection ProjectCollection[] } @@ -33,8 +33,8 @@ model Password { model Team { id String @id @default(cuid()) - name String @default("") @db.VarChar(100) - description String @default("") @db.VarChar(255) + name String @default("") + description String @default("") createdAt DateTime @default(now()) updatedAt DateTime @updatedAt members TeamMember[] @@ -42,22 +42,22 @@ model Team { } model TeamMember { - id String @id @default(cuid()) - role Role + id String @id @default(cuid()) + role String @default("MEMBER") userId String - user User @relation(fields: [userId], references: [id], onDelete: Cascade) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) teamId String - team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) - status InviteStatus @default(Success) + team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) + status String @default("Success") @@unique([userId, teamId]) } model Project { id String @id @default(cuid()) - name String @db.VarChar(50) - description String @db.VarChar(255) - visibility ProjectVisibility @default(PRIVATE) + name String + description String + visibility String @default("PRIVATE") createdAt DateTime @default(now()) updatedAt DateTime @updatedAt members ProjectMember[] @@ -65,15 +65,10 @@ model Project { teamId String Team Team @relation(fields: [teamId], references: [id], onDelete: Cascade) collections Collection[] - VisitedHisotry VisitedHisotry[] + VisitedHistory VisitedHistory[] ProjectCollection ProjectCollection[] } -enum ProjectVisibility { - PUBLIC - PRIVATE -} - model ProjectCollection { id String @id @default(cuid()) userId String @@ -86,7 +81,7 @@ model ProjectCollection { model ProjectMember { id String @id @default(cuid()) - role Role + role String userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) projectId String @@ -95,26 +90,13 @@ model ProjectMember { @@unique([userId, projectId]) } -enum Role { - Owner - Maintainer - Developer - Viewer -} - -enum InviteStatus { - Pending - Success - Reject -} - model Collection { id String @id @default(cuid()) pid String? name String order Int - createdAt DateTime @default(now()) @db.Timestamp(3) - updatedAt DateTime @updatedAt @db.Timestamp(3) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt parent Collection? @relation("CollectionChildParent", fields: [pid], references: [id]) children Collection[] @relation("CollectionChildParent") projectId String @@ -124,20 +106,20 @@ model Collection { model Api { id String @id @default(cuid()) - name String @default("") @db.VarChar(100) - description String @default("") @db.VarChar(255) - endpoint String @db.VarChar(255) - method ApiMethod - params Json - body Json - headers Json - authorization Json + name String @default("") + description String @default("") + endpoint String + method String + params String + body String + headers String + authorization String preRequestScript String @default("") postResponseScript String @default("") - tags Json - versions Json + tags String + versions String order Int - status ApiStatus @default(DRAFT) + status String @default("DRAFT") createdAt DateTime @default(now()) updatedAt DateTime @updatedAt projectId String @@ -146,26 +128,7 @@ model Api { collection Collection? @relation(fields: [collectionId], references: [id]) } -// refs: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods -enum ApiMethod { - GET - PUT - DELETE - POST - HEAD - CONNECT - OPTIONS - TRACE - PATCH - CUSTOM -} - -enum ApiStatus { - DRAFT - PUBLISHED -} - -model VisitedHisotry { +model VisitedHistory { id String @id @default(cuid()) projectId String project Project @relation(fields: [projectId], references: [id], onDelete: Cascade) diff --git a/server/trpc/routers/api.ts b/server/trpc/routers/api.ts index 8583ffd..9e94d7d 100644 --- a/server/trpc/routers/api.ts +++ b/server/trpc/routers/api.ts @@ -1,7 +1,6 @@ -import { $Enums } from '@prisma/client' import { z } from 'zod' import { protectedProcedure, router } from '../trpc' -import type { ApiParams } from '@/types' +import { ApiMethod, type ApiParams, ApiStatus, Role } from '@/types' export const apiRouter = router({ // API, TODO: permission @@ -31,7 +30,7 @@ export const apiRouter = router({ name: z.string().min(3).max(50).optional(), description: z.string().min(3).max(255).optional(), endpoint: z.string(), - method: z.nativeEnum($Enums.ApiMethod), + method: z.nativeEnum(ApiMethod), params: z.array(z.object({ key: z.string(), type: z.enum(['string', 'number']), @@ -48,7 +47,7 @@ export const apiRouter = router({ tags: z.array(z.string()), versions: z.array(z.string()), order: z.number(), - status: z.nativeEnum($Enums.ApiStatus).optional(), + status: z.nativeEnum(ApiStatus).optional(), projectId: z.string(), }), ).mutation(async (event) => { @@ -64,8 +63,8 @@ export const apiRouter = router({ if (!projectMember) throw new Error('Project not found') if (![ - $Enums.Role.Owner, - $Enums.Role.Maintainer, + Role.Owner, + Role.Maintainer, ].includes(projectMember.role)) throw new Error('Permission denied') @@ -82,7 +81,7 @@ export const apiRouter = router({ name: z.string().min(3).max(50).optional(), description: z.string().min(3).max(255).optional(), endpoint: z.string(), - method: z.nativeEnum($Enums.ApiMethod), + method: z.nativeEnum(ApiMethod), params: z.array(z.object({ key: z.string(), type: z.enum(['string', 'number']), @@ -99,7 +98,7 @@ export const apiRouter = router({ tags: z.array(z.string()), versions: z.array(z.string()), order: z.number(), - status: z.nativeEnum($Enums.ApiStatus).optional(), + status: z.nativeEnum(ApiStatus).optional(), projectId: z.string(), }), ).mutation(async (event) => { @@ -115,8 +114,8 @@ export const apiRouter = router({ if (!projectMember) throw new Error('Project not found') if (![ - $Enums.Role.Owner, - $Enums.Role.Maintainer, + Role.Owner, + Role.Maintainer, ].includes(projectMember.role)) throw new Error('Permission denied') diff --git a/server/trpc/routers/project.ts b/server/trpc/routers/project.ts index d77f9cd..1da6e68 100644 --- a/server/trpc/routers/project.ts +++ b/server/trpc/routers/project.ts @@ -1,6 +1,6 @@ -import { $Enums } from '@prisma/client' import { z } from 'zod' import { protectedProcedure, router } from '../trpc' +import { ProjectVisibility, Role } from '~/types' export const projectRouter = router({ userList: protectedProcedure @@ -90,7 +90,7 @@ export const projectRouter = router({ name: z.string().min(3).max(50), description: z.string().min(3).max(255), teamId: z.string(), - visibility: z.nativeEnum($Enums.ProjectVisibility), + visibility: z.nativeEnum(ProjectVisibility), }), ) .mutation(async (event) => { @@ -105,7 +105,7 @@ export const projectRouter = router({ members: { create: { userId: user.id, - role: $Enums.Role.Owner, + role: Role.Owner, }, }, }, @@ -131,14 +131,14 @@ export const projectRouter = router({ throw new Error('Project not found') // add or update visted history - const visitedRecord = await ctx.prisma.visitedHisotry.findFirst({ + const visitedRecord = await ctx.prisma.visitedHistory.findFirst({ where: { projectId: input.id, userId: user.id, }, }) if (visitedRecord) { - await ctx.prisma.visitedHisotry.update({ + await ctx.prisma.visitedHistory.update({ where: { id: visitedRecord.id, }, @@ -148,7 +148,7 @@ export const projectRouter = router({ }) } else { - await ctx.prisma.visitedHisotry.create({ + await ctx.prisma.visitedHistory.create({ data: { projectId: input.id, userId: user.id, @@ -165,7 +165,7 @@ export const projectRouter = router({ id: z.string(), name: z.string().min(3).max(50), description: z.string().min(3).max(255), - visibility: z.nativeEnum($Enums.ProjectVisibility), + visibility: z.nativeEnum(ProjectVisibility), }), ) .mutation(async (event) => { @@ -174,7 +174,7 @@ export const projectRouter = router({ const existed = await ctx.prisma.project.update({ where: { id: input.id, - members: { some: { userId: user.id, role: $Enums.Role.Owner } }, + members: { some: { userId: user.id, role: Role.Owner } }, }, data: { name: input.name, @@ -198,7 +198,7 @@ export const projectRouter = router({ const existed = await ctx.prisma.project.delete({ where: { id: input.id, - members: { some: { userId: user.id, role: $Enums.Role.Owner } }, + members: { some: { userId: user.id, role: Role.Owner } }, }, }) if (!existed) @@ -210,7 +210,7 @@ export const projectRouter = router({ .query(async (event) => { const { ctx } = event const user = ctx.session.data.user - const projects = await ctx.prisma.visitedHisotry.findMany({ + const visitedList = await ctx.prisma.visitedHistory.findMany({ where: { userId: user.id, }, diff --git a/server/trpc/routers/team.ts b/server/trpc/routers/team.ts index f58cc00..42a13d2 100644 --- a/server/trpc/routers/team.ts +++ b/server/trpc/routers/team.ts @@ -1,11 +1,10 @@ import process from 'node:process' -import type { Role } from '@prisma/client' -import { $Enums, InviteStatus } from '@prisma/client' import { z } from 'zod' import nodemailer from 'nodemailer' import { protectedProcedure, router } from '../trpc' import { useCompiler } from '#vue-email' import { generateUUID } from '~/server/utils/uuid' +import { InviteStatus, Role } from '~/types' export const teamRouter = router({ // Team, TODO: permission @@ -39,8 +38,8 @@ export const teamRouter = router({ members: { create: { userId: user.id, - role: $Enums.Role.Owner, - status: $Enums.InviteStatus.Success, + role: Role.Owner, + status: InviteStatus.Success, }, }, }, @@ -130,13 +129,13 @@ export const teamRouter = router({ userId, role: input.role as Role, teamId: input.teamId, - status: $Enums.InviteStatus.Pending, + status: InviteStatus.Pending, } }) // insert into team member record - const res = await ctx.prisma.teamMember.createMany({ - data, - }) + // const res = await ctx.prisma.teamMember.createMany({ + // data, + // }) // send email data.forEach(async (item) => { diff --git a/types.d.ts b/types.d.ts index a02b2da..f144549 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,4 +1,4 @@ -import type { $Enums, User } from '@prisma/client' +import type { User } from '@prisma/client' // RouteMeta` w/ custom properties, like `requiredAuth` declare module 'vue-router' { @@ -7,11 +7,38 @@ declare module 'vue-router' { } } -// Re Export `prisma` enums -export type ApiMethod = $Enums.ApiMethod -export type ApiStatus = $Enums.ApiStatus -export type ProjectVisibility = $Enums.ProjectVisibility -export type Role = $Enums.Role +// refs: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods +export enum ApiMethod { + GET = 'GET', + PUT = 'PUT', + DELETE = 'DELETE', + POST = 'POST', + HEAD = 'HEAD', + CONNECT = 'CONNECT', + OPTIONS = 'OPTIONS', + TRACE = 'TRACE', + PATCH = 'PATCH', + CUSTOM = 'CUSTOM', +} +export enum ApiStatus { + DRAFT = 'DRAFT', + PUBLISHED = 'PUBLISHED', +} +export enum ProjectVisibility { + PUBLIC = 'PUBLIC', + PRIVATE = 'PRIVATE', +} +export enum Role { + Owner = 'Owner', + Maintainer = 'Maintainer', + Developer = 'Developer', + Viewer = 'Viewer', +} +export enum InviteStatus { + Pending = 'Pending', + Success = 'Success', + Reject = 'Reject', +} export type SessionUser = Pick export interface Session {