New controllers and services; Auth

This commit is contained in:
Aslan 2025-12-26 19:33:43 +01:00
parent 2fc0f9c404
commit d17f37749d
35 changed files with 1040 additions and 164 deletions

View file

@ -0,0 +1,50 @@
/*
Warnings:
- You are about to drop the column `communityId` on the `User` table. All the data in the column will be lost.
- Added the required column `ownerId` to the `Community` table without a default value. This is not possible if the table is not empty.
- Added the required column `creatorId` to the `Invite` table without a default value. This is not possible if the table is not empty.
- Made the column `communityId` on table `Invite` required. This step will fail if there are existing NULL values in that column.
*/
-- DropForeignKey
ALTER TABLE "Invite" DROP CONSTRAINT "Invite_communityId_fkey";
-- DropForeignKey
ALTER TABLE "User" DROP CONSTRAINT "User_communityId_fkey";
-- AlterTable
ALTER TABLE "Community" ADD COLUMN "ownerId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "Invite" ADD COLUMN "creatorId" TEXT NOT NULL,
ALTER COLUMN "communityId" SET NOT NULL;
-- AlterTable
ALTER TABLE "User" DROP COLUMN "communityId";
-- CreateTable
CREATE TABLE "_MembersCommunitiesToUsers" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_MembersCommunitiesToUsers_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE INDEX "_MembersCommunitiesToUsers_B_index" ON "_MembersCommunitiesToUsers"("B");
-- AddForeignKey
ALTER TABLE "Community" ADD CONSTRAINT "Community_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Invite" ADD CONSTRAINT "Invite_communityId_fkey" FOREIGN KEY ("communityId") REFERENCES "Community"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Invite" ADD CONSTRAINT "Invite_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_MembersCommunitiesToUsers" ADD CONSTRAINT "_MembersCommunitiesToUsers_A_fkey" FOREIGN KEY ("A") REFERENCES "Community"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_MembersCommunitiesToUsers" ADD CONSTRAINT "_MembersCommunitiesToUsers_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View file

@ -0,0 +1,11 @@
-- AlterTable
ALTER TABLE "Channel" ADD COLUMN "creationDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "Community" ADD COLUMN "creationDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "Role" ADD COLUMN "creationDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "Session" ADD COLUMN "creationDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

View file

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Role" ADD COLUMN "permissions" TEXT[];

View file

@ -0,0 +1,16 @@
-- CreateTable
CREATE TABLE "_UsersRoleToUsers" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_UsersRoleToUsers_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE INDEX "_UsersRoleToUsers_B_index" ON "_UsersRoleToUsers"("B");
-- AddForeignKey
ALTER TABLE "_UsersRoleToUsers" ADD CONSTRAINT "_UsersRoleToUsers_A_fkey" FOREIGN KEY ("A") REFERENCES "Role"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_UsersRoleToUsers" ADD CONSTRAINT "_UsersRoleToUsers_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View file

@ -0,0 +1,31 @@
/*
Warnings:
- You are about to drop the `_UsersRoleToUsers` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "_UsersRoleToUsers" DROP CONSTRAINT "_UsersRoleToUsers_A_fkey";
-- DropForeignKey
ALTER TABLE "_UsersRoleToUsers" DROP CONSTRAINT "_UsersRoleToUsers_B_fkey";
-- DropTable
DROP TABLE "_UsersRoleToUsers";
-- CreateTable
CREATE TABLE "_UsersRolesToUsers" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_UsersRolesToUsers_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE INDEX "_UsersRolesToUsers_B_index" ON "_UsersRolesToUsers"("B");
-- AddForeignKey
ALTER TABLE "_UsersRolesToUsers" ADD CONSTRAINT "_UsersRolesToUsers_A_fkey" FOREIGN KEY ("A") REFERENCES "Role"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_UsersRolesToUsers" ADD CONSTRAINT "_UsersRolesToUsers_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View file

@ -1,64 +1,76 @@
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
engineType = "client"
provider = "prisma-client"
output = "../src/generated/prisma"
engineType = "client"
}
datasource db {
provider = "postgresql"
provider = "postgresql"
}
model Community {
id String @id @unique @default(uuid())
name String @unique
description String?
members User[]
Channel Channel[]
Role Role[]
invites Invite[]
id String @id @unique @default(uuid())
name String @unique
description String?
creationDate DateTime @default(now())
User User @relation(name: "OwnerCommunityToUser", fields: [ownerId], references: [id])
ownerId String
members User[] @relation(name: "MembersCommunitiesToUsers")
channels Channel[]
roles Role[]
invites Invite[]
}
model Channel {
id String @id @unique @default(uuid())
name String?
community Community? @relation(fields: [communityId], references: [id])
communityId String?
id String @id @unique @default(uuid())
name String?
community Community? @relation(fields: [communityId], references: [id])
communityId String?
creationDate DateTime @default(now())
}
model Role {
id String @id @unique @default(uuid())
name String?
community Community @relation(fields: [communityId], references: [id])
communityId String
id String @id @unique @default(uuid())
name String?
community Community @relation(fields: [communityId], references: [id])
communityId String
users User[] @relation(name: "UsersRolesToUsers")
permissions String[]
creationDate DateTime @default(now())
}
model User {
id String @id @unique @default(uuid())
username String @unique
email String? @unique
passwordHash String?
description String?
admin Boolean @default(false)
registerDate DateTime @default(now())
lastLogin DateTime?
Community Community? @relation(fields: [communityId], references: [id])
communityId String?
Session Session[]
id String @id @unique @default(uuid())
username String @unique
email String? @unique
passwordHash String?
description String?
admin Boolean @default(false)
registerDate DateTime @default(now())
lastLogin DateTime?
Session Session[]
ownedInvites Invite[]
ownedCommunities Community[] @relation(name: "OwnerCommunityToUser")
communities Community[] @relation(name: "MembersCommunitiesToUsers")
roles Role[] @relation(name: "UsersRolesToUsers")
}
model Session {
id String @id @unique @default(uuid())
owner User @relation(fields: [userId], references: [id])
token String
userId String
id String @id @unique @default(uuid())
owner User @relation(fields: [userId], references: [id])
userId String
token String
creationDate DateTime @default(now())
}
model Invite {
id String @id @unique @default(uuid())
Community Community? @relation(fields: [communityId], references: [id])
communityId String?
totalInvites Int @default(0)
remainingInvites Int @default(0)
creationDate DateTime @default(now())
expirationDate DateTime?
id String @id @unique @default(uuid())
Community Community @relation(fields: [communityId], references: [id])
communityId String
User User @relation(fields: [creatorId], references: [id])
creatorId String
totalInvites Int @default(0)
remainingInvites Int @default(0)
creationDate DateTime @default(now())
expirationDate DateTime?
}