From 229e4b316da097a507cc80bc26fd7f50cf51938b Mon Sep 17 00:00:00 2001
From: Yunus <19399214+yunusefendi52@users.noreply.github.com>
Date: Fri, 5 Apr 2024 00:14:00 +0700
Subject: [PATCH] Add groups
---
components/Groups.vue | 60 +++++++++++++++++++
pages/orgs/[orgName]/apps/[appId].vue | 20 ++-----
.../migrations/20240404165653_/migration.sql | 26 ++++++++
.../migrations/20240404171110_/migration.sql | 8 +++
prisma/schema.prisma | 28 ++++++++-
server/api/groups/list-groups.get.ts | 22 +++++++
server/api/groups/new-group.post.ts | 28 +++++++++
7 files changed, 174 insertions(+), 18 deletions(-)
create mode 100644 components/Groups.vue
create mode 100644 prisma/migrations/20240404165653_/migration.sql
create mode 100644 prisma/migrations/20240404171110_/migration.sql
create mode 100644 server/api/groups/list-groups.get.ts
create mode 100644 server/api/groups/new-group.post.ts
diff --git a/components/Groups.vue b/components/Groups.vue
new file mode 100644
index 0000000..03416b2
--- /dev/null
+++ b/components/Groups.vue
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pages/orgs/[orgName]/apps/[appId].vue b/pages/orgs/[orgName]/apps/[appId].vue
index fe1ad43..a24c557 100644
--- a/pages/orgs/[orgName]/apps/[appId].vue
+++ b/pages/orgs/[orgName]/apps/[appId].vue
@@ -10,21 +10,11 @@
}">
-
+
+
+
diff --git a/prisma/migrations/20240404165653_/migration.sql b/prisma/migrations/20240404165653_/migration.sql
new file mode 100644
index 0000000..90a2b79
--- /dev/null
+++ b/prisma/migrations/20240404165653_/migration.sql
@@ -0,0 +1,26 @@
+-- CreateTable
+CREATE TABLE "ArtifactsGroups" (
+ "id" SERIAL NOT NULL,
+ "name" TEXT NOT NULL,
+ "appsId" INTEGER NOT NULL,
+
+ CONSTRAINT "ArtifactsGroups_pkey" PRIMARY KEY ("id")
+);
+
+-- CreateTable
+CREATE TABLE "ArtifactsGroupsManager" (
+ "artifactsId" INTEGER NOT NULL,
+ "artifactsGroupsId" INTEGER NOT NULL
+);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "ArtifactsGroupsManager_artifactsId_artifactsGroupsId_key" ON "ArtifactsGroupsManager"("artifactsId", "artifactsGroupsId");
+
+-- AddForeignKey
+ALTER TABLE "ArtifactsGroups" ADD CONSTRAINT "ArtifactsGroups_appsId_fkey" FOREIGN KEY ("appsId") REFERENCES "Apps"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ArtifactsGroupsManager" ADD CONSTRAINT "ArtifactsGroupsManager_artifactsId_fkey" FOREIGN KEY ("artifactsId") REFERENCES "Artifacts"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+
+-- AddForeignKey
+ALTER TABLE "ArtifactsGroupsManager" ADD CONSTRAINT "ArtifactsGroupsManager_artifactsGroupsId_fkey" FOREIGN KEY ("artifactsGroupsId") REFERENCES "ArtifactsGroups"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
diff --git a/prisma/migrations/20240404171110_/migration.sql b/prisma/migrations/20240404171110_/migration.sql
new file mode 100644
index 0000000..efbb0f6
--- /dev/null
+++ b/prisma/migrations/20240404171110_/migration.sql
@@ -0,0 +1,8 @@
+/*
+ Warnings:
+
+ - A unique constraint covering the columns `[appsId,name]` on the table `ArtifactsGroups` will be added. If there are existing duplicate values, this will fail.
+
+*/
+-- CreateIndex
+CREATE UNIQUE INDEX "ArtifactsGroups_appsId_name_key" ON "ArtifactsGroups"("appsId", "name");
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 3e66ac9..97ab93b 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -44,9 +44,10 @@ model Apps {
displayName String
osType Int
- Organization Organizations @relation(fields: [organizationsId], references: [id])
+ Organization Organizations @relation(fields: [organizationsId], references: [id])
organizationsId Int
Artifacts Artifacts[]
+ ArtifactsGroups ArtifactsGroups[]
@@unique([organizationsId, name])
}
@@ -60,6 +61,27 @@ model Artifacts {
createdAt DateTime
updatedAt DateTime
- apps Apps @relation(fields: [appsId], references: [id])
- appsId Int
+ apps Apps @relation(fields: [appsId], references: [id])
+ appsId Int
+ ArtifactsGroupsManager ArtifactsGroupsManager[]
+}
+
+model ArtifactsGroups {
+ id Int @id @default(autoincrement())
+ name String
+
+ apps Apps @relation(fields: [appsId], references: [id])
+ appsId Int
+ ArtifactsGroupsManager ArtifactsGroupsManager[]
+
+ @@unique([appsId, name])
+}
+
+model ArtifactsGroupsManager {
+ artifacts Artifacts @relation(fields: [artifactsId], references: [id])
+ artifactsGroup ArtifactsGroups @relation(fields: [artifactsGroupsId], references: [id])
+ artifactsId Int
+ artifactsGroupsId Int
+
+ @@unique([artifactsId, artifactsGroupsId])
}
diff --git a/server/api/groups/list-groups.get.ts b/server/api/groups/list-groups.get.ts
new file mode 100644
index 0000000..22eca4a
--- /dev/null
+++ b/server/api/groups/list-groups.get.ts
@@ -0,0 +1,22 @@
+export default defineEventHandler(async (event) => {
+ const { appName, orgName } = getQuery(event)
+ const groups = await event.context.prisma.artifactsGroups.findMany({
+ // include: {
+ // apps: true,
+ // },
+ where: {
+ apps: {
+ name: appName?.toString(),
+ Organization: {
+ name: orgName?.toString(),
+ OrganizationsPeople: {
+ every: {
+ userId: event.context.auth.userId,
+ },
+ },
+ },
+ }
+ }
+ })
+ return groups
+})
diff --git a/server/api/groups/new-group.post.ts b/server/api/groups/new-group.post.ts
new file mode 100644
index 0000000..20bd648
--- /dev/null
+++ b/server/api/groups/new-group.post.ts
@@ -0,0 +1,28 @@
+export default defineEventHandler(async (event) => {
+ const { appName, orgName, groupName } = await readBody(event)
+ const app = await event.context.prisma.apps.findFirstOrThrow({
+ include: {
+ Organization: true,
+ },
+ where: {
+ name: appName,
+ Organization: {
+ name: orgName,
+ OrganizationsPeople: {
+ every: {
+ userId: event.context.auth.userId,
+ },
+ },
+ },
+ },
+ })
+ await event.context.prisma.artifactsGroups.create({
+ data: {
+ name: normalizeName(groupName),
+ appsId: app.id,
+ }
+ })
+ return {
+ ok: true,
+ }
+})