Fix transaction use

This commit is contained in:
jaina heartles 2022-12-10 01:40:53 -08:00
parent 766878432b
commit c6af6caec7

View file

@ -439,14 +439,18 @@ fn ApiConn(comptime DbConn: type) type {
}, },
} }
return self.getUserUnchecked(user_id) catch |err| switch (err) { const user = self.getUserUnchecked(tx, user_id) catch |err| switch (err) {
error.NotFound => error.Unexpected, error.NotFound => return error.Unexpected,
else => err, else => |e| return e,
}; };
errdefer util.deepFree(self.allocator, user);
try tx.commit();
return user;
} }
fn getUserUnchecked(self: *Self, user_id: Uuid) !UserResponse { fn getUserUnchecked(self: *Self, db: anytype, user_id: Uuid) !UserResponse {
const user = try services.actors.get(self.db, user_id, self.allocator); const user = try services.actors.get(db, user_id, self.allocator);
return UserResponse{ return UserResponse{
.id = user.id, .id = user.id,
@ -470,7 +474,7 @@ fn ApiConn(comptime DbConn: type) type {
} }
pub fn getUser(self: *Self, user_id: Uuid) !UserResponse { pub fn getUser(self: *Self, user_id: Uuid) !UserResponse {
const user = try self.getUserUnchecked(user_id); const user = try self.getUserUnchecked(self.db, user_id);
errdefer util.deepFree(self.allocator, user); errdefer util.deepFree(self.allocator, user);
if (self.user_id == null) { if (self.user_id == null) {