feat: integrate notification system across PO,store,supplier claims,delivery task and ride

This commit is contained in:
2026-10-20 16:49:05 +05:30
parent d1c3d4e22f
commit a0df2a1bbf
6 changed files with 147 additions and 2 deletions
+15 -1
View File
@@ -1,3 +1,4 @@
using Distribution.Features.Notifications;
using Distribution.Features.Scheme;
using Distribution.Features.Stock;
using Distribution.Infra.Authorization;
@@ -6,7 +7,7 @@ using Distribution.Models;
namespace Distribution.Features.Store;
public class StoreService(IStoreRepository repo, IUnitOfWork uow, ICurrentUserService currentUser, IScopeAccessService scopeAccess, SchemeService schemeService, Route.IRouteRepository routeRepo)
public class StoreService(IStoreRepository repo, IUnitOfWork uow, ICurrentUserService currentUser, IScopeAccessService scopeAccess, SchemeService schemeService, Route.IRouteRepository routeRepo, INotificationService notifications)
{
private const int GlobalScopeRoleLevel = 50;
private const int CreditApproverRoleLevel = 20;
@@ -147,6 +148,7 @@ public class StoreService(IStoreRepository repo, IUnitOfWork uow, ICurrentUserSe
var store = await repo.GetByIdAsync(id);
if (store is null || !store.IsActive) return null;
if (!await HasStoreScopeAsync(id)) return null;
var wasWithinLimit = store.OutstandingBalance <= store.CreditLimit;
store.OutstandingBalance = request.NewBalance;
await uow.BeginAsync(ct);
try
@@ -159,6 +161,18 @@ public class StoreService(IStoreRepository repo, IUnitOfWork uow, ICurrentUserSe
await uow.RollbackAsync(ct);
throw;
}
// Only on the crossing, so repeated updates while over the limit don't re-alert.
if (store.CreditLimit > 0 && wasWithinLimit && store.OutstandingBalance > store.CreditLimit)
await notifications.NotifyAsync(
NotificationTypes.CreditLimitBreached,
[
RecipientRule.RouteOwner(ScopeKind.Store, store.Id),
RecipientRule.PermissionInScope("store.manage", ScopeKind.Store, store.Id),
],
new NotificationArgs(new { store.StoreName }, "Store", store.Id, $"/stores/{store.Id}", currentUser.UserId),
ct);
return ToResponse(store);
}