-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbaby.js
57 lines (45 loc) · 1.25 KB
/
baby.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import firestore from '@react-native-firebase/firestore';
const babyDocument = firestore().collection('babys').doc('baby');
export function createBaby({code, babyForm}) {
const today = new Date();
const age = today.getFullYear() - parseInt(babyForm.birthYear, 10);
const monthsAfterBirth =
age * 12 + today.getMonth() - parseInt(babyForm.birthMonth, 10);
const daysAfterBirth = monthsAfterBirth * 31;
return babyDocument
.collection(code)
.doc(babyForm.order + '')
.set({
...babyForm,
age: age,
monthsAfterBirth: monthsAfterBirth,
daysAfterBirth: daysAfterBirth,
});
}
export async function getBaby({code}) {
const snapshot = await babyDocument
.collection(code)
.orderBy('order', 'asc')
.get();
const babys = snapshot.docs.map(doc => ({
id: doc.id,
...doc.data(),
}));
return babys;
}
export async function getBabyInfo({code, order}) {
const snapshot = await babyDocument
.collection(code)
.doc(order + '')
.get();
const info = snapshot.data();
return info;
}
//for Chips
export async function getBabyOrder({code}) {
const snapshot = await babyDocument.collection(code).get();
const chip = snapshot.docs.map(doc => ({
id: doc.id,
}));
return chip;
}