< Summary

Information
Class: Syki.Daemon.Tasks.LinkOldNotificationsHandler
Assembly: Daemon
File(s): /home/runner/work/syki/syki/Daemon/Tasks/LinkOldNotificationsHandler.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 29
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/Daemon/Tasks/LinkOldNotificationsHandler.cs

#LineLine coverage
 1using Syki.Back.Features.Cross.LinkOldNotifications;
 2using Syki.Back.Features.Academic.CreateNotification;
 3
 4namespace Syki.Daemon.Tasks;
 5
 1776public class LinkOldNotificationsHandler(SykiDbContext ctx) : ISykiTaskHandler<LinkOldNotifications>
 7{
 8    public async Task Handle(LinkOldNotifications task)
 9    {
 17710        var isStudent = await ctx.Students.AnyAsync(s => s.Id == task.UserId);
 17711        var group = isStudent ? UsersGroup.Students : UsersGroup.Teachers;
 12
 17713        var userNotifications = await ctx.UserNotifications
 17714            .Where(x => x.UserId == task.UserId)
 17715            .Select(x => x.NotificationId)
 17716            .ToListAsync();
 17
 17718        var notifications = await ctx.Notifications.AsNoTracking()
 17719            .Where(x => x.InstitutionId == task.InstitutionId && (x.Target == group || x.Target == UsersGroup.All) && x.
 17720            .ToListAsync();
 21
 36222        foreach (var notification in notifications)
 23        {
 424            ctx.Add(new UserNotification(task.UserId, notification.Id));
 25        }
 26
 17727        await ctx.SaveChangesAsync();
 17728    }
 29}