(userId: string, name: string, month: string, value: number)
| 87 | } |
| 88 | |
| 89 | static async create(userId: string, name: string, month: string, value: number) { |
| 90 | const extra: Budget['extra'] = { |
| 91 | usedValue: 0, |
| 92 | availableValue: value, |
| 93 | }; |
| 94 | |
| 95 | const newBudget = (await db.query<Budget>( |
| 96 | sql`INSERT INTO "bewcloud_budgets" ( |
| 97 | "user_id", |
| 98 | "name", |
| 99 | "month", |
| 100 | "value", |
| 101 | "extra" |
| 102 | ) VALUES ($1, $2, $3, $4, $5) |
| 103 | RETURNING *`, |
| 104 | [ |
| 105 | userId, |
| 106 | name, |
| 107 | month, |
| 108 | value, |
| 109 | JSON.stringify(extra), |
| 110 | ], |
| 111 | ))[0]; |
| 112 | |
| 113 | // Numeric values come as strings, so we need to convert them to numbers |
| 114 | return { |
| 115 | ...newBudget, |
| 116 | value: Number(newBudget.value), |
| 117 | }; |
| 118 | } |
| 119 | |
| 120 | static async update( |
| 121 | budget: Budget, |
no outgoing calls
no test coverage detected