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