Resolver tidy.
This commit is contained in:
parent
07ac477fde
commit
e7965dda4a
@ -1,40 +1,18 @@
|
|||||||
import low from 'lowdb'
|
import low from 'lowdb'
|
||||||
import storage from 'lowdb/lib/storages/file-async'
|
import storage from 'lowdb/lib/storages/file-async'
|
||||||
|
|
||||||
const db = low('db.json', {
|
const db = low('db.json', { storage })
|
||||||
storage
|
db.defaults({ uploads: [] }).write()
|
||||||
})
|
|
||||||
|
|
||||||
db
|
const saveFile = file =>
|
||||||
.defaults({
|
db.get('uploads').push({ id: file.path, ...file }).last().write()
|
||||||
uploads: []
|
|
||||||
})
|
|
||||||
.write()
|
|
||||||
|
|
||||||
const saveFile = file => {
|
|
||||||
return db
|
|
||||||
.get('uploads')
|
|
||||||
.push({
|
|
||||||
id: file.path,
|
|
||||||
...file
|
|
||||||
})
|
|
||||||
.last()
|
|
||||||
.write()
|
|
||||||
.then(result => result)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
uploads() {
|
uploads: () => db.get('uploads').value()
|
||||||
return db.get('uploads').value()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
singleUpload: (_, { file }) => saveFile(file),
|
singleUpload: (_, { file }) => saveFile(file),
|
||||||
multipleUpload(_, { files }) {
|
multipleUpload: (_, { files }) => Promise.all(files.map(saveFile))
|
||||||
return Promise.all(files.map(file => saveFile(file))).then(
|
|
||||||
results => results
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user