diff --git a/endpoints.json b/endpoints.json index 8111f8e..0a6cb77 100644 --- a/endpoints.json +++ b/endpoints.json @@ -2461,61 +2461,6 @@ }, "response": [] }, - { - "name": "Coordinator Scientific Activity", - "request": { - "method": "PUT", - "header": [ - { - "key": "Authorization", - "value": "{{coordinator_token}}", - "type": "text" - } - ], - "body": { - "mode": "formdata", - "formdata": [ - { - "key": "fullName", - "value": "Demo name", - "type": "text" - }, - { - "key": "publicationNumberWebOfScience", - "value": "", - "type": "text" - }, - { - "key": "committees", - "value": "", - "type": "text" - }, - { - "key": "conferences", - "value": "", - "type": "text" - }, - { - "key": "reportYear", - "value": "", - "type": "text" - } - ] - }, - "url": { - "raw": "{{host}}/api/coordinator/scientific-activity", - "host": [ - "{{host}}" - ], - "path": [ - "api", - "coordinator", - "scientific-activity" - ] - } - }, - "response": [] - }, { "name": "Coordinator Scientific Activity", "request": { @@ -2532,27 +2477,27 @@ "formdata": [ { "key": "fullName", - "value": "", + "value": "Demo Name", "type": "text" }, { "key": "publicationNumberWebOfScience", - "value": "", + "value": "323 I guess", "type": "text" }, { "key": "committees", - "value": "", + "value": "One", "type": "text" }, { "key": "conferences", - "value": "", + "value": "Conference", "type": "text" }, { "key": "reportYear", - "value": "", + "value": "2012", "type": "text" } ] @@ -2603,6 +2548,9 @@ "item": [ { "name": "Coordinator Referential Activity", + "protocolProfileBehavior": { + "disableBodyPruning": true + }, "request": { "method": "GET", "header": [ @@ -2612,6 +2560,10 @@ "type": "text" } ], + "body": { + "mode": "formdata", + "formdata": [] + }, "url": { "raw": "{{host}}/api/coordinator/scientific-activity", "host": [ @@ -2629,7 +2581,7 @@ { "name": "Coordinator Referential Activity", "request": { - "method": "PUT", + "method": "PATCH", "header": [ { "key": "Authorization", @@ -2642,22 +2594,22 @@ "formdata": [ { "key": "fullName", - "value": "", + "value": "Full Name", "type": "text" }, { "key": "thesisDomain", - "value": "", + "value": "Computer Science", "type": "text" }, { "key": "thesisReference", - "value": "", + "value": "Reference", "type": "text" }, { "key": "IOSUD", - "value": "", + "value": "ISOSU", "type": "text" } ] @@ -2676,49 +2628,6 @@ }, "response": [] }, - { - "name": "Coordinator Referential Activity", - "request": { - "method": "PATCH", - "header": [ - { - "key": "Authorization", - "value": "{{coordinator_token}}", - "type": "text" - } - ], - "url": { - "raw": "{{host}}/api/coordinator/scientific-activity?fullName&thesisDomain&thesisReference&IOSUD", - "host": [ - "{{host}}" - ], - "path": [ - "api", - "coordinator", - "scientific-activity" - ], - "query": [ - { - "key": "fullName", - "value": null - }, - { - "key": "thesisDomain", - "value": null - }, - { - "key": "thesisReference", - "value": null - }, - { - "key": "IOSUD", - "value": null - } - ] - } - }, - "response": [] - }, { "name": "Coordinator Referential Activity", "request": { diff --git a/src/app/controller/coordinator.forms.controller.ts b/src/app/controller/coordinator.forms.controller.ts index c7f2de7..64169b7 100644 --- a/src/app/controller/coordinator.forms.controller.ts +++ b/src/app/controller/coordinator.forms.controller.ts @@ -3,7 +3,6 @@ import {JwtService} from "../services/jwt.service"; import {Coordinator} from "../database/models"; import {CoordinatorFormsService} from "../service/coordinator.forms.service"; import {CoordinatorReferentialActivity, CoordinatorScientificActivity} from "../database/form.models"; -import {StatusCode} from "../services/rest.util"; export class CoordinatorFormsController { @@ -20,29 +19,13 @@ export class CoordinatorFormsController { } } - static async addCoordinatorScientificActivity(req: Request, res: Response, next: NextFunction) { - try { - const token = req.get('Authorization') as string; - const coordinator = JwtService.verifyToken(token) as Coordinator; - const body = req.body as CoordinatorScientificActivity; - - await CoordinatorFormsService.addCoordinatorScientificActivity(coordinator, body); - - res.statusCode = StatusCode.CREATED; - res.end(); - } catch (err) { - next(err); - } - } - static async updateCoordinatorScientificActivity(req: Request, res: Response, next: NextFunction) { try { const token = req.get('Authorization') as string; const coordinator = JwtService.verifyToken(token) as Coordinator; const body = req.body as CoordinatorScientificActivity; - const formId = req.params.id; - await CoordinatorFormsService.updateCoordinatorScientificActivity(coordinator, formId, body); + await CoordinatorFormsService.updateCoordinatorScientificActivity(coordinator, body); res.end(); } catch (err) { next(err); @@ -53,9 +36,8 @@ export class CoordinatorFormsController { try { const token = req.get('Authorization') as string; const coordinator = JwtService.verifyToken(token) as Coordinator; - const id = req.params.id; - await CoordinatorFormsService.deleteCoordinatorScientificActivity(coordinator, id); + await CoordinatorFormsService.deleteCoordinatorScientificActivity(coordinator); res.end(); } catch (err) { next(err); @@ -75,29 +57,13 @@ export class CoordinatorFormsController { } } - static async addCoordinatorReferentialActivity(req: Request, res: Response, next: NextFunction) { - try { - const token = req.get('Authorization') as string; - const coordinator = JwtService.verifyToken(token) as Coordinator; - const body = req.body as CoordinatorReferentialActivity; - - await CoordinatorFormsService.addCoordinatorReferentialActivity(coordinator, body); - - res.statusCode = StatusCode.CREATED; - res.end(); - } catch (err) { - next(err); - } - } - static async updateCoordinatorReferentialActivity(req: Request, res: Response, next: NextFunction) { try { const token = req.get('Authorization') as string; const coordinator = JwtService.verifyToken(token) as Coordinator; const body = req.body as CoordinatorReferentialActivity; - const formId = req.params.id; - await CoordinatorFormsService.updateCoordinatorReferentialActivity(coordinator, formId, body); + await CoordinatorFormsService.updateCoordinatorReferentialActivity(coordinator, body); res.end(); } catch (err) { next(err); @@ -108,9 +74,8 @@ export class CoordinatorFormsController { try { const token = req.get('Authorization') as string; const coordinator = JwtService.verifyToken(token) as Coordinator; - const id = req.params.id; - await CoordinatorFormsService.deleteCoordinatorReferentialActivity(coordinator, id); + await CoordinatorFormsService.deleteCoordinatorReferentialActivity(coordinator); res.end(); } catch (err) { next(err); diff --git a/src/app/endpoints/coordinator.endpoints.ts b/src/app/endpoints/coordinator.endpoints.ts index 62b5970..dc5820a 100644 --- a/src/app/endpoints/coordinator.endpoints.ts +++ b/src/app/endpoints/coordinator.endpoints.ts @@ -9,12 +9,10 @@ export function registerCoordinatorEndpoints(app: Express) { app.get(`${EndpointIdentifier.COORDINATOR_STUDENT_FORMS}/:identifier`, Middleware.coordinatorMiddleware, CoordinatorController.getStudentForms); app.get(EndpointIdentifier.COORDINATOR_SCIENTIFIC_ACTIVITY, Middleware.coordinatorMiddleware, CoordinatorFormsController.getCoordinatorScientificActivity); - app.post(EndpointIdentifier.COORDINATOR_SCIENTIFIC_ACTIVITY, Middleware.coordinatorMiddleware, CoordinatorFormsController.addCoordinatorScientificActivity); app.patch(EndpointIdentifier.COORDINATOR_SCIENTIFIC_ACTIVITY, Middleware.coordinatorMiddleware, CoordinatorFormsController.updateCoordinatorScientificActivity); app.delete(EndpointIdentifier.COORDINATOR_SCIENTIFIC_ACTIVITY, Middleware.coordinatorMiddleware, CoordinatorFormsController.deleteCoordinatorScientificActivity); app.get(EndpointIdentifier.COORDINATOR_REFERENTIAL_ACTIVITY, Middleware.coordinatorMiddleware, CoordinatorFormsController.getCoordinatorReferentialActivity); - app.post(EndpointIdentifier.COORDINATOR_REFERENTIAL_ACTIVITY, Middleware.coordinatorMiddleware, CoordinatorFormsController.addCoordinatorReferentialActivity); app.patch(EndpointIdentifier.COORDINATOR_REFERENTIAL_ACTIVITY, Middleware.coordinatorMiddleware, CoordinatorFormsController.updateCoordinatorReferentialActivity); app.delete(EndpointIdentifier.COORDINATOR_REFERENTIAL_ACTIVITY, Middleware.coordinatorMiddleware, CoordinatorFormsController.deleteCoordinatorReferentialActivity); diff --git a/src/app/service/coordinator.forms.service.ts b/src/app/service/coordinator.forms.service.ts index 2e800f8..66fdc6d 100644 --- a/src/app/service/coordinator.forms.service.ts +++ b/src/app/service/coordinator.forms.service.ts @@ -18,42 +18,33 @@ export class CoordinatorFormsService { })).map(item => item.toJSON()); } - static async addCoordinatorScientificActivity(coordinator: Coordinator, data: CoordinatorScientificActivity): Promise { - if (!UtilService.checkFormFields(data)) { - throw new ResponseError(ResponseMessage.FORM_FIELD_ERROR, StatusCode.BAD_REQUEST); - } - - await CoordinatorScientificActivityModel.create({ - ...data, - ownerId: coordinator.id, - }); - return; - } - - static async updateCoordinatorScientificActivity(coordinator: Coordinator, formId: number, data: CoordinatorScientificActivity): Promise { + static async updateCoordinatorScientificActivity(coordinator: Coordinator, data: CoordinatorScientificActivity): Promise { if (!UtilService.checkFormFields(data)) { throw new ResponseError(ResponseMessage.FORM_FIELD_ERROR, StatusCode.BAD_REQUEST); } const row = await CoordinatorScientificActivityModel.findOne({ where: { - id: formId, ownerId: coordinator.id, } }); if (row === null) { - throw new ResponseError(ResponseMessage.DATA_NOT_FOUND, StatusCode.NOT_FOUND); + await CoordinatorScientificActivityModel.create({ + ...data, + ownerId: coordinator.id, + }); + + return; } await row.set({...data}).save(); return; } - static async deleteCoordinatorScientificActivity(coordinator: Coordinator, formId: number): Promise { + static async deleteCoordinatorScientificActivity(coordinator: Coordinator): Promise { const row = await CoordinatorScientificActivityModel.findOne({ where: { - id: formId, ownerId: coordinator.id, } }); @@ -74,42 +65,32 @@ export class CoordinatorFormsService { })).map(item => item.toJSON()); } - static async addCoordinatorReferentialActivity(coordinator: Coordinator, data: CoordinatorReferentialActivity): Promise { - if (!UtilService.checkFormFields(data)) { - throw new ResponseError(ResponseMessage.FORM_FIELD_ERROR, StatusCode.BAD_REQUEST); - } - - await CoordinatorReferentialActivityModel.create({ - ...data, - ownerId: coordinator.id, - }); - return; - } - - static async updateCoordinatorReferentialActivity(coordinator: Coordinator, formId: number, data: CoordinatorReferentialActivity): Promise { + static async updateCoordinatorReferentialActivity(coordinator: Coordinator, data: CoordinatorReferentialActivity): Promise { if (!UtilService.checkFormFields(data)) { throw new ResponseError(ResponseMessage.FORM_FIELD_ERROR, StatusCode.BAD_REQUEST); } const row = await CoordinatorReferentialActivityModel.findOne({ where: { - id: formId, ownerId: coordinator.id, } }); if (row === null) { - throw new ResponseError(ResponseMessage.DATA_NOT_FOUND, StatusCode.NOT_FOUND); + await CoordinatorReferentialActivityModel.create({ + ...data, + ownerId: coordinator.id, + }); + return; } await row.set({...data}).save(); return; } - static async deleteCoordinatorReferentialActivity(coordinator: Coordinator, formId: number): Promise { + static async deleteCoordinatorReferentialActivity(coordinator: Coordinator): Promise { const row = await CoordinatorReferentialActivityModel.findOne({ where: { - id: formId, ownerId: coordinator.id, } });