-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices_ProjectService.js.html
207 lines (176 loc) · 5.91 KB
/
services_ProjectService.js.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: services/ProjectService.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: services/ProjectService.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import { PouchService } from './PouchService'
import { ActivityService } from './ActivityService'
/**
* Provides access to the project database through a standardized interface.
*
* @class
*/
export class ProjectService {
constructor () {
this.pouchService = new PouchService('projects')
this.pouchService.addIndex('activities')
this.activityService = new ActivityService()
}
/**
* Adds a new project to the database.
*
* @param {string} name - The name of the project to add.
* @return {string} The GUID of the newly created project.
*
* @function
*/
async create (name) {
const document = {
activities: [],
name: name
}
const id = this.pouchService.create(document)
return id
}
/**
* Gets the project with the specified ID from the database.
*
* @param {string} projectId - The ID of the desired project.
* @return {Promise<Object>} A promise to the requested project object.
*
* @function
*/
async getOne (projectId) {
return this.pouchService.getOne(projectId)
}
/**
* Gets all projects from the database.
*
* @return {Promise<Array<Object>>} A promise to an array containing all project objects.
*
* @function
*/
async getAll () {
return this.pouchService.getAll()
}
/**
* Gets the project that contains the specified activity.
*
* @param {string} activityId - The ID of the activity to get the project for.
* @return {Promise<Object>} A promise to the project object that contains the activity.
*
* @function
*/
async getForActivity (activityId) {
const docs = await this.pouchService.getByQuery({
selector: {
activities: {
$elemMatch: {
$eq: activityId
}
}
}
})
return docs[0]
}
/**
* Gets all activites for the specified project.
*
* @param {string} projectId - The ID of the project to get the activities for.
* @return {Promise<Array<Object>>} A promise to an array containing the activity objects for the project.
*
* @function
*/
async getActivities (projectId) {
let activities = []
const project = await this.getOne(projectId)
for (const activityId of project.activities) {
let activity = await this.activityService.getOne(activityId)
if(activity.endTime) {
activities.push(activity)
}
}
return activities
}
/**
* Updates the name of the specified project.
*
* @param {string} projectId - The ID of the project to update the name for.
* @param {string} name - The new name for the project.
*
* @function
*/
async updateName (projectId, name) {
let document = await this.pouchService.getOne(projectId)
document.name = name
this.pouchService.update(document)
}
/**
* Adds the activity with the specified ID to the specified project.
*
* @param {string} projectId - The ID of the project to add the activity to.
* @param {string} activityId - The ID of the activity to add to the project.
*
* @function
*/
async addActivity (projectId, activityId) {
let document = await this.pouchService.getOne(projectId)
document.activities.push(activityId)
this.pouchService.update(document)
}
/**
* Removes the activity with the specified ID from the specified object.
*
* @param {string} projectId - The ID of the project to remove the activity from.
* @param {string} activityId - The ID of the activity to remove from the project.
*
* @function
*/
async removeActivity (projectId, activityId) {
let document = await this.pouchService.getOne(projectId)
const index = document.activities.indexOf(activityId)
if (index !== -1) {
document.activities.splice(index, 1)
}
this.pouchService.update(document)
}
/**
* Removes the specified project from the database.
*
* @param {string} projectId - The ID of the project to remove.
*
* @function
*/
async delete (projectId) {
const document = await this.pouchService.getOne(projectId)
this.pouchService.delete(document)
}
}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ActivityService.html">ActivityService</a></li><li><a href="AreaService.html">AreaService</a></li><li><a href="PouchService.html">PouchService</a></li><li><a href="ProjectService.html">ProjectService</a></li><li><a href="TagService.html">TagService</a></li></ul><h3>Global</h3><ul><li><a href="global.html#compareArrayByName">compareArrayByName</a></li><li><a href="global.html#router">router</a></li><li><a href="global.html#routes">routes</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a> on Sun Jan 24 2021 18:08:50 GMT+0000 (Coordinated Universal Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>