< 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: 4_16869239191
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
 4348public class LinkOldNotificationsCommandHandler(SykiDbContext ctx) : ICommandHandler<LinkOldNotificationsCommand>
 9{
 10    public async Task Handle(CommandId commandId, LinkOldNotificationsCommand command)
 11    {
 43412        var isStudent = await ctx.Students.AnyAsync(s => s.Id == command.UserId);
 43413        var group = isStudent ? UsersGroup.Students : UsersGroup.Teachers;
 14
 43415        var userNotifications = await ctx.UserNotifications
 43416            .Where(x => x.UserId == command.UserId)
 43417            .Select(x => x.NotificationId)
 43418            .ToListAsync();
 19
 43420        var notifications = await ctx.Notifications
 43421            .Where(x => x.InstitutionId == command.InstitutionId && x.Timeless && (x.Target == group || x.Target == User
 43422            .Select(x => new { x.Id })
 43423            .ToListAsync();
 24
 88425        foreach (var notification in notifications)
 26        {
 827            ctx.Add(new UserNotification(command.UserId, notification.Id));
 28        }
 43429    }
 30}