Refactored UI
Added Role filed to user table and endpoint implementation
This commit is contained in:
@@ -17,13 +17,21 @@ public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext
|
||||
{
|
||||
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var recipient = await context.TenantUsers.AsNoTracking()
|
||||
.Include(i => i.User)
|
||||
.Include(i => i.Tenant)
|
||||
.FirstOrDefaultAsync(u => u.UserId == request.Recipient && u.Status == ActivityStatus.Active && u.Tenant!.Status == ActivityStatus.Active);
|
||||
|
||||
if (recipient is null)
|
||||
return Result.Fail(ValidationError.Create("Tenant or User is not active, invite not sent"));
|
||||
|
||||
var invite = new Domain.Entities.Invite
|
||||
{
|
||||
OrganisationId = request.OrganisationId,
|
||||
InvitedOrganisationId = request.InvitedOrganisationId,
|
||||
AwardId = request.AwardId,
|
||||
ContractId = request.ContractId,
|
||||
Recipient = request.Recipient,
|
||||
Recipient = recipient.UserId,
|
||||
CreatedBy = userId,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
TenantId = tenantContext.TenantId
|
||||
@@ -31,13 +39,13 @@ public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext
|
||||
|
||||
context.Invites.Add(invite);
|
||||
|
||||
var notificationRequest = new CreateNotificationRequest(request.InvitedOrganisationId, request.Recipient,
|
||||
request.Platform, "Invitation to Onboard", string.Empty, request.Message);
|
||||
var notificationRequest = new CreateNotificationRequest(request.InvitedOrganisationId, recipient.UserId,
|
||||
request.Platform, "Funding award invite", recipient!.User!.Email, request.Message);
|
||||
|
||||
var notificationResult = await CreateNotificationAsync(notificationRequest, userId, cancellationToken);
|
||||
|
||||
return Result.FailIf(await context.SaveChangesAsync(cancellationToken) <= 0 && notificationResult.IsFailed,
|
||||
CreateError.Create().CausedBy(notificationResult.Errors))
|
||||
CreateError.Create("Failed to create invite, contact support").CausedBy(notificationResult.Errors))
|
||||
.ToResult(invite.Map());
|
||||
}));
|
||||
|
||||
@@ -60,9 +68,11 @@ public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext
|
||||
{
|
||||
await using var context = await contextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var invite = await context.Invites.AsNoTracking().FirstOrDefaultAsync(i => i.Recipient == applicantUserId, cancellationToken);
|
||||
var invite = await context.Invites.AsNoTracking()
|
||||
.OrderByDescending(o => o.Id)
|
||||
.FirstOrDefaultAsync(i => i.Recipient == applicantUserId, cancellationToken);
|
||||
|
||||
return Result.FailIf(invite is null, NotFoundError.New)
|
||||
return Result.FailIf(invite is null, NotFoundError.Create("No active invite found"))
|
||||
.ToResult(invite!.Map());
|
||||
}));
|
||||
|
||||
@@ -97,7 +107,8 @@ public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext
|
||||
TenantId = tenantContext.TenantId
|
||||
});
|
||||
|
||||
return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0, CreateError.Create("Failed to create entry"));
|
||||
return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0,
|
||||
CreateError.Create("Failed to create entry, contact support"));
|
||||
}));
|
||||
|
||||
public async Task<Result> UpdateNotificationAsync(UpdateNotificationRequest request, CancellationToken cancellationToken = default) =>
|
||||
@@ -114,7 +125,7 @@ public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext
|
||||
.SetProperty(u => u.UpdatedAt, DateTime.UtcNow)
|
||||
.SetProperty(u => u.Status, request.Status), cancellationToken);
|
||||
|
||||
return Result.OkIf(changedTotal > 0, UpdateError.Create($"Failed to update notification: {request.NotificationId}"));
|
||||
return Result.OkIf(changedTotal > 0, UpdateError.Create($"Failed to update notification: {request.NotificationId}, contact support"));
|
||||
}));
|
||||
|
||||
public async Task<Result<Notification[]>> GetNotificationsAsync(string organisationIdHash, CancellationToken cancellationToken = default) =>
|
||||
@@ -150,7 +161,7 @@ public sealed class CommunicationsService(IDbContextFactory<ApplicationDbContext
|
||||
var notification = await context.Notifications.AsNoTracking()
|
||||
.FirstOrDefaultAsync(n => n.Id == decodeResult.Value, cancellationToken);
|
||||
|
||||
return Result.FailIf(notification is null, NotFoundError.New)
|
||||
return Result.FailIf(notification is null, NotFoundError.Create("Notification not found"))
|
||||
.ToResult(notification!.Map());
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user