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:
Nathan Anderson
2023-08-02 01:12:32 -06:00
parent 37250a15fb
commit ef9a7d06e4
8 changed files with 2507 additions and 10 deletions
+35
View File
@@ -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);
}