diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-14 14:56:12 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-14 14:56:12 +0300 |
commit | fd3efcdec584d550f70fb473386e01086e8238e0 (patch) | |
tree | d5019e835f70fd70fe6825704e8aa7c010ed8ce3 | |
parent | 87306ea2e4ffad7b8c588da0423ecf199575ac9c (diff) | |
download | bsu-fantom-fd3efcdec584d550f70fb473386e01086e8238e0.tar.gz |
feat: add Users and Events services
-rw-r--r-- | app.js | 2 | ||||
-rw-r--r-- | index.js | 2 | ||||
-rw-r--r-- | package-lock.json | 20 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | services/events/event.model.js | 6 | ||||
-rw-r--r-- | services/events/event.schema.js | 16 | ||||
-rw-r--r-- | services/events/event.service.js | 7 | ||||
-rw-r--r-- | services/index.js | 10 | ||||
-rw-r--r-- | services/users/user.model.js | 6 | ||||
-rw-r--r-- | services/users/user.schema.js | 14 | ||||
-rw-r--r-- | services/users/user.service.js | 7 |
11 files changed, 91 insertions, 0 deletions
@@ -3,6 +3,7 @@ const express = require('@feathersjs/express'); const socketio = require('@feathersjs/socketio'); const cors = require('cors') +const services = require('./services'); const app = express(feathers()); @@ -15,6 +16,7 @@ app.use(cors()); app.configure(express.rest()); app.configure(socketio()); +app.configure(services); module.exports = app; @@ -26,3 +26,5 @@ db.once('open', () => { console.log('Connection to MongoDB successful'); }); +app.listen(PORT).on('listening', () => console.log(`Feathers server listening on localhost:${PORT}`)); + diff --git a/package-lock.json b/package-lock.json index 4a40ee6..c91d532 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,16 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@feathersjs/adapter-commons": { + "version": "4.5.7", + "resolved": "https://registry.npmjs.org/@feathersjs/adapter-commons/-/adapter-commons-4.5.7.tgz", + "integrity": "sha512-968FYEeX5S790dhhPf/u1RBhh8824jW6fRb0bmWqGpzjEkC7dNJ9+m+j3/Gduh1cPGL1a6Nf5sXkkMEFWDJ4tw==", + "requires": { + "@feathersjs/commons": "^4.5.8", + "@feathersjs/errors": "^4.5.8", + "@feathersjs/feathers": "^4.5.8" + } + }, "@feathersjs/commons": { "version": "4.5.10", "resolved": "https://registry.npmjs.org/@feathersjs/commons/-/commons-4.5.10.tgz", @@ -623,6 +633,16 @@ "pend": "~1.2.0" } }, + "feathers-mongoose": { + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/feathers-mongoose/-/feathers-mongoose-8.3.1.tgz", + "integrity": "sha512-N89kOOp06PaYwyK2REI56fDSPDBKYuJc/E6uqCUu4+nQ6wvM3m+L4aX6lfXWBowD7MWpFzNDG/T9GOGjzrQ55g==", + "requires": { + "@feathersjs/adapter-commons": "^4.4.3", + "@feathersjs/commons": "^4.4.3", + "@feathersjs/errors": "^4.4.3" + } + }, "finalhandler": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", diff --git a/package.json b/package.json index 5d5a3fd..853eaef 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "bluebird": "^3.7.2", "cors": "^2.8.5", "dotenv": "^8.2.0", + "feathers-mongoose": "^8.3.1", "mongoose": "^5.10.14", "puppeteer": "^5.4.1" } diff --git a/services/events/event.model.js b/services/events/event.model.js new file mode 100644 index 0000000..7bac9d5 --- /dev/null +++ b/services/events/event.model.js @@ -0,0 +1,6 @@ +const { model } = require('mongoose'); +const eventSchema = require('./event.schema.js'); + +module.exports = model('Event', eventSchema); + + diff --git a/services/events/event.schema.js b/services/events/event.schema.js new file mode 100644 index 0000000..555153b --- /dev/null +++ b/services/events/event.schema.js @@ -0,0 +1,16 @@ +const { Schema, Types } = require('mongoose'); + +module.exports = new Schema({ + startDate: { + type: Date, + required: true + }, + endDate: { + type: Date, + required: true + }, + attendanceId: Number, + conferenceId: Number, + participantIds: [Types.ObjectId] +}, { timestamps: true }); + diff --git a/services/events/event.service.js b/services/events/event.service.js new file mode 100644 index 0000000..e9e7e50 --- /dev/null +++ b/services/events/event.service.js @@ -0,0 +1,7 @@ +const service = require('feathers-mongoose'); +const Model = require('./event.model.js'); + +const EventService = service({ Model }) + +module.exports = app => app.use('/events', EventService); + diff --git a/services/index.js b/services/index.js new file mode 100644 index 0000000..f2d65d0 --- /dev/null +++ b/services/index.js @@ -0,0 +1,10 @@ +const Users = require('./users/user.service.js'); +const Events = require('./events/event.service.js'); + +module.exports = app => { + app.configure(Users); + app.configure(Events); + + app.get('/ping', (req, res) => res.send('pong')); +}; + diff --git a/services/users/user.model.js b/services/users/user.model.js new file mode 100644 index 0000000..74a83ae --- /dev/null +++ b/services/users/user.model.js @@ -0,0 +1,6 @@ +const { model } = require('mongoose'); +const userSchema = require('./user.schema.js'); + +module.exports = model('User', userSchema); + + diff --git a/services/users/user.schema.js b/services/users/user.schema.js new file mode 100644 index 0000000..f2c98ef --- /dev/null +++ b/services/users/user.schema.js @@ -0,0 +1,14 @@ +const { Schema } = require('mongoose'); + +module.exports = new Schema({ + username: { + type: String, + unique: true, + required: true + }, + password: { + type: String, + required: true + } +}, { timestamps: true }); + diff --git a/services/users/user.service.js b/services/users/user.service.js new file mode 100644 index 0000000..67f2ae6 --- /dev/null +++ b/services/users/user.service.js @@ -0,0 +1,7 @@ +const service = require('feathers-mongoose'); +const Model = require('./user.model.js'); + +const UserService = service({ Model }) + +module.exports = app => app.use('/users', UserService); + |