Skip to content

Commit

Permalink
hot-fix : creating user repo
Browse files Browse the repository at this point in the history
  • Loading branch information
lshtar13 committed Aug 18, 2023
1 parent 21233c0 commit 9da51e6
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 176 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
image: mcr.microsoft.com/vscode/devcontainers/typescript-node:18-bullseye
ports:
- 4000:4000
expose:
- 4000
volumes:
- .:/workspace:cached
stdin_open: true
Expand Down
8 changes: 0 additions & 8 deletions prisma/migrations/20230727042812_/migration.sql

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions prisma/migrations/20230802044433_/migration.sql

This file was deleted.

8 changes: 0 additions & 8 deletions prisma/migrations/20230802044621_/migration.sql

This file was deleted.

11 changes: 0 additions & 11 deletions prisma/migrations/20230806062344_/migration.sql

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions prisma/migrations/20230817124452_/migration.sql

This file was deleted.

57 changes: 0 additions & 57 deletions prisma/migrations/20230818063054_/migration.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- CreateEnum
CREATE TYPE "Role" AS ENUM ('Tutor', 'Student');

-- CreateEnum
CREATE TYPE "TestcaseType" AS ENUM ('OPENED', 'HIDDEN');

-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
Expand All @@ -17,7 +20,6 @@ CREATE TABLE "User" (
CREATE TABLE "Repo" (
"id" SERIAL NOT NULL,
"name" VARCHAR(255) NOT NULL,
"url" VARCHAR(255) NOT NULL,

CONSTRAINT "Repo_pkey" PRIMARY KEY ("id")
);
Expand Down Expand Up @@ -47,6 +49,7 @@ CREATE TABLE "Problem" (
"id" SERIAL NOT NULL,
"title" VARCHAR(255) NOT NULL,
"text" TEXT NOT NULL,
"uuid" VARCHAR(255) NOT NULL DEFAULT 'null',
"repoId" INTEGER NOT NULL,

CONSTRAINT "Problem_pkey" PRIMARY KEY ("id")
Expand All @@ -57,19 +60,21 @@ CREATE TABLE "TestCase" (
"id" SERIAL NOT NULL,
"input" TEXT NOT NULL,
"output" TEXT NOT NULL,
"isHidden" "TestcaseType" NOT NULL,
"repoId" INTEGER NOT NULL,
"problemId" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "HiddenCase" (
CREATE TABLE "UserTestCase" (
"id" SERIAL NOT NULL,
"input" TEXT NOT NULL,
"output" TEXT NOT NULL,
"problemId" INTEGER NOT NULL,
"isCorrect" BOOLEAN,
"userId" INTEGER NOT NULL,
"testCaseId" INTEGER NOT NULL,

CONSTRAINT "HiddenCase_pkey" PRIMARY KEY ("id")
CONSTRAINT "UserTestCase_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
Expand All @@ -78,6 +83,12 @@ CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
-- CreateIndex
CREATE UNIQUE INDEX "User_nickname_key" ON "User"("nickname");

-- CreateIndex
CREATE UNIQUE INDEX "Repo_name_key" ON "Repo"("name");

-- CreateIndex
CREATE UNIQUE INDEX "UserRepo_userId_repoId_key" ON "UserRepo"("userId", "repoId");

-- AddForeignKey
ALTER TABLE "UserRepo" ADD CONSTRAINT "UserRepo_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

Expand All @@ -93,8 +104,14 @@ ALTER TABLE "Score" ADD CONSTRAINT "Score_problemId_fkey" FOREIGN KEY ("problemI
-- AddForeignKey
ALTER TABLE "Problem" ADD CONSTRAINT "Problem_repoId_fkey" FOREIGN KEY ("repoId") REFERENCES "Repo"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TestCase" ADD CONSTRAINT "TestCase_repoId_fkey" FOREIGN KEY ("repoId") REFERENCES "Repo"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TestCase" ADD CONSTRAINT "TestCase_problemId_fkey" FOREIGN KEY ("problemId") REFERENCES "Problem"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "HiddenCase" ADD CONSTRAINT "HiddenCase_problemId_fkey" FOREIGN KEY ("problemId") REFERENCES "Problem"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "UserTestCase" ADD CONSTRAINT "UserTestCase_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserTestCase" ADD CONSTRAINT "UserTestCase_testCaseId_fkey" FOREIGN KEY ("testCaseId") REFERENCES "TestCase"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
2 changes: 2 additions & 0 deletions src/problem/problem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export class ProblemService {
}

async isMemberOfRepo(userId: number, repoId: number): Promise<boolean> {
console.log(userId, repoId)

const userRepo = await this.prisma.userRepo.findFirst({
where: {
userId,
Expand Down
10 changes: 8 additions & 2 deletions src/repos/repos.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ export class ReposController {

@Roles(Role.Tutor)
@Post()
async createRepo(@Body() createRepoDto: CreateRepoDto) {
const newRepo = await this.reposService.createNewRepo(createRepoDto)
async createRepo(
@Body() createRepoDto: CreateRepoDto,
@Req() req: AuthenticatedRequest
) {
const newRepo = await this.reposService.createNewRepo(
createRepoDto,
req.user.userId
)
return new CommonResponseDto({ repoId: newRepo.id })
}

Expand Down
9 changes: 7 additions & 2 deletions src/repos/repos.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ReposService {
})
}

async createNewRepo(createRepoDto: CreateRepoDto) {
async createNewRepo(createRepoDto: CreateRepoDto, userId: number) {
const repoName = createRepoDto.repoName.toLowerCase()
const repoExist = await this.prismaService.repo.findFirst({
where: {
Expand All @@ -49,7 +49,12 @@ export class ReposService {
await this.minio.makeBucket(repoName)
return await tx.repo.create({
data: {
name: repoName
name: repoName,
UserRepo: {
create: {
userId: userId
}
}
}
})
})
Expand Down

0 comments on commit 9da51e6

Please sign in to comment.