diff --git a/prisma/migrations/20240630211113_removing_the_unused_next_js_auth_schema/migration.sql b/prisma/migrations/20240630211113_removing_the_unused_next_js_auth_schema/migration.sql new file mode 100644 index 0000000..ab6d55c --- /dev/null +++ b/prisma/migrations/20240630211113_removing_the_unused_next_js_auth_schema/migration.sql @@ -0,0 +1,33 @@ +/* + Warnings: + + - You are about to drop the `Account` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `Authenticator` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `Session` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `User` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `VerificationToken` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "Account" DROP CONSTRAINT "Account_userId_fkey"; + +-- DropForeignKey +ALTER TABLE "Authenticator" DROP CONSTRAINT "Authenticator_userId_fkey"; + +-- DropForeignKey +ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey"; + +-- DropTable +DROP TABLE "Account"; + +-- DropTable +DROP TABLE "Authenticator"; + +-- DropTable +DROP TABLE "Session"; + +-- DropTable +DROP TABLE "User"; + +-- DropTable +DROP TABLE "VerificationToken"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 523a6f5..7e54e05 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -139,73 +139,3 @@ model File { Assistant Assistant? @relation(fields: [assistantId], references: [id]) assistantId String? } - -// NextAuth.js schema -model User { - id String @id @default(cuid()) - name String? - email String @unique - emailVerified DateTime? - image String? - accounts Account[] - sessions Session[] - // Optional for WebAuthn support - Authenticator Authenticator[] - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} - -model Account { - userId String - type String - provider String - providerAccountId String - refresh_token String? - access_token String? - expires_at Int? - token_type String? - scope String? - id_token String? - session_state String? - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - - user User @relation(fields: [userId], references: [id], onDelete: Cascade) - - @@id([provider, providerAccountId]) -} - -model Session { - sessionToken String @unique - userId String - expires DateTime - user User @relation(fields: [userId], references: [id], onDelete: Cascade) - - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt -} - -model VerificationToken { - identifier String - token String - expires DateTime - - @@id([identifier, token]) -} - -// Optional for WebAuthn support -model Authenticator { - id String @id @default(cuid()) - credentialID String @unique - userId String - providerAccountId String - credentialPublicKey String - counter Int - credentialDeviceType String - credentialBackedUp Boolean - transports String? - - user User @relation(fields: [userId], references: [id], onDelete: Cascade) -} diff --git a/src/app/admin/dashboard/AssistantMetrics.tsx b/src/app/admin/dashboard/AssistantMetrics.tsx new file mode 100644 index 0000000..acd81a2 --- /dev/null +++ b/src/app/admin/dashboard/AssistantMetrics.tsx @@ -0,0 +1,63 @@ +import prisma from '@/app/api/utils/prisma'; +import { Card } from 'flowbite-react'; + +export default function AssistantMetrics() { + const getAssistantCount = async function() { + let total = await prisma.assistant.aggregate({ + _count: { + id: true + } + }) + + return total._count.id + } + + const getThreadCount = async function() { + let total = await prisma.thread.aggregate({ + _count: { + id: true + } + }) + + return total._count.id + } + + const getMessageCount = async function() { + let total = await prisma.message.aggregate({ + _count: { + id: true + } + }) + + return total._count.id + } + + return ( +
+ +
+ Assistants +
+

+ {getAssistantCount()} +

+
+ +
+ Threads +
+

+ {getThreadCount()} +

+
+ +
+ Messages +
+

+ {getMessageCount()} +

+
+
+ ) +} \ No newline at end of file diff --git a/src/app/admin/dashboard/UserMetrics.tsx b/src/app/admin/dashboard/UserMetrics.tsx new file mode 100644 index 0000000..8609874 --- /dev/null +++ b/src/app/admin/dashboard/UserMetrics.tsx @@ -0,0 +1,55 @@ +import prisma from '@/app/api/utils/prisma'; +import { Card } from 'flowbite-react'; + +export default function UserMetrics() { + const getUserCount = async function() { + let total = await prisma.organization.aggregate({ + where: { + ownerType: { + in: ['personal'], + }, + }, + _count: { + owner: true + } + }) + + return total._count.owner + } + + const getOrganizationCount = async function() { + let total = await prisma.organization.aggregate({ + where: { + ownerType: { + notIn: ['personal'], + }, + }, + _count: { + owner: true + } + }) + + return total._count.owner + } + + return ( +
+ +
+ Users +
+

+ {getUserCount()} +

+
+ +
+ Organizations +
+

+ {getOrganizationCount()} +

+
+
+ ) +} \ No newline at end of file diff --git a/src/app/admin/dashboard/page.tsx b/src/app/admin/dashboard/page.tsx index ff9e21a..bfc3978 100644 --- a/src/app/admin/dashboard/page.tsx +++ b/src/app/admin/dashboard/page.tsx @@ -1,4 +1,6 @@ import React from 'react'; +import AssistantMetrics from '@/app/admin/dashboard/AssistantMetrics'; +import UserMetrics from '@/app/admin/dashboard/UserMetrics'; export default function Dashboard() { return ( @@ -7,6 +9,18 @@ export default function Dashboard() {

Analytics on your Assistants Hub instance

+
+
+ Assistant Metrics +
+ +
+
+
+ User Metrics +
+ +
); }