diff --git a/api/controllers/profil/index.ts b/api/controllers/profil/index.ts index 5d7b5c90..40cd5bc3 100644 --- a/api/controllers/profil/index.ts +++ b/api/controllers/profil/index.ts @@ -10,4 +10,5 @@ export { getUserInvitationsReceived, getUserInvitationsSent, postUserToGroupInvitation, + deleteInvitationById, } from './invitation'; diff --git a/api/controllers/profil/invitation.ts b/api/controllers/profil/invitation.ts index 4f1b1130..7b3615c7 100644 --- a/api/controllers/profil/invitation.ts +++ b/api/controllers/profil/invitation.ts @@ -4,11 +4,17 @@ import type core from 'express-serve-static-core'; import type { Request } from 'express'; import type { NextFunction } from 'express'; import type { operations } from '@schema'; -import type { getHTTPCode, getRequestBody, getResponsesBody } from '@typing'; +import type { + getHTTPCode, + getPathParams, + getRequestBody, + getResponsesBody, +} from '@typing'; type GetUserInvitationReceived = operations['getUserInvitationReceived']; type GetUserInvitationSent = operations['getUserInvitationSent']; type PostUserToGroupInvitation = operations['postUserToGroupInvitation']; +type DeleteProfilInvitationById = operations['deleteProfilInvitationById']; export const getUserInvitationsReceived = async ( req: Request<{}, getResponsesBody, {}, {}>, @@ -192,3 +198,46 @@ export const postUserToGroupInvitation = async ( next(err); } }; + +export const deleteInvitationById = async ( + req: Request< + getPathParams, + getResponsesBody, + {}, + {} + >, + res: core.Response< + getResponsesBody, + {}, + getHTTPCode + >, + next: NextFunction, +): Promise< + core.Response< + getResponsesBody, + {}, + getHTTPCode + > +> => { + try { + const invationId = req.params.invitationId; + const invitationRepository = getRepository(Invitation); + + const invitation = await invitationRepository.findOne({ + id: invationId, + type: 'musicianToGroup', + }); + + if (!invitation) { + return res.status(404).json({ msg: 'E_INVITATION_DOES_NOT_EXIST' }); + } + + await invitationRepository.delete({ + id: invationId, + }); + + return res.sendStatus(204); + } catch (err) { + next(err); + } +}; diff --git a/api/docs/openApiDoc.ts b/api/docs/openApiDoc.ts index 0773b67e..b5f25f82 100644 --- a/api/docs/openApiDoc.ts +++ b/api/docs/openApiDoc.ts @@ -1564,6 +1564,37 @@ const openApiDocs: OpenAPIV3.Document = { }, }, }, + '/profil/invitations/{invitationId}': { + delete: { + operationId: 'deleteProfilInvitationById', + tags: ['profil'], + security: [{ BearerAuth: [] }], + description: 'Delete a musician to group invitation by its id', + parameters: [ + { + in: 'path', + description: 'the invitation id', + name: 'invitationId', + schema: { type: 'string' }, + required: true, + }, + ], + responses: { + '204': { + description: 'The invitations hbas been deleted', + content: { 'application/json': { schema: { type: 'string' } } }, + }, + '404': { + description: 'the invitation does not exist', + content: { + 'application/json': { + schema: { $ref: '#/components/schemas/httpError' }, + }, + }, + }, + }, + }, + }, '/profil/invitations/received': { get: { operationId: 'getUserInvitationReceived', diff --git a/api/docs/schemas/profil/invitation/invitation.ts b/api/docs/schemas/profil/invitation/invitation.ts new file mode 100644 index 00000000..f976bbc2 --- /dev/null +++ b/api/docs/schemas/profil/invitation/invitation.ts @@ -0,0 +1,46 @@ +import { HandlerDefinition } from '@typing'; + +const schema: HandlerDefinition = { + path: '/profil/invitations/{invitationId}', + delete: { + operationId: 'deleteProfilInvitationById', + tags: ['profil'], + security: [{ BearerAuth: [] }], + description: 'Delete a musician to group invitation by its id', + parameters: [ + { + in: 'path', + description: 'the invitation id', + name: 'invitationId', + schema: { + type: 'string', + }, + required: true, + }, + ], + responses: { + 204: { + description: 'The invitations hbas been deleted', + content: { + 'application/json': { + schema: { + type: 'string', + }, + }, + }, + }, + 404: { + description: 'the invitation does not exist', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/httpError', + }, + }, + }, + }, + }, + }, +}; + +export default schema; diff --git a/api/routes/profil.ts b/api/routes/profil.ts index a2320aef..75e529f2 100644 --- a/api/routes/profil.ts +++ b/api/routes/profil.ts @@ -22,5 +22,9 @@ router.get( profilController.getUserInvitationsReceived, ); router.post('/invitations', profilController.postUserToGroupInvitation); +router.delete( + '/invitations/:invitationId', + profilController.deleteInvitationById, +); export default router; diff --git a/api/server/server.ts b/api/server/server.ts index 6e5acd7d..71628fc7 100644 --- a/api/server/server.ts +++ b/api/server/server.ts @@ -64,7 +64,7 @@ app.use( OpenApiValidator.middleware({ apiSpec: openApiDocs, validateRequests: true, - validateResponses: false, + validateResponses: true, }), ); diff --git a/api/types/schema.ts b/api/types/schema.ts index 34d72b63..3be23650 100644 --- a/api/types/schema.ts +++ b/api/types/schema.ts @@ -110,6 +110,10 @@ export interface paths { /** Leave a group */ post: operations["leaveGroup"]; }; + "/profil/invitations/{invitationId}": { + /** Delete a musician to group invitation by its id */ + delete: operations["deleteProfilInvitationById"]; + }; "/profil/invitations/received": { /** Get all the invitation received by the logged user */ get: operations["getUserInvitationReceived"]; @@ -1128,6 +1132,29 @@ export interface operations { }; }; }; + /** Delete a musician to group invitation by its id */ + deleteProfilInvitationById: { + parameters: { + path: { + /** the invitation id */ + invitationId: string; + }; + }; + responses: { + /** The invitations hbas been deleted */ + 204: { + content: { + "application/json": string; + }; + }; + /** the invitation does not exist */ + 404: { + content: { + "application/json": components["schemas"]["httpError"]; + }; + }; + }; + }; /** Get all the invitation received by the logged user */ getUserInvitationReceived: { responses: {