MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / update

Method update

lib/models/expenses.ts:313–345  ·  view source on GitHub ↗
(expense: Expense)

Source from the content-addressed store, hash-verified

311 }
312
313 static async update(expense: Expense) {
314 const existingBudgetInMonth = await BudgetModel.getByName(
315 expense.user_id,
316 expense.date.substring(0, 7),
317 expense.budget,
318 );
319
320 if (!existingBudgetInMonth) {
321 await BudgetModel.create(expense.user_id, expense.budget, expense.date.substring(0, 7), 100);
322 }
323
324 await db.query(
325 sql`UPDATE "bewcloud_expenses" SET
326 "cost" = $2,
327 "description" = $3,
328 "budget" = $4,
329 "date" = $5,
330 "is_recurring" = $6,
331 "extra" = $7
332 WHERE "id" = $1`,
333 [
334 expense.id,
335 expense.cost,
336 expense.description,
337 expense.budget,
338 expense.date,
339 expense.is_recurring,
340 JSON.stringify(expense.extra),
341 ],
342 );
343
344 await recalculateMonthBudgets(expense.user_id, expense.date.substring(0, 7));
345 }
346
347 static async delete(userId: string, id: string) {
348 const expense = await this.getById(userId, id);

Callers

nothing calls this directly

Calls 4

recalculateMonthBudgetsFunction · 0.85
queryMethod · 0.80
getByNameMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected