split getUser into helper

This commit is contained in:
jaina heartles 2022-12-09 22:37:03 -08:00
parent f49e59bb47
commit eb001b39a4

View file

@ -434,19 +434,14 @@ fn ApiConn(comptime DbConn: type) type {
},
}
return self.getUser(user_id) catch |err| switch (err) {
return self.getUserUnchecked(user_id) catch |err| switch (err) {
error.NotFound => error.Unexpected,
else => err,
};
}
pub fn getUser(self: *Self, user_id: Uuid) !UserResponse {
fn getUserUnchecked(self: *Self, user_id: Uuid) !UserResponse {
const user = try services.actors.get(self.db, user_id, self.allocator);
errdefer util.deepFree(self.allocator, user);
if (self.user_id == null) {
if (!Uuid.eql(self.community.id, user.community_id)) return error.NotFound;
}
return UserResponse{
.id = user.id,
@ -469,6 +464,17 @@ fn ApiConn(comptime DbConn: type) type {
};
}
pub fn getUser(self: *Self, user_id: Uuid) !UserResponse {
const user = try self.getUserUnchecked(user_id);
errdefer util.deepFree(self.allocator, user);
if (self.user_id == null) {
if (!Uuid.eql(self.community.id, user.community_id)) return error.NotFound;
}
return user;
}
pub fn createNote(self: *Self, content: []const u8) !NoteResponse {
// You cannot post on admin accounts
if (self.community.kind == .admin) return error.WrongCommunity;