Skip to content

Commit

Permalink
feat(invitation): delete profil sent invitation
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainGuarinoni committed Mar 28, 2022
1 parent d00d30a commit cf82f9d
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/controllers/profil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export {
getUserInvitationsReceived,
getUserInvitationsSent,
postUserToGroupInvitation,
deleteInvitationById,
} from './invitation';
51 changes: 50 additions & 1 deletion api/controllers/profil/invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetUserInvitationReceived>, {}, {}>,
Expand Down Expand Up @@ -192,3 +198,46 @@ export const postUserToGroupInvitation = async (
next(err);
}
};

export const deleteInvitationById = async (
req: Request<
getPathParams<DeleteProfilInvitationById>,
getResponsesBody<DeleteProfilInvitationById>,
{},
{}
>,
res: core.Response<
getResponsesBody<DeleteProfilInvitationById>,
{},
getHTTPCode<DeleteProfilInvitationById>
>,
next: NextFunction,
): Promise<
core.Response<
getResponsesBody<DeleteProfilInvitationById>,
{},
getHTTPCode<DeleteProfilInvitationById>
>
> => {
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);
}
};
31 changes: 31 additions & 0 deletions api/docs/openApiDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
46 changes: 46 additions & 0 deletions api/docs/schemas/profil/invitation/invitation.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 4 additions & 0 deletions api/routes/profil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ router.get(
profilController.getUserInvitationsReceived,
);
router.post('/invitations', profilController.postUserToGroupInvitation);
router.delete(
'/invitations/:invitationId',
profilController.deleteInvitationById,
);

export default router;
2 changes: 1 addition & 1 deletion api/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ app.use(
OpenApiValidator.middleware({
apiSpec: openApiDocs,
validateRequests: true,
validateResponses: false,
validateResponses: true,
}),
);

Expand Down
27 changes: 27 additions & 0 deletions api/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit cf82f9d

Please sign in to comment.