From f7ecffe572cff80dbabb4a46f1d8e54e5c760d5d Mon Sep 17 00:00:00 2001 From: "vincent.steinman" <vincent.steinmann@etu.hesge.ch> Date: Tue, 13 Feb 2024 12:06:24 +0100 Subject: [PATCH] migration --- .../20240212153007_test_tag/migration.sql | 7 ++++ .../20240212153538_test_tag/migration.sql | 1 + .../migration.sql | 1 + .../migration.sql | 1 + ExpressAPI/prisma/schema.prisma | 11 +++++- ExpressAPI/src/routes/TagsRoutes.ts | 38 ++++++------------- 6 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 ExpressAPI/prisma/migrations/20240212153007_test_tag/migration.sql create mode 100644 ExpressAPI/prisma/migrations/20240212153538_test_tag/migration.sql create mode 100644 ExpressAPI/prisma/migrations/20240212155805_description_of_the_migration/migration.sql create mode 100644 ExpressAPI/prisma/migrations/20240212155844_description_of_the_migration/migration.sql diff --git a/ExpressAPI/prisma/migrations/20240212153007_test_tag/migration.sql b/ExpressAPI/prisma/migrations/20240212153007_test_tag/migration.sql new file mode 100644 index 0000000..1931dc5 --- /dev/null +++ b/ExpressAPI/prisma/migrations/20240212153007_test_tag/migration.sql @@ -0,0 +1,7 @@ +-- CreateTable +CREATE TABLE `Tag` ( + `name` CHAR(36) NOT NULL, + `type` ENUM('LANGUAGE', 'FRAMEWORK', 'THEME', 'USERDEFINED') NOT NULL, + + PRIMARY KEY (`name`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; diff --git a/ExpressAPI/prisma/migrations/20240212153538_test_tag/migration.sql b/ExpressAPI/prisma/migrations/20240212153538_test_tag/migration.sql new file mode 100644 index 0000000..af5102c --- /dev/null +++ b/ExpressAPI/prisma/migrations/20240212153538_test_tag/migration.sql @@ -0,0 +1 @@ +-- This is an empty migration. \ No newline at end of file diff --git a/ExpressAPI/prisma/migrations/20240212155805_description_of_the_migration/migration.sql b/ExpressAPI/prisma/migrations/20240212155805_description_of_the_migration/migration.sql new file mode 100644 index 0000000..af5102c --- /dev/null +++ b/ExpressAPI/prisma/migrations/20240212155805_description_of_the_migration/migration.sql @@ -0,0 +1 @@ +-- This is an empty migration. \ No newline at end of file diff --git a/ExpressAPI/prisma/migrations/20240212155844_description_of_the_migration/migration.sql b/ExpressAPI/prisma/migrations/20240212155844_description_of_the_migration/migration.sql new file mode 100644 index 0000000..af5102c --- /dev/null +++ b/ExpressAPI/prisma/migrations/20240212155844_description_of_the_migration/migration.sql @@ -0,0 +1 @@ +-- This is an empty migration. \ No newline at end of file diff --git a/ExpressAPI/prisma/schema.prisma b/ExpressAPI/prisma/schema.prisma index 8d0ffc7..6fed16d 100644 --- a/ExpressAPI/prisma/schema.prisma +++ b/ExpressAPI/prisma/schema.prisma @@ -4,7 +4,7 @@ generator client { datasource db { provider = "mysql" - url = env("mysql://root:9buz7f312479g6234f1gnioubervw79b8z@localhost:59231/dojo") + url = env("DATABASE_URL") } enum UserRole { @@ -13,6 +13,13 @@ enum UserRole { ADMIN } +enum Type{ + LANGUAGE + FRAMEWORK + THEME + USERDEFINED +} + model User { id Int @id /// The user's id is the same as their gitlab id name String? @@ -75,5 +82,5 @@ model Result { model Tag { name String @id @db.Char(36) - type Json @db.Json + type Type } \ No newline at end of file diff --git a/ExpressAPI/src/routes/TagsRoutes.ts b/ExpressAPI/src/routes/TagsRoutes.ts index 148d7c7..d8af7ea 100644 --- a/ExpressAPI/src/routes/TagsRoutes.ts +++ b/ExpressAPI/src/routes/TagsRoutes.ts @@ -49,39 +49,25 @@ class TagRoutes implements RoutesManager { } private async addTag(req: express.Request, res: express.Response) { + let name = req.body.name + let type = req.body.type + //TODO this + db.exercise.upsert({ + where : { id: name }, + update: {}, + create: { + id : name, + type : type, + } + } + ) } private async deleteTag(req: express.Request, res: express.Response) { } private async getSubmittedTag(req: express.Request, res: express.Response) { - const repoTree: Array<GitlabTreeFile> = await GitlabManager.getRepositoryTree(req.boundParams.exercise!.assignment.gitlabId); - - let assignmentHjsonFile!: GitlabFile; - const immutableFiles: Array<GitlabFile> = await Promise.all(Config.assignment.baseFiles.map(async (baseFile: string) => { - const file = await GitlabManager.getFile(req.boundParams.exercise!.assignment.gitlabId, baseFile); - - if ( baseFile === Config.assignment.filename ) { - assignmentHjsonFile = file; - } - - return file; - })); - - const dojoAssignmentFile: AssignmentFile = JSON5.parse(atob(assignmentHjsonFile.content)) as AssignmentFile; - - const immutablePaths = dojoAssignmentFile.immutable.map(fileDescriptor => fileDescriptor.path); - await Promise.all(repoTree.map(async gitlabTreeFile => { - if ( gitlabTreeFile.type == GitlabTreeFileType.BLOB ) { - for ( const immutablePath of immutablePaths ) { - if ( gitlabTreeFile.path.startsWith(immutablePath) ) { - immutableFiles.push(await GitlabManager.getFile(req.boundParams.exercise!.assignment.gitlabId, gitlabTreeFile.path)); - break; - } - } - } - })); return req.session.sendResponse(res, StatusCodes.OK, { assignment : (req.boundParams.exercise as Exercise).assignment, -- GitLab