Newer
Older
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
This section explains how to handle data storage.
We handle data storage according to the following process :
The folder /db contains all the JSON entities that are directly stored in the couchDB during the initialization process that is executed in the splash screen. They are stored under their related doctype.
## Initialization and Updating
During the initialization process, we store a hash for each dataEntity that is likely to be changed or updated. The hash is stored in the userProfile.
```json
[
{
"ecogestureHash": "",
"challengeHash": "",
"duelHash": "",
"isFirstConnection": true,
"haveSeenFavoriteModal": false,
"haveSeenOldFluidModal": false,
"haveSeenLastReport": true,
"sendReportNotification": false,
"monthlyReportDate": "0000-01-01T00:00:00.000Z"
}
]
```
This way, once the initialization is launched, we compare the hash we have in the current userProfile with the one generated from the entity located in /db folder, and if they are different we update the couchDB with the new data.
### dataEntity vs userData
In the project, you'll see two versions for the same data. The dataEntity (quizEntity, challengeEntity, ...) is the data stored in the db folder and in the couchDB. These data are only edited in the couchDB when we update a challenge/quiz/duel or add a new one.
The userData (userChallenge, userQuiz...) is created from the entity and extended with user's data, such as his progress, his consumption data, goals, fails etc.
Using this 2 structures allows us to keep user's datas when we'll update the application, by editing just the entities.
### Relationships
Relationships is a functionality made by cozy, they are built with the name of the relation, containing a "data" object, itself containing the id of the related item and its doctype "\_type". Using this allows us to reduce the size of the stored items and increase readability.
You can see more on [cozy documentation](https://docs.cozy.io/en/cozy-doctypes/docs/io.cozy.apps.suggestions/#relationships).
```json
"relationships": {
"quiz": {
"data": { "_id": "QUIZ001", "_type": "com.grandlyon.ecolyo.quiz" }
},
"duel": {
"data": { "_id": "DUEL001", "_type": "com.grandlyon.ecolyo.duel" }
}
}
```
### UserData creation
We create a userData and store it in the couchDB under the doctype userData name '**com.grandlyon.ecolyo.userDataName'.** During this process, the objects related to the dataEntity will be be converted to an user version which contains informations about the user(example: user progress, the fluids connected and so on).
To illustrate this, let's show an example of the conversion of quizEntity to userQuiz :
```jsx
DuelEntity {
id: string
title: string
description: string
duration: Duration
}
```
Becomes :
```jsx
UserQuiz {
id: string
title: string
description: string
duration: Duration
threshold: number
state: UserDuelState
startDate: string | null
fluidTypes: FluidType[]
userConsumption: number
}
```