Skip to content

Commit

Permalink
feat(invitation): add notif when group receive invitation
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainGuarinoni committed Mar 28, 2022
1 parent 17c72e1 commit 15452fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
22 changes: 20 additions & 2 deletions api/controllers/profil/invitation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { getRepository } from 'typeorm';
import { Groups, Instrument, Invitation, MusicianGroup } from '../../entity';
import {
Groups,
Instrument,
Invitation,
MusicianGroup,
GroupReceiveInvitationNotification,
} from '../../entity';
import type core from 'express-serve-static-core';
import type { Request } from 'express';
import type { NextFunction } from 'express';
Expand Down Expand Up @@ -165,7 +171,10 @@ export const postUserToGroupInvitation = async (
}

const group = await getRepository(Groups).findOne({
id: groupId,
where: {
id: groupId,
},
relations: ['members', 'members.musician'],
});

if (!group) {
Expand Down Expand Up @@ -199,6 +208,15 @@ export const postUserToGroupInvitation = async (

await invitationRepo.save(newInvition);

const notifications = group.members.map((member) =>
getRepository(GroupReceiveInvitationNotification).create({
musician: member.musician,
group: group,
}),
);

await getRepository(GroupReceiveInvitationNotification).save(notifications);

return res.sendStatus(201);
} catch (err) {
next(err);
Expand Down
1 change: 1 addition & 0 deletions api/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export { GroupKickNotification } from './notifications/group/GroupKickNotificati
export { EventDeletedNotification } from './notifications/event/EventDeletedNotification';
export { EventGroupJoin } from './notifications/event/EventGroupJoin';
export { EventGroupKickNotification } from './notifications/event/EventGroupKickNotification';
export { GroupReceiveInvitationNotification } from './notifications/invitation/GroupReceiveInvitationNotification';
export { Invitation } from './Invitation';
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Groups, Notification } from '../../index';
import { ChildEntity, ManyToOne } from 'typeorm';

/**
* @description This notification is used when a group or a musician
* has receive an invitation
*/

@ChildEntity()
export class GroupReceiveInvitationNotification extends Notification {
@ManyToOne(() => Groups, {
onDelete: 'CASCADE',
nullable: true,
})
group: Groups;
}

0 comments on commit 15452fb

Please sign in to comment.