-
Notifications
You must be signed in to change notification settings - Fork 5
/
todos.service.js
36 lines (29 loc) · 981 Bytes
/
todos.service.js
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
// Initializes the `todos` service on path `/todos`
const createService = require('feathers-nedb');
const createModel = require('../../models/todos.model');
const hooks = require('./todos.hooks');
module.exports = async function (app) {
const Model = createModel(app);
const paginate = app.get('paginate');
const options = {
Model,
paginate
};
// Initialize our service with any options it requires
app.use('/todos', createService(options));
// Get our initialized service so that we can register hooks
const service = app.service('todos');
const todos = [
{ title: 'Learn vue', completed: true },
{ title: 'Learn vuex', completed: true },
{ title: 'Learn feathers', completed: true },
{ title: 'Learn feathers-vuex', completed: false },
];
for (let todo of todos) {
const found = await service.find({ query: { title: todo.title } });
if (!found.total) {
service.create(todo);
}
}
service.hooks(hooks);
};