-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.js
43 lines (36 loc) · 949 Bytes
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Item } from "./types";
import { db } from "./db";
/**
* @param {Item} item
* @returns {Item} Created item
*/
export const createItem = async (item) => {
const created = await db.items.add(item);
if (!created) {
console.error("could not create item " + item);
}
return created;
};
/**
* @param {number} id - The id of the item to update
* @param {string} column - The column to update
* @param {string | number | boolean} value - The new value
* @returns {Item} Updated item
*/
export const updateItem = async (id, column, value) => {
const updated = await db.items.update(id, { [column]: value });
if (!updated) {
console.error("could not update item " + id);
}
return updated;
};
/**
* @param {number} id - The id of the item to delete
*/
export const deleteItem = async (id) => {
try {
await db.items.delete(id);
} catch (error) {
console.error("could not delete item " + id);
}
};