Skip to content
Snippets Groups Projects
Commit d1d115dd authored by vincent.steinman's avatar vincent.steinman Committed by michael.minelli
Browse files

fix param/body for add, delete

parent 77fed69d
Branches
Tags
No related merge requests found
/*
Warnings:
- Added the required column `state` to the `SubmissionTag` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `SubmissionTag` ADD COLUMN `state` ENUM('PENDINGAPPROVAL', 'DECLINED', 'APPROVED') NOT NULL;
/*
Warnings:
- You are about to alter the column `state` on the `SubmissionTag` table. The data in that column could be lost. The data in that column will be cast from `Enum(EnumId(3))` to `VarChar(191)`.
*/
-- AlterTable
ALTER TABLE `SubmissionTag` MODIFY `state` VARCHAR(191) NOT NULL;
......@@ -98,5 +98,6 @@ model Tag {
model SubmissionTag {
name String @id @db.Char(36)
type TagType
type TagType
state String
}
\ No newline at end of file
......@@ -2,10 +2,10 @@ import { Prisma, Tag } from '@prisma/client';
import db from '../helpers/DatabaseHelper';
class TagManager {
async get(name: string, include: Prisma.ExerciseInclude | undefined = undefined): Promise<Tag | undefined> {
return await db.exercise.findUnique({
async get(name: string, include: Prisma.TagInclude | undefined = undefined): Promise<Tag | undefined> {
return await db.tag.findUnique({
where : {
id: name
name: name
},
include: include
}) as unknown as Tag ?? undefined;
......
......@@ -49,11 +49,11 @@ class ParamsCallbackManager {
this.listenParam('tagId', backend, (TagManager.get as GetFunction).bind(TagManager), [ {
} ], 'tag');
} ], 'tags');
this.listenParam('tagProposalName', backend, (TagManager.get as GetFunction).bind(TagManager), [ {
} ], 'tag');
} ], 'tags');
}
}
......
......@@ -5,6 +5,7 @@ import SessionRoutes from './SessionRoutes.js';
import AssignmentRoutes from './AssignmentRoutes.js';
import GitlabRoutes from './GitlabRoutes.js';
import ExerciseRoutes from './ExerciseRoutes.js';
import TagsRoutes from './TagsRoutes';
class AdminRoutesManager implements RoutesManager {
......@@ -14,6 +15,7 @@ class AdminRoutesManager implements RoutesManager {
GitlabRoutes.registerOnBackend(backend);
AssignmentRoutes.registerOnBackend(backend);
ExerciseRoutes.registerOnBackend(backend);
TagsRoutes.registerOnBackend(backend);
}
}
......
......@@ -18,7 +18,7 @@ enum SubmitStatus{
}
class TagRoutes implements RoutesManager {
private readonly tagsValidator: ExpressValidator.Schema = {
private readonly tagsValidatorNameType: ExpressValidator.Schema = {
name: {
trim: true,
notEmpty: true
......@@ -29,21 +29,26 @@ class TagRoutes implements RoutesManager {
}
};
registerOnBackend(backend: Express) {
backend.post('/tags', SecurityMiddleware.check(true, SecurityCheckType.TEACHING_STAFF), ParamsValidatorMiddleware.validate(this.tagsValidator), this.addTag.bind(this));
backend.delete('/tags/:tagId', SecurityMiddleware.check(true, SecurityCheckType.ADMIN), ParamsValidatorMiddleware.validate(this.tagsValidator), this.deleteTag.bind(this));
backend.get('/tags/proposals/state?', SecurityMiddleware.check(true, SecurityCheckType.ADMIN), ParamsValidatorMiddleware.validate(this.tagsValidator), this.getSubmittedTag.bind(this));
backend.post('/tags/proposals', SecurityMiddleware.check(true, SecurityCheckType.TEACHING_STAFF), ParamsValidatorMiddleware.validate(this.tagsValidator), this.SubmitTag.bind(this));
backend.patch('/tags/proposals/:tagProposalName', SecurityMiddleware.check(true, SecurityCheckType.ADMIN), ParamsValidatorMiddleware.validate(this.tagsValidator), this.validateTag.bind(this));
private readonly tagsValidatorStatus: ExpressValidator.Schema = {
status: {
trim: true,
notEmpty: true
},
};
registerOnBackend(backend: Express) {
backend.post('/tags', SecurityMiddleware.check(true, SecurityCheckType.TEACHING_STAFF), ParamsValidatorMiddleware.validate(this.tagsValidatorNameType), this.addTag.bind(this));
backend.delete('/tags/:tageName', SecurityMiddleware.check(true, SecurityCheckType.ADMIN), this.deleteTag.bind(this));
backend.get('/tags/proposals/state', SecurityMiddleware.check(true, SecurityCheckType.ADMIN), this.getSubmittedTag.bind(this)); //Check ?
backend.post('/tags/proposals', SecurityMiddleware.check(true, SecurityCheckType.TEACHING_STAFF), ParamsValidatorMiddleware.validate(this.tagsValidatorNameType), this.SubmitTag.bind(this));
backend.patch('/tags/proposals/:tagProposalName', SecurityMiddleware.check(true, SecurityCheckType.ADMIN), ParamsValidatorMiddleware.validate(this.tagsValidatorStatus), this.validateTag.bind(this));
}
private async addTag(req: express.Request, res: express.Response) {
const tagName = req.body.name
const tagType = req.body.type
console.log("Popipo");
if(tagType != TagType.USERDEFINED && !req.session.profile.isAdmin) {
console.log("Hehehehe");
return req.session.sendResponse(res, StatusCodes.FORBIDDEN);
}
......@@ -56,13 +61,12 @@ class TagRoutes implements RoutesManager {
}
})
return req.session.sendResponse(res, StatusCodes.OK, {
tag : (req.boundParams.tag as Tags),
tag : req.body.type,
name : req.body.name
}, "Tag ajouté avec succès");
}
private async deleteTag(req: express.Request, res: express.Response) {
console.log("DELETE");
const tagName = req.body.name
const tagName = req.params.name
db.tag.delete({
where : { name: tagName }
......@@ -70,21 +74,22 @@ class TagRoutes implements RoutesManager {
return req.session.sendResponse(res, StatusCodes.OK, "Tag supprimé avec succès");
}
private async getSubmittedTag(req: express.Request, res: express.Response) {
const tagName = req.body.name
const state = req.params.name
db.submissionTag.findMany({
where : {
name: tagName
},
state: state
}
})
return req.session.sendResponse(res, StatusCodes.OK, {
name : req.body.name,
tag : (req.boundParams.tag as Tags)
tag : req.body.type
});
}
private async SubmitTag(req: express.Request, res: express.Response) {
const tagName = req.body.name
const tagType = req.body.type
const tagState = req.body.state
db.submissionTag.upsert({
where : { name: tagName },
......@@ -92,12 +97,13 @@ class TagRoutes implements RoutesManager {
create: {
name : tagName,
type : tagType,
state : tagState
}
})
return req.session.sendResponse(res, StatusCodes.OK, {
name : req.body.name,
tag : (req.boundParams.tag as Tags)
tag : req.body.tag
});
}
private async validateTag(req: express.Request, res: express.Response) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment