< Summary - Syki

Information
Class: Syki.Back.Features.Cross.LinkOldNotifications.LinkOldNotificationsCommandHandler
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Cross/LinkOldNotifications/LinkOldNotificationsCommand.cs
Tag: 21_17346963026
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 30
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Handle()100%44100%

File(s)

/home/runner/work/syki/syki/Back/Features/Cross/LinkOldNotifications/LinkOldNotificationsCommand.cs

#LineLine coverage
 1using Syki.Back.Features.Academic.CreateNotification;
 2
 3namespace Syki.Back.Features.Cross.LinkOldNotifications;
 4
 5[CommandDescription("Vincular notificações ao novo usuário")]
 6public record LinkOldNotificationsCommand(Guid InstitutionId, Guid UserId) : ICommand;
 7
 4488public class LinkOldNotificationsCommandHandler(SykiDbContext ctx) : ICommandHandler<LinkOldNotificationsCommand>
 9{
 10    public async Task Handle(CommandId commandId, LinkOldNotificationsCommand command)
 11    {
 44812        var isStudent = await ctx.Students.AnyAsync(s => s.Id == command.UserId);
 44813        var group = isStudent ? UsersGroup.Students : UsersGroup.Teachers;
 14
 44815        var userNotifications = await ctx.UserNotifications
 44816            .Where(x => x.UserId == command.UserId)
 44817            .Select(x => x.NotificationId)
 44818            .ToListAsync();
 19
 44820        var notifications = await ctx.Notifications
 44821            .Where(x => x.InstitutionId == command.InstitutionId && x.Timeless && (x.Target == group || x.Target == User
 44822            .Select(x => new { x.Id })
 44823            .ToListAsync();
 24
 91225        foreach (var notification in notifications)
 26        {
 827            ctx.Add(new UserNotification(command.UserId, notification.Id));
 28        }
 44829    }
 30}