diff --git a/ExpressAPI/prisma/migrations/20240222174056_add_correction_to_assignment/migration.sql b/ExpressAPI/prisma/migrations/20240222174056_add_correction_to_assignment/migration.sql new file mode 100644 index 0000000000000000000000000000000000000000..7c9d9ee91b6b11784c6e9f4130be1918aaf5e886 --- /dev/null +++ b/ExpressAPI/prisma/migrations/20240222174056_add_correction_to_assignment/migration.sql @@ -0,0 +1,29 @@ +-- CreateTable +CREATE TABLE `_AssignmentToTag` ( + `A` VARCHAR(191) NOT NULL, + `B` CHAR(36) NOT NULL, + + UNIQUE INDEX `_AssignmentToTag_AB_unique`(`A`, `B`), + INDEX `_AssignmentToTag_B_index`(`B`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `_ExerciseToTag` ( + `A` CHAR(36) NOT NULL, + `B` CHAR(36) NOT NULL, + + UNIQUE INDEX `_ExerciseToTag_AB_unique`(`A`, `B`), + INDEX `_ExerciseToTag_B_index`(`B`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `_AssignmentToTag` ADD CONSTRAINT `_AssignmentToTag_A_fkey` FOREIGN KEY (`A`) REFERENCES `Assignment`(`name`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `_AssignmentToTag` ADD CONSTRAINT `_AssignmentToTag_B_fkey` FOREIGN KEY (`B`) REFERENCES `Tag`(`name`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `_ExerciseToTag` ADD CONSTRAINT `_ExerciseToTag_A_fkey` FOREIGN KEY (`A`) REFERENCES `Exercise`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `_ExerciseToTag` ADD CONSTRAINT `_ExerciseToTag_B_fkey` FOREIGN KEY (`B`) REFERENCES `Tag`(`name`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/ExpressAPI/prisma/schema.prisma b/ExpressAPI/prisma/schema.prisma index 6fed16d63b980486c9979eb9ad1c14d9b906c6c0..57139d4af976b627e9c9f45360fb9b3752b154ab 100644 --- a/ExpressAPI/prisma/schema.prisma +++ b/ExpressAPI/prisma/schema.prisma @@ -44,6 +44,7 @@ model Assignment { exercises Exercise[] staff User[] + tags Tag[] } model Exercise { @@ -64,6 +65,7 @@ model Exercise { members User[] results Result[] + tags Tag[] } model Result { @@ -81,6 +83,9 @@ model Result { } model Tag { - name String @id @db.Char(36) - type Type + name String @id @db.Char(36) + type Type + + assignment Assignment[] + exercise Exercise[] } \ No newline at end of file diff --git a/ExpressAPI/prisma/seed.ts b/ExpressAPI/prisma/seed.ts index 3e0fdb3a6775d90e6ced2e1339d655ee367ad970..ab340d7c43998192f81b8b0984cf5b7b9f3ca91d 100644 --- a/ExpressAPI/prisma/seed.ts +++ b/ExpressAPI/prisma/seed.ts @@ -13,7 +13,7 @@ async function main() { await assignments(); await exercises(); await results(); - await tags(); + await tag(); } main().then(async () => { @@ -1590,380 +1590,380 @@ async function results() { } } -async function tags() { - await db.tags.upsert({ - where : { id: 'C' }, +async function tag() { + await db.tag.upsert({ + where : { name: 'C' }, update: {}, create: { - id : 'C', + name : 'C', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Java' }, + await db.tag.upsert({ + where : { name: 'Java' }, update: {}, create: { - id : 'Java', + name : 'Java', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Scala' }, + await db.tag.upsert({ + where : { name: 'Scala' }, update: {}, create: { - id : 'Scala', + name : 'Scala', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Kotlin' }, + await db.tag.upsert({ + where : { name: 'Kotlin' }, update: {}, create: { - id : 'Kotlin', + name : 'Kotlin', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Rust' }, + await db.tag.upsert({ + where : { name: 'Rust' }, update: {}, create: { - id : 'Rust', + name : 'Rust', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'JavaScript' }, + await db.tag.upsert({ + where : { name: 'JavaScript' }, update: {}, create: { - id : 'JavaScript', + name : 'JavaScript', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'TypeScript' }, + await db.tag.upsert({ + where : { name: 'TypeScript' }, update: {}, create: { - id : 'TypeScript', + name : 'TypeScript', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Python' }, + await db.tag.upsert({ + where : { name: 'Python' }, update: {}, create: { - id : 'Python', + name : 'Python', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'HTML' }, + await db.tag.upsert({ + where : { name: 'HTML' }, update: {}, create: { - id : 'HTML', + name : 'HTML', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'CSS' }, + await db.tag.upsert({ + where : { name: 'CSS' }, update: {}, create: { - id : 'CSS', + name : 'CSS', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'C++' }, + await db.tag.upsert({ + where : { name: 'C++' }, update: {}, create: { - id : 'C++', + name : 'C++', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Go' }, + await db.tag.upsert({ + where : { name: 'Go' }, update: {}, create: { - id : 'Go', + name : 'Go', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'PHP' }, + await db.tag.upsert({ + where : { name: 'PHP' }, update: {}, create: { - id : 'PHP', + name : 'PHP', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'C#' }, + await db.tag.upsert({ + where : { name: 'C#' }, update: {}, create: { - id : 'C#', + name : 'C#', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Swift' }, + await db.tag.upsert({ + where : { name: 'Swift' }, update: {}, create: { - id : 'Swift', + name : 'Swift', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Matlab' }, + await db.tag.upsert({ + where : { name: 'Matlab' }, update: {}, create: { - id : 'Matlab', + name : 'Matlab', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'SQL' }, + await db.tag.upsert({ + where : { name: 'SQL' }, update: {}, create: { - id : 'SQL', + name : 'SQL', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Assembly' }, + await db.tag.upsert({ + where : { name: 'Assembly' }, update: {}, create: { - id : 'Assembly', + name : 'Assembly', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Ruby' }, + await db.tag.upsert({ + where : { name: 'Ruby' }, update: {}, create: { - id : 'Ruby', + name : 'Ruby', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Fortran' }, + await db.tag.upsert({ + where : { name: 'Fortran' }, update: {}, create: { - id : 'Fortran', + name : 'Fortran', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Pascal' }, + await db.tag.upsert({ + where : { name: 'Pascal' }, update: {}, create: { - id : 'Pascal', + name : 'Pascal', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Visual Basic' }, + await db.tag.upsert({ + where : { name: 'Visual Basic' }, update: {}, create: { - id : 'Visual Basic', + name : 'Visual Basic', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'R' }, + await db.tag.upsert({ + where : { name: 'R' }, update: {}, create: { - id : 'R', + name : 'R', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Objective-C' }, + await db.tag.upsert({ + where : { name: 'Objective-C' }, update: {}, create: { - id : 'Objective-C', + name : 'Objective-C', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Lua' }, + await db.tag.upsert({ + where : { name: 'Lua' }, update: {}, create: { - id : 'Lua', + name : 'Lua', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Ada' }, + await db.tag.upsert({ + where : { name: 'Ada' }, update: {}, create: { - id : 'Ada', + name : 'Ada', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Haskell' }, + await db.tag.upsert({ + where : { name: 'Haskell' }, update: {}, create: { - id : 'Haskell', + name : 'Haskell', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Shell/PowerShell' }, + await db.tag.upsert({ + where : { name: 'Shell/PowerShell' }, update: {}, create: { - id : 'Shell/PowerShell', + name : 'Shell/PowerShell', type : tagType.Language, } }); - await db.tags.upsert({ - where : { id: 'Express' }, + await db.tag.upsert({ + where : { name: 'Express' }, update: {}, create: { - id : 'Express', + name : 'Express', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Django' }, + await db.tag.upsert({ + where : { name: 'Django' }, update: {}, create: { - id : 'Django', + name : 'Django', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Ruby on Rails' }, + await db.tag.upsert({ + where : { name: 'Ruby on Rails' }, update: {}, create: { - id : 'Ruby on Rails', + name : 'Ruby on Rails', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Angular' }, + await db.tag.upsert({ + where : { name: 'Angular' }, update: {}, create: { - id : 'Angular', + name : 'Angular', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'React' }, + await db.tag.upsert({ + where : { name: 'React' }, update: {}, create: { - id : 'React', + name : 'React', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Flutter' }, + await db.tag.upsert({ + where : { name: 'Flutter' }, update: {}, create: { - id : 'Flutter', + name : 'Flutter', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Ionic' }, + await db.tag.upsert({ + where : { name: 'Ionic' }, update: {}, create: { - id : 'Ionic', + name : 'Ionic', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Flask' }, + await db.tag.upsert({ + where : { name: 'Flask' }, update: {}, create: { - id : 'Flask', + name : 'Flask', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'React Native' }, + await db.tag.upsert({ + where : { name: 'React Native' }, update: {}, create: { - id : 'React Native', + name : 'React Native', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Xamarin' }, + await db.tag.upsert({ + where : { name: 'Xamarin' }, update: {}, create: { - id : 'Xamarin', + name : 'Xamarin', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Laravel' }, + await db.tag.upsert({ + where : { name: 'Laravel' }, update: {}, create: { - id : 'Laravel', + name : 'Laravel', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Spring' }, + await db.tag.upsert({ + where : { name: 'Spring' }, update: {}, create: { - id : 'Spring', + name : 'Spring', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Play' }, + await db.tag.upsert({ + where : { name: 'Play' }, update: {}, create: { - id : 'Play', + name : 'Play', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Symfony' }, + await db.tag.upsert({ + where : { name: 'Symfony' }, update: {}, create: { - id : 'Symfony', + name : 'Symfony', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'ASP.NET' }, + await db.tag.upsert({ + where : { name: 'ASP.NET' }, update: {}, create: { - id : 'ASP.NET', + name : 'ASP.NET', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Meteor' }, + await db.tag.upsert({ + where : { name: 'Meteor' }, update: {}, create: { - id : 'Meteor', + name : 'Meteor', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Vue.js' }, + await db.tag.upsert({ + where : { name: 'Vue.js' }, update: {}, create: { - id : 'Vue.js', + name : 'Vue.js', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Svelte' }, + await db.tag.upsert({ + where : { name: 'Svelte' }, update: {}, create: { - id : 'Svelte', + name : 'Svelte', type : tagType.Framework, } }); - await db.tags.upsert({ - where : { id: 'Express.js' }, + await db.tag.upsert({ + where : { name: 'Express.js' }, update: {}, create: { - id : 'Express.js', + name : 'Express.js', type : tagType.Framework, } }); diff --git a/ExpressAPI/src/routes/TagsRoutes.ts b/ExpressAPI/src/routes/TagsRoutes.ts index d8af7ea06e9cbf230b2bf89995c7d0a156fe503a..fcfb493d70d23fa9590453ac2b1552b59b5cb0fb 100644 --- a/ExpressAPI/src/routes/TagsRoutes.ts +++ b/ExpressAPI/src/routes/TagsRoutes.ts @@ -49,21 +49,26 @@ class TagRoutes implements RoutesManager { } private async addTag(req: express.Request, res: express.Response) { - let name = req.body.name - let type = req.body.type + let my_name = req.body.name + let my_type = req.body.type - //TODO this - db.exercise.upsert({ - where : { id: name }, + //TODO this + check admin ->si non -> UserDefined + db.tag.upsert({ + where : { name: my_name }, update: {}, create: { - id : name, - type : type, - } - } - ) + name : my_name, + type : my_type, + } + }) } private async deleteTag(req: express.Request, res: express.Response) { + let my_name = req.body.name + + //TODO this + check admin ->si non -> UserDefined + db.tag.delete({ + where : { name: my_name } + }) } private async getSubmittedTag(req: express.Request, res: express.Response) { diff --git a/ExpressAPI/src/types/DatabaseTypes.ts b/ExpressAPI/src/types/DatabaseTypes.ts index eadad92e00f30b96d8d3cf9b1c687a67d959ed27..1636dd79f43fd643b1d92f9a457db4ab2465c0c0 100644 --- a/ExpressAPI/src/types/DatabaseTypes.ts +++ b/ExpressAPI/src/types/DatabaseTypes.ts @@ -9,14 +9,16 @@ const userBase = Prisma.validator<Prisma.UserDefaultArgs>()({ const assignmentBase = Prisma.validator<Prisma.AssignmentDefaultArgs>()({ include: { exercises: true, - staff : true + staff : true, + tags : true } }); const exerciseBase = Prisma.validator<Prisma.ExerciseDefaultArgs>()({ include: { assignment: true, members : true, - results : true + results : true, + tags : true } }); const resultBase = Prisma.validator<Prisma.ResultDefaultArgs>()({ @@ -26,8 +28,8 @@ const resultBase = Prisma.validator<Prisma.ResultDefaultArgs>()({ }); const tagsBase = Prisma.validator<Prisma.TagsDefaultArgs>()({ include: { - name: true, - type: true, + exercises: true, + assignments: true, } });