You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.0 KiB
98 lines
2.0 KiB
import DatabaseHandler from './databaseHandler.js'
|
|
|
|
/**
|
|
* apps
|
|
*
|
|
* @author Björn Hase
|
|
* @license hhttps://www.gnu.org/licenses/gpl-3.0.en.html GPL-3
|
|
* @link https://gitea.node001.net/HerrHase/tellme-bot.git
|
|
*
|
|
*/
|
|
class TagsDatabase extends DatabaseHandler {
|
|
|
|
constructor() {
|
|
super('tags')
|
|
|
|
// add index for apps
|
|
this.createIndex([
|
|
'name'
|
|
], 'tags')
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @param {object} data
|
|
*
|
|
*/
|
|
async update(tags) {
|
|
|
|
const query = {
|
|
'selector': {
|
|
'name': {
|
|
'$in': tags
|
|
}
|
|
}, 'fields': [
|
|
'name'
|
|
]
|
|
}
|
|
|
|
// check for existings tags and remove
|
|
// adding tags that are not removed
|
|
this.db.find(query).then((documents) => {
|
|
if (documents.docs.length > 0) {
|
|
documents.docs.forEach((data) => {
|
|
|
|
// getting
|
|
const index = tags.indexOf(data.name)
|
|
|
|
if (index >= 0) {
|
|
tags.splice(index, 1)
|
|
}
|
|
})
|
|
}
|
|
|
|
if (tags.length > 0) {
|
|
tags.forEach((tag) => {
|
|
this.db.post({
|
|
'name': tag
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
/**
|
|
* find apps
|
|
*
|
|
*
|
|
* @return
|
|
*
|
|
*/
|
|
find() {
|
|
const query = {
|
|
'fields': [
|
|
'name'
|
|
],
|
|
'selector': {
|
|
'name': {
|
|
'$exists': true
|
|
}
|
|
},
|
|
'sort': [
|
|
'name'
|
|
]
|
|
}
|
|
|
|
return this.db.find(query).then((documents) => {
|
|
if (documents.warning) {
|
|
console.warning(documents.warning)
|
|
}
|
|
|
|
return documents.docs
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
export default TagsDatabase |