Skip to content

Commit

Permalink
added friends and friendrequest relations for users
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayahhhmed committed Oct 26, 2023
1 parent 81af2dc commit d57e9e0
Show file tree
Hide file tree
Showing 8 changed files with 2,500 additions and 5,454 deletions.
7,694 changes: 2,326 additions & 5,368 deletions server/package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"author": "",
"private": true,
"license": "UNLICENSED",
"prisma": {
"seed": "ts-node prisma/seed.ts"
},
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
Expand Down
53 changes: 0 additions & 53 deletions server/prisma/migrations/20230906070029_init/migration.sql

This file was deleted.

99 changes: 99 additions & 0 deletions server/prisma/migrations/20231026012818_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
-- CreateTable
CREATE TABLE "User" (
"userId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"lastLogin" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
"firstname" TEXT,
"lastname" TEXT,
"email" TEXT NOT NULL,
"profileURL" TEXT,

CONSTRAINT "User_pkey" PRIMARY KEY ("userId")
);

-- CreateTable
CREATE TABLE "Event" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"location" TEXT,
"description" TEXT,
"colour" TEXT NOT NULL DEFAULT '#1F7E8C',
"day" TEXT NOT NULL,
"start" TIMESTAMP(3) NOT NULL,
"end" TIMESTAMP(3) NOT NULL,
"timetableId" TEXT,

CONSTRAINT "Event_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Class" (
"id" TEXT NOT NULL,
"classType" TEXT NOT NULL,
"courseName" TEXT,
"timetableId" TEXT
);

-- CreateTable
CREATE TABLE "Timetable" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"selectedCourses" TEXT[],
"userId" TEXT NOT NULL,

CONSTRAINT "Timetable_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Settings" (
"userId" TEXT NOT NULL,
"is12HourMode" BOOLEAN NOT NULL,
"isDarkMode" BOOLEAN NOT NULL,
"isSquareEdges" BOOLEAN NOT NULL,
"isHideFullClasses" BOOLEAN NOT NULL,
"isDefaultUnscheduled" BOOLEAN NOT NULL,
"isHideClassInfo" BOOLEAN NOT NULL,
"isSortAlphabetic" BOOLEAN NOT NULL,
"isShowOnlyOpenClasses" BOOLEAN NOT NULL,
"isHideExamClasses" BOOLEAN NOT NULL,
"isConvertToLocalTimezone" BOOLEAN NOT NULL
);

-- CreateTable
CREATE TABLE "_UserFriends" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "Class_id_key" ON "Class"("id");

-- CreateIndex
CREATE UNIQUE INDEX "Timetable_id_key" ON "Timetable"("id");

-- CreateIndex
CREATE UNIQUE INDEX "Settings_userId_key" ON "Settings"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "_UserFriends_AB_unique" ON "_UserFriends"("A", "B");

-- CreateIndex
CREATE INDEX "_UserFriends_B_index" ON "_UserFriends"("B");

-- AddForeignKey
ALTER TABLE "Event" ADD CONSTRAINT "Event_timetableId_fkey" FOREIGN KEY ("timetableId") REFERENCES "Timetable"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Class" ADD CONSTRAINT "Class_timetableId_fkey" FOREIGN KEY ("timetableId") REFERENCES "Timetable"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Timetable" ADD CONSTRAINT "Timetable_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("userId") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Settings" ADD CONSTRAINT "Settings_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("userId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_UserFriends" ADD CONSTRAINT "_UserFriends_A_fkey" FOREIGN KEY ("A") REFERENCES "User"("userId") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_UserFriends" ADD CONSTRAINT "_UserFriends_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("userId") ON DELETE CASCADE ON UPDATE CASCADE;
52 changes: 26 additions & 26 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ datasource db {
}

model User {
userId String @id
createdAt DateTime @default(now())
deleteUserAt DateTime // Temporary, Max's TTL method
google_uid String
lastLogin DateTime?
firstname String?
lastname String?
email String
profileURL String?
timetable Timetable[]
settings Settings?
userId String @id // same as zid
createdAt DateTime @default(now())
lastLogin DateTime? @default(now())
firstname String?
lastname String?
email String
profileURL String?
timetable Timetable[]
settings Settings?
friends User[] @relation("UserFriends")
friendRequests User[] @relation("UserFriends")
}

model Event {
Expand All @@ -43,34 +43,34 @@ model Class {
id String @unique
classType String // e.g. Lecture, Tutorial, Laboratory, etc. Not putting into enum because there are other whacky classTypes
courseName String?
Timetable Timetable? @relation(fields: [timetableId], references: [id])
Timetable Timetable? @relation(fields: [timetableId], references: [id], onDelete: Cascade)
timetableId String?
}

model Timetable {
id String @id
id String @id @unique
name String
selectedCourses String[]
selectedClasses Class[]
createdEvents Event[]
user User @relation(fields: [userId], references: [userId])
user User @relation(fields: [userId], references: [userId], onDelete: Cascade)
userId String
}

// Weak entity
model Settings {
userId String @unique
user User @relation(fields: [userId], references: [userId])
is12HourMode Boolean
isDarkMode Boolean
isSquareEdges Boolean
isHideFullClasses Boolean
isDefaultUnscheduled Boolean
isHideClassInfo Boolean
isSortAlphabetic Boolean
isShowOnlyOpenClasses Boolean
isHideExamClasses Boolean
isConvertToLocalTimezone Boolean
userId String @unique
user User @relation(fields: [userId], references: [userId])
is12HourMode Boolean
isDarkMode Boolean
isSquareEdges Boolean
isHideFullClasses Boolean
isDefaultUnscheduled Boolean
isHideClassInfo Boolean
isSortAlphabetic Boolean
isShowOnlyOpenClasses Boolean
isHideExamClasses Boolean
isConvertToLocalTimezone Boolean
}

// future: add settings for individual timetables, rounded corners, show only open classes etc?
43 changes: 43 additions & 0 deletions server/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// prisma/seed.ts

import { PrismaClient } from '@prisma/client';
// initialize Prisma Client
const prisma = new PrismaClient();
const maximumZidNumber = 9e7;
const minimumZidNumber = 1e7;

const getZid = (): number => {
return Math.floor(Math.random() * (maximumZidNumber - minimumZidNumber + 1) + minimumZidNumber);
}
// TODO
const generateTimetable = async () => {}

const generateUsers = async (numUsers: number, generateTimetablesForAllUsers? : boolean) => {
for (let i = 0; i < numUsers; i++) {
const zid = getZid().toString();
const user = await prisma.user.upsert({
where: { userId: zid},
update: {},
create: {
userId: zid,
email: `z${zid}@unsw.edu.au`,
}
});
console.log(user);
}
}

async function main() {
generateUsers(2);
}

// execute the main function
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});

10 changes: 3 additions & 7 deletions server/src/auth/dtos/auth.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { IsNotEmpty, IsString } from 'class-validator';

export class AuthDto {
@IsString()
@IsNotEmpty()
code : string;
@IsString() @IsNotEmpty() code : string;

@IsString()
@IsNotEmpty()
state: string
}
@IsString() @IsNotEmpty() state: string;
}
Empty file.

0 comments on commit d57e9e0

Please sign in to comment.