|
|
|
@ -19,13 +19,14 @@ class AppsDatabase extends DatabaseHandler {
|
|
|
|
|
'name'
|
|
|
|
|
], 'name-sort')
|
|
|
|
|
|
|
|
|
|
// add index for apps to sort by name
|
|
|
|
|
// add index for apps to sort by date_started
|
|
|
|
|
this.createIndex([
|
|
|
|
|
'date_started'
|
|
|
|
|
], 'date-started-sort')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* create app
|
|
|
|
|
*
|
|
|
|
|
* @param {object} data
|
|
|
|
|
* @return {object}
|
|
|
|
@ -33,11 +34,13 @@ class AppsDatabase extends DatabaseHandler {
|
|
|
|
|
*/
|
|
|
|
|
create(data) {
|
|
|
|
|
|
|
|
|
|
// default for date_started
|
|
|
|
|
data.date_started = 0
|
|
|
|
|
|
|
|
|
|
return this.db.post(data)
|
|
|
|
|
.then((response) => {
|
|
|
|
|
|
|
|
|
|
// if tags are in data update tags also in database
|
|
|
|
|
if (data.tags) {
|
|
|
|
|
const tagsDatabase = new TagsDatabase()
|
|
|
|
|
tagsDatabase.update(data.tags)
|
|
|
|
@ -45,11 +48,14 @@ class AppsDatabase extends DatabaseHandler {
|
|
|
|
|
|
|
|
|
|
return this.findOneById(response._id)
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
|
|
|
|
|
// @TODO handle errors from pouchdb
|
|
|
|
|
console.error(error)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* update app
|
|
|
|
|
*
|
|
|
|
|
* @param {object} data
|
|
|
|
|
* @return {object}
|
|
|
|
@ -60,26 +66,34 @@ class AppsDatabase extends DatabaseHandler {
|
|
|
|
|
.then((response) => {
|
|
|
|
|
return this.findOneById(response._id)
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
|
|
|
|
|
// @TODO handle errors from pouchdb
|
|
|
|
|
console.error(error)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* remove app
|
|
|
|
|
*
|
|
|
|
|
* @param {object} data
|
|
|
|
|
* @param {object} document
|
|
|
|
|
* @return {object}
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
remove(data) {
|
|
|
|
|
return this.db.remove(data)
|
|
|
|
|
remove(document) {
|
|
|
|
|
return this.db.remove(document)
|
|
|
|
|
.then(async (response) => {
|
|
|
|
|
|
|
|
|
|
// successfull remove document, check for tags that
|
|
|
|
|
// not longer used
|
|
|
|
|
if (response.ok === true) {
|
|
|
|
|
const tagsDatabase = new TagsDatabase()
|
|
|
|
|
|
|
|
|
|
await tagsDatabase.removeNotNeeded()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
return response
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
|
|
|
|
|
// @TODO handle errors from pouchdb
|
|
|
|
|
console.error(error)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@ -115,6 +129,8 @@ class AppsDatabase extends DatabaseHandler {
|
|
|
|
|
return documents.docs[0]
|
|
|
|
|
}
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
|
|
|
|
|
// @TODO handle errors from pouchdb
|
|
|
|
|
console.error(error)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@ -148,13 +164,16 @@ class AppsDatabase extends DatabaseHandler {
|
|
|
|
|
query.sort = []
|
|
|
|
|
query.sort.push(parameters.sort)
|
|
|
|
|
|
|
|
|
|
// if sort is date_stared change 'date-started-sort'
|
|
|
|
|
if (parameters.sort === 'date_started') {
|
|
|
|
|
query.use_index = '_design/date-started-sort'
|
|
|
|
|
query.selector = {
|
|
|
|
|
'date_started': {
|
|
|
|
|
'$regex': ''
|
|
|
|
|
'$exists': true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if sort is name change 'name-sort'
|
|
|
|
|
} else {
|
|
|
|
|
query.use_index = '_design/name-sort'
|
|
|
|
|
query.selector = {
|
|
|
|
@ -173,16 +192,10 @@ class AppsDatabase extends DatabaseHandler {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.db.find(query).then((documents) => {
|
|
|
|
|
if (documents.warning) {
|
|
|
|
|
console.log(documents.warning)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (documents.docs.length > 0 && parameters.tags.length > 0) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return documents.docs
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
|
|
|
|
|
// @TODO handle errors from pouchdb
|
|
|
|
|
console.error(error)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|