-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummyFirebase.js
42 lines (36 loc) · 1.09 KB
/
dummyFirebase.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
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
const db = {};
export const firestore = () => {
const get = (tableName) => () => {
const data = db[tableName];
const orderIds = Object.keys(data);
let orders = {};
for (let i = 0; i < orderIds.length; i++) {
const orderId = orderIds[i];
console.log(orderId, data[orderId]);
orders = {
items: data[orderId].items
};
}
return orders;
};
const add = (tableName) => (item = {}) => {
const uuid = uuidv4();
db[tableName][uuid] = {};
db[tableName][uuid] = item;
// console.log('RECORD', db[tableName]);
return Promise.resolve({
[uuid]: db[tableName][uuid]
});
};
return {
collection: (tableName) => {
if (!db[tableName]) {
console.log("table does not exist");
db[tableName] = {};
}
return { add: add(tableName), get: get(tableName) };
}
}
};