split getUser into helper
This commit is contained in:
parent
f49e59bb47
commit
eb001b39a4
1 changed files with 13 additions and 7 deletions
|
@ -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,
|
error.NotFound => error.Unexpected,
|
||||||
else => err,
|
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);
|
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{
|
return UserResponse{
|
||||||
.id = user.id,
|
.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 {
|
pub fn createNote(self: *Self, content: []const u8) !NoteResponse {
|
||||||
// You cannot post on admin accounts
|
// You cannot post on admin accounts
|
||||||
if (self.community.kind == .admin) return error.WrongCommunity;
|
if (self.community.kind == .admin) return error.WrongCommunity;
|
||||||
|
|
Loading…
Reference in a new issue