mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 05:30:13 +01:00
feat: return organisationId if user is an organization
this will help to determine if an event is created by the user or not
This commit is contained in:
@@ -11,4 +11,15 @@ namespace WebApp.DTOs
|
||||
[Required] DateTime CreatedAt,
|
||||
[Required] bool isOrganisation
|
||||
);
|
||||
|
||||
public record class UserSummaryWithOrgIdDto
|
||||
(
|
||||
[Required] int UserId,
|
||||
[Required] string Email,
|
||||
[Required] string FirstName,
|
||||
[Required] string LastName,
|
||||
[Required] DateTime CreatedAt,
|
||||
[Required] bool isOrganisation,
|
||||
int? OrganisationId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,10 @@ namespace WebApp.Endpoints
|
||||
return Results.Json(new {message = "No user found."}, statusCode: 404);
|
||||
}
|
||||
|
||||
Organisation? org = await guh.GetOrganisationFromUserId(user.UserId);
|
||||
if (org is not null) return Results.Ok(user.ToUserSummaryWithOrgIdDto(org.OrganisationId));
|
||||
return Results.Ok(user.ToUserSummaryDto());
|
||||
|
||||
})
|
||||
.WithName(GetUserEndpointName);
|
||||
|
||||
|
||||
@@ -54,6 +54,12 @@ public class GeneralUseHelpers
|
||||
return org;
|
||||
}
|
||||
|
||||
async public Task<Organisation?> GetOrganisationFromUserId(int userId)
|
||||
{
|
||||
Organisation? org = await _context.Organisations.FirstOrDefaultAsync(o => o.UserId == userId);
|
||||
return org;
|
||||
}
|
||||
|
||||
public string? GetTokenStrFromHTTPContext(HttpContext httpContext)
|
||||
{
|
||||
var cookies = httpContext.Request.Cookies;
|
||||
|
||||
@@ -16,5 +16,18 @@ namespace WebApp.Mapping
|
||||
user.IsOrganisation
|
||||
);
|
||||
}
|
||||
|
||||
public static UserSummaryWithOrgIdDto ToUserSummaryWithOrgIdDto(this User user, int OrganisationId)
|
||||
{
|
||||
return new UserSummaryWithOrgIdDto(
|
||||
user.UserId,
|
||||
user.Email,
|
||||
user.FirstName,
|
||||
user.LastName,
|
||||
user.CreatedAt,
|
||||
user.IsOrganisation,
|
||||
OrganisationId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user