Resolve "implement updating a category"

This commit is contained in:
Thomas Schleicher 2024-01-05 19:56:55 +00:00
parent 0ddfe3e606
commit d7bb318c24
6 changed files with 25 additions and 14 deletions

View file

@ -24,6 +24,18 @@ export const initDatabase = async () => {
}
};
export const updateCategory = async (guid: string, name: string, color: string, type: string, allocated_amount: number) => {
try {
await db.transactionAsync(async (tx) => {
await tx.executeSqlAsync("UPDATE category SET name = ?, color = ?, type = ?, allocated_amount = ? WHERE guid = ?", [name, color, type, allocated_amount, guid]);
});
} catch (error) {
console.log("Error updating category: ", error);
throw error;
}
};
export const addCategory = async (name: string, color: string, type: string, allocated_amount: number) => {
//needs user input validation for type and color (should be validated by this function)