Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null ref #58

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task SyncSSO()

// Get and check user verification:
var user = await _iUserRepository.GetByDiscordIdAsync(Context.User.Id, Context.Guild.Id);
if (!user.Verified)
if (user == null || !user.Verified)
{
ButtonBuilder getStartedButton = new ButtonBuilder();
getStartedButton.WithLabel("Get Started");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public interface IUserRepository
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<DataTables.User> GetByBsonIdAsync(string id);
Task<DataTables.User?> GetByBsonIdAsync(string id);
/// <summary>
/// Get user by Discord ID
/// Only shows users from specific guild.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<DataTables.User> GetByDiscordIdAsync(ulong userID, ulong guildID);
Task<DataTables.User?> GetByDiscordIdAsync(ulong userID, ulong guildID);
/// <summary>
/// Get users with a linq filter
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions CCSODiscordBot/Services/Database/Repository/UserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public async Task CreateNewUserAsync(DataTables.User newGuild)
{
return await _userCollection.Find(_ => true).ToListAsync();
}
public async Task<DataTables.User> GetByBsonIdAsync(string id)
public async Task<DataTables.User?> GetByBsonIdAsync(string id)
{
return await _userCollection.Find(_ => _.Id == id).FirstOrDefaultAsync();
}
public async Task<DataTables.User> GetByDiscordIdAsync(ulong userID, ulong guildID)
public async Task<DataTables.User?> GetByDiscordIdAsync(ulong userID, ulong guildID)
{
return await _userCollection.Find(_ => _.DiscordID == userID && _.DiscordGuildID == guildID).FirstOrDefaultAsync();
}
Expand Down
Loading