Added better datetime and fixed transaction fetching for beginning of month, I think, added edit and delete of transactions and categories
This commit is contained in:
@@ -232,3 +232,38 @@ pub fn putBudgetCategory(req: *httpz.Request, res: *httpz.Response) !void {
|
||||
try handler.returnData(updated_budget_cat.?, res);
|
||||
return;
|
||||
}
|
||||
|
||||
const deleteIdReq = struct {
|
||||
id: u32,
|
||||
};
|
||||
|
||||
pub fn deleteBudgetCategory(req: *httpz.Request, res: *httpz.Response) !void {
|
||||
var db = handler.getDb();
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
const body = handler.getReqJson(req, res, deleteIdReq) catch {
|
||||
return;
|
||||
};
|
||||
|
||||
const budget_category = try db.selectOneById(models.BudgetCategory, allocator, body.id);
|
||||
if (budget_category == null) {
|
||||
return handler.returnError("Cannot find budget", 404, res);
|
||||
}
|
||||
const budget = try db.selectOneById(models.Budget, allocator, budget_category.?.budget_id);
|
||||
if (budget == null) {
|
||||
return handler.returnError("Cannot find budget", 404, res);
|
||||
}
|
||||
|
||||
_ = auth.verifyRequest(req, res, null, budget.?.family_id) catch {
|
||||
return;
|
||||
};
|
||||
|
||||
try db.updateHideById(models.BudgetCategory, true, body.id);
|
||||
|
||||
const updated_budget_category = try db.selectOneById(models.BudgetCategory, allocator, body.id);
|
||||
if (budget_category == null) {
|
||||
return handler.returnError("Could not delete category", 500, res);
|
||||
}
|
||||
return try handler.returnData(updated_budget_category.?, res);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user