< Summary - Syki

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_InstitutionId()100%11100%

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")]
 30466public record LinkOldNotificationsCommand(Guid InstitutionId, Guid UserId) : ICommand;
 7
 8public class LinkOldNotificationsCommandHandler(SykiDbContext ctx) : ICommandHandler<LinkOldNotificationsCommand>
 9{
 10    public async Task Handle(CommandId commandId, LinkOldNotificationsCommand command)
 11    {
 12        var isStudent = await ctx.Students.AnyAsync(s => s.Id == command.UserId);
 13        var group = isStudent ? UsersGroup.Students : UsersGroup.Teachers;
 14
 15        var userNotifications = await ctx.UserNotifications
 16            .Where(x => x.UserId == command.UserId)
 17            .Select(x => x.NotificationId)
 18            .ToListAsync();
 19
 20        var notifications = await ctx.Notifications
 21            .Where(x => x.InstitutionId == command.InstitutionId && x.Timeless && (x.Target == group || x.Target == User
 22            .Select(x => new { x.Id })
 23            .ToListAsync();
 24
 25        foreach (var notification in notifications)
 26        {
 27            ctx.Add(new UserNotification(command.UserId, notification.Id));
 28        }
 29    }
 30}

Methods/Properties

get_InstitutionId()