Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 6f20d63

Browse files
added pages service
1 parent c9a3735 commit 6f20d63

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed

server/models/pages.model.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// pages-model.js - A mongoose model
2+
//
3+
// See http://mongoosejs.com/docs/models.html
4+
// for more of what you can do here.
5+
module.exports = function (app) {
6+
const mongooseClient = app.get('mongooseClient');
7+
const pages = new mongooseClient.Schema({
8+
title: { type: String, required: true },
9+
slug: { type: String, required: true },
10+
type: { type: String, required: true, default: 'page' },
11+
content: { type: String, required: true },
12+
language: { type: String, required: true, index: true },
13+
active: { type: Boolean, default: true, index: true },
14+
createdAt: { type: Date, default: Date.now },
15+
updatedAt: { type: Date, default: Date.now },
16+
wasSeeded: { type: Boolean }
17+
});
18+
19+
return mongooseClient.model('pages', pages);
20+
};

server/services/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const invites = require('./invites/invites.service.js');
1919
const usersCandos = require('./users-candos/users-candos.service.js');
2020
const search = require('./search/search.service.js');
2121
const usersettings = require('./usersettings/usersettings.service.js');
22+
const pages = require('./pages/pages.service.js');
2223
const systemNotifications = require('./system-notifications/system-notifications.service.js');
2324

2425
module.exports = function () {
@@ -44,5 +45,6 @@ module.exports = function () {
4445
app.configure(usersCandos);
4546
app.configure(search);
4647
app.configure(usersettings);
48+
app.configure(pages);
4749
app.configure(systemNotifications);
4850
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint no-console: 1 */
2+
console.warn('You are using the default filter for the pages service. For more information about event filters see https://docs.feathersjs.com/api/events.html#event-filtering'); // eslint-disable-line no-console
3+
4+
module.exports = function (data, connection, hook) { // eslint-disable-line no-unused-vars
5+
return data;
6+
};

server/services/pages/pages.hooks.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const { unless, isProvider } = require('feathers-hooks-common');
2+
const { isVerified } = require('feathers-authentication-management').hooks;
3+
const { authenticate } = require('feathers-authentication').hooks;
4+
const isAdmin = require('../../hooks/is-admin');
5+
const createSlug = require('../../hooks/create-slug');
6+
7+
module.exports = {
8+
before: {
9+
all: [],
10+
find: [],
11+
get: [],
12+
create: [
13+
authenticate('jwt'),
14+
unless(isProvider('server'),
15+
isVerified(),
16+
isAdmin()
17+
),
18+
createSlug({ field: 'title' })
19+
],
20+
update: [
21+
authenticate('jwt'),
22+
unless(isProvider('server'),
23+
isVerified(),
24+
isAdmin()
25+
)
26+
],
27+
patch: [
28+
authenticate('jwt'),
29+
unless(isProvider('server'),
30+
isVerified(),
31+
isAdmin()
32+
)
33+
],
34+
remove: [
35+
authenticate('jwt'),
36+
isVerified(),
37+
isAdmin()
38+
]
39+
},
40+
41+
after: {
42+
all: [],
43+
find: [],
44+
get: [],
45+
create: [],
46+
update: [],
47+
patch: [],
48+
remove: []
49+
},
50+
51+
error: {
52+
all: [],
53+
find: [],
54+
get: [],
55+
create: [],
56+
update: [],
57+
patch: [],
58+
remove: []
59+
}
60+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Initializes the `pages` service on path `/pages`
2+
const createService = require('feathers-mongoose');
3+
const createModel = require('../../models/pages.model');
4+
const hooks = require('./pages.hooks');
5+
const filters = require('./pages.filters');
6+
7+
module.exports = function () {
8+
const app = this;
9+
const Model = createModel(app);
10+
const paginate = app.get('paginate');
11+
12+
const options = {
13+
name: 'pages',
14+
Model,
15+
paginate
16+
};
17+
18+
// Initialize our service with any options it requires
19+
app.use('/pages', createService(options));
20+
21+
// Get our initialized service so that we can register hooks and filters
22+
const service = app.service('pages');
23+
24+
service.hooks(hooks);
25+
26+
if (service.filter) {
27+
service.filter(filters);
28+
}
29+
};

0 commit comments

Comments
 (0)