aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.ts20
-rw-r--r--index.ts17
-rw-r--r--models/polls/poll.model.ts5
-rw-r--r--models/polls/poll.schema.ts33
-rw-r--r--models/users/user.model.ts5
-rw-r--r--models/users/user.schema.ts19
-rw-r--r--package-lock.json245
-rw-r--r--package.json5
-rw-r--r--services/index.ts1
-rw-r--r--services/polls/polls.class.ts38
-rw-r--r--services/polls/polls.service.ts7
-rw-r--r--services/users/users.class.ts20
-rw-r--r--services/users/users.service.ts7
13 files changed, 337 insertions, 85 deletions
diff --git a/app.ts b/app.ts
index 264b517..0dce8b6 100644
--- a/app.ts
+++ b/app.ts
@@ -17,25 +17,5 @@ app.use(express.errorHandler());
app.configure(services);
-// Mock data
-app.service('polls').create({
- contents: {
- left: {
- url: 'https://github.com/eug-vs.png',
- votes: 10
- },
- right: {
- url: 'https://github.com/ilyayudovin.png',
- votes: 15
- }
- }
-});
-
-app.service('users').create({
- name: 'John Doe',
- age: 20,
- avatarUrl: 'https://github.com/ilyayudovin.png'
-});
-
export default app;
diff --git a/index.ts b/index.ts
index 35d1411..b358fdb 100644
--- a/index.ts
+++ b/index.ts
@@ -1,4 +1,16 @@
import app from './app';
+import mongoose from 'mongoose';
+
+
+mongoose.Promise = global.Promise;
+
+mongoose.connect('mongodb://localhost:27017/which', { useNewUrlParser: true });
+
+const db = mongoose.connection;
+db.on('error', console.error.bind(console, 'connection error:'));
+db.once('open', function() {
+ console.log('Connection to MongoDB successful');
+});
// Add any new real-time connection to the `everybody` channel
app.on('connection', connection =>
@@ -8,7 +20,8 @@ app.on('connection', connection =>
app.publish(data => app.channel('everybody'));
-app.listen(3030).on('listening', () =>
- console.log('Feathers server listening on localhost:3030')
+const port = 3030
+app.listen(port).on('listening', () =>
+ console.log(`Feathers server listening on localhost:${port}`)
);
diff --git a/models/polls/poll.model.ts b/models/polls/poll.model.ts
new file mode 100644
index 0000000..211d1e6
--- /dev/null
+++ b/models/polls/poll.model.ts
@@ -0,0 +1,5 @@
+import { Model, model } from "mongoose"
+import { Poll, PollSchema } from './poll.schema';
+
+export default model<Poll, Model<Poll>>("Poll", PollSchema);
+
diff --git a/models/polls/poll.schema.ts b/models/polls/poll.schema.ts
new file mode 100644
index 0000000..2e7dccd
--- /dev/null
+++ b/models/polls/poll.schema.ts
@@ -0,0 +1,33 @@
+import { Document, Schema, Types } from 'mongoose';
+import { User } from '../users/user.schema';
+
+interface ImageData {
+ url: string;
+ votes: number;
+}
+
+export interface Poll extends Document {
+ authorId: string;
+ contents: {
+ left: ImageData;
+ right: ImageData;
+ };
+}
+
+
+const imageDataSchema = {
+ url: String,
+ votes: Number
+}
+
+export const PollSchema = new Schema({
+ contents: {
+ left: imageDataSchema,
+ right: imageDataSchema
+ },
+ authorId: {
+ type: Types.ObjectId,
+ ref: 'User'
+ }
+});
+
diff --git a/models/users/user.model.ts b/models/users/user.model.ts
new file mode 100644
index 0000000..cec9298
--- /dev/null
+++ b/models/users/user.model.ts
@@ -0,0 +1,5 @@
+import { Model, model } from "mongoose"
+import { User, UserSchema } from './user.schema';
+
+export default model<User, Model<User>>("User", UserSchema);
+
diff --git a/models/users/user.schema.ts b/models/users/user.schema.ts
new file mode 100644
index 0000000..c846f81
--- /dev/null
+++ b/models/users/user.schema.ts
@@ -0,0 +1,19 @@
+import { Document, Schema } from "mongoose"
+
+export interface User extends Document {
+ name: string;
+ avatarUrl?: string;
+ age?: number;
+}
+
+export const UserSchema = new Schema({
+ name: String,
+ avatarUrl: {
+ type: String,
+ required: false
+ },
+ age: {
+ type: Number
+ }
+});
+
diff --git a/package-lock.json b/package-lock.json
index 8fd7531..ab94251 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4,6 +4,16 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+ "@feathersjs/adapter-commons": {
+ "version": "4.5.2",
+ "resolved": "https://registry.npmjs.org/@feathersjs/adapter-commons/-/adapter-commons-4.5.2.tgz",
+ "integrity": "sha512-7NF4WO/R0OOZo6/mPnMml4Hz+Ynr0JMCp4TDO6JIf3ITAwc78A7b6jrORw1sw3Cq3hkD0sC342sk7mRk3BwPDg==",
+ "requires": {
+ "@feathersjs/commons": "^4.5.2",
+ "@feathersjs/errors": "^4.5.2",
+ "@feathersjs/feathers": "^4.5.2"
+ }
+ },
"@feathersjs/commons": {
"version": "4.5.3",
"resolved": "https://registry.npmjs.org/@feathersjs/commons/-/commons-4.5.3.tgz",
@@ -75,6 +85,14 @@
"@types/node": "*"
}
},
+ "@types/bson": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/@types/bson/-/bson-4.0.2.tgz",
+ "integrity": "sha512-+uWmsejEHfmSjyyM/LkrP0orfE2m5Mx9Xel4tXNeqi1ldK5XMQcDsFkBmLDtuyKUbxj2jGDo0H240fbCRJZo7Q==",
+ "requires": {
+ "@types/node": "*"
+ }
+ },
"@types/connect": {
"version": "3.4.33",
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.33.tgz",
@@ -117,6 +135,24 @@
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.2.tgz",
"integrity": "sha512-4kPlzbljFcsttWEq6aBW0OZe6BDajAmyvr2xknBG92tejQnvdGtT9+kXSZ580DqpxY9qG2xeQVF9Dq0ymUTo5Q=="
},
+ "@types/mongodb": {
+ "version": "3.5.20",
+ "resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.5.20.tgz",
+ "integrity": "sha512-BN0wJn670DkivxiP7ZW0InX4qBtX01qITaucD+3A+sTgPQo4XUYay0Y+sGM4MJ9OyKDRlb3RQuVAlyeWzl/NoA==",
+ "requires": {
+ "@types/bson": "*",
+ "@types/node": "*"
+ }
+ },
+ "@types/mongoose": {
+ "version": "5.7.23",
+ "resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.7.23.tgz",
+ "integrity": "sha512-Yh1vXr+Y+ro887sma0kihtvbazy3prC+gjT0FJZ/Kt6rOQoHnCRm8oiOvDWGncP3YVXAoCj4YeNLp7moIyBKIQ==",
+ "requires": {
+ "@types/mongodb": "*",
+ "@types/node": "*"
+ }
+ },
"@types/node": {
"version": "14.0.11",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.11.tgz",
@@ -202,11 +238,25 @@
"callsite": "1.0.0"
}
},
+ "bl": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz",
+ "integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==",
+ "requires": {
+ "readable-stream": "^2.3.5",
+ "safe-buffer": "^5.1.1"
+ }
+ },
"blob": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/blob/-/blob-0.0.5.tgz",
"integrity": "sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig=="
},
+ "bluebird": {
+ "version": "3.5.1",
+ "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
+ "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA=="
+ },
"body-parser": {
"version": "1.19.0",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
@@ -239,6 +289,11 @@
}
}
},
+ "bson": {
+ "version": "1.1.4",
+ "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.4.tgz",
+ "integrity": "sha512-S/yKGU1syOMzO86+dGpg2qGoDL0zvzcb262G+gqEy6TgP6rt6z6qxSFX/8X6vLC91P7G7C3nLs0+bvDzmvBA3Q=="
+ },
"bytes": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
@@ -287,6 +342,11 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
+ "core-util-is": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
+ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
+ },
"debug": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
@@ -295,6 +355,11 @@
"ms": "^2.1.1"
}
},
+ "denque": {
+ "version": "1.4.1",
+ "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz",
+ "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ=="
+ },
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
@@ -447,6 +512,16 @@
}
}
},
+ "feathers-mongoose": {
+ "version": "8.3.0",
+ "resolved": "https://registry.npmjs.org/feathers-mongoose/-/feathers-mongoose-8.3.0.tgz",
+ "integrity": "sha512-VsfAfCYJfulF/Mku0K9O02vVh14ahoctPn7mpMoXzYA/232dv5QeCwf4d8hzw/jLbgLhuehKAmeFnwODfU5TjA==",
+ "requires": {
+ "@feathersjs/adapter-commons": "^4.4.1",
+ "@feathersjs/commons": "^4.4.1",
+ "@feathersjs/errors": "^4.4.1"
+ }
+ },
"finalhandler": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
@@ -539,6 +614,11 @@
"resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz",
"integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4="
},
+ "kareem": {
+ "version": "2.3.1",
+ "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.1.tgz",
+ "integrity": "sha512-l3hLhffs9zqoDe8zjmb/mAN4B8VT3L56EUvKNqLFVs9YlFA+zx7ke1DO8STAdDyYNkeSo1nKmjuvQeI12So8Xw=="
+ },
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
@@ -549,6 +629,12 @@
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
},
+ "memory-pager": {
+ "version": "1.5.0",
+ "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
+ "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
+ "optional": true
+ },
"merge-descriptors": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
@@ -577,6 +663,74 @@
"mime-db": "1.44.0"
}
},
+ "mongodb": {
+ "version": "3.5.8",
+ "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.8.tgz",
+ "integrity": "sha512-jz7mR58z66JKL8Px4ZY+FXbgB7d0a0hEGCT7kw8iye46/gsqPrOEpZOswwJ2BQlfzsrCLKdsF9UcaUfGVN2HrQ==",
+ "requires": {
+ "bl": "^2.2.0",
+ "bson": "^1.1.4",
+ "denque": "^1.4.1",
+ "require_optional": "^1.0.1",
+ "safe-buffer": "^5.1.2",
+ "saslprep": "^1.0.0"
+ }
+ },
+ "mongoose": {
+ "version": "5.9.18",
+ "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.18.tgz",
+ "integrity": "sha512-agZbIuQcN1gZ12BJn6KesA+bgsvoLVjCwhfPw88hggxX8O24SWK4EJwN35GEZKDej9AHUZKNAPgmdeXCVQxviA==",
+ "requires": {
+ "bson": "^1.1.4",
+ "kareem": "2.3.1",
+ "mongodb": "3.5.8",
+ "mongoose-legacy-pluralize": "1.0.2",
+ "mpath": "0.7.0",
+ "mquery": "3.2.2",
+ "ms": "2.1.2",
+ "regexp-clone": "1.0.0",
+ "safe-buffer": "5.1.2",
+ "sift": "7.0.1",
+ "sliced": "1.0.1"
+ }
+ },
+ "mongoose-legacy-pluralize": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz",
+ "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ=="
+ },
+ "mpath": {
+ "version": "0.7.0",
+ "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.7.0.tgz",
+ "integrity": "sha512-Aiq04hILxhz1L+f7sjGyn7IxYzWm1zLNNXcfhDtx04kZ2Gk7uvFdgZ8ts1cWa/6d0TQmag2yR8zSGZUmp0tFNg=="
+ },
+ "mquery": {
+ "version": "3.2.2",
+ "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.2.tgz",
+ "integrity": "sha512-XB52992COp0KP230I3qloVUbkLUxJIu328HBP2t2EsxSFtf4W1HPSOBWOXf1bqxK4Xbb66lfMJ+Bpfd9/yZE1Q==",
+ "requires": {
+ "bluebird": "3.5.1",
+ "debug": "3.1.0",
+ "regexp-clone": "^1.0.0",
+ "safe-buffer": "5.1.2",
+ "sliced": "1.0.1"
+ },
+ "dependencies": {
+ "debug": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
+ "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
+ "requires": {
+ "ms": "2.0.0"
+ }
+ },
+ "ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
+ }
+ }
+ },
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
@@ -626,6 +780,11 @@
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
+ "process-nextick-args": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
+ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
+ },
"proxy-addr": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz",
@@ -661,6 +820,46 @@
"unpipe": "1.0.0"
}
},
+ "readable-stream": {
+ "version": "2.3.7",
+ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
+ "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
+ "requires": {
+ "core-util-is": "~1.0.0",
+ "inherits": "~2.0.3",
+ "isarray": "~1.0.0",
+ "process-nextick-args": "~2.0.0",
+ "safe-buffer": "~5.1.1",
+ "string_decoder": "~1.1.1",
+ "util-deprecate": "~1.0.1"
+ },
+ "dependencies": {
+ "isarray": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
+ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
+ }
+ }
+ },
+ "regexp-clone": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz",
+ "integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw=="
+ },
+ "require_optional": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz",
+ "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==",
+ "requires": {
+ "resolve-from": "^2.0.0",
+ "semver": "^5.1.0"
+ }
+ },
+ "resolve-from": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz",
+ "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c="
+ },
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
@@ -671,6 +870,20 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
+ "saslprep": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz",
+ "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==",
+ "optional": true,
+ "requires": {
+ "sparse-bitfield": "^3.0.3"
+ }
+ },
+ "semver": {
+ "version": "5.7.1",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
+ "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ=="
+ },
"send": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz",
@@ -729,6 +942,16 @@
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
},
+ "sift": {
+ "version": "7.0.1",
+ "resolved": "https://registry.npmjs.org/sift/-/sift-7.0.1.tgz",
+ "integrity": "sha512-oqD7PMJ+uO6jV9EQCl0LrRw1OwsiPsiFQR5AR30heR+4Dl7jBBbDLnNvWiak20tzZlSE1H7RB30SX/1j/YYT7g=="
+ },
+ "sliced": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz",
+ "integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E="
+ },
"socket.io": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-2.3.0.tgz",
@@ -805,11 +1028,28 @@
"isarray": "2.0.1"
}
},
+ "sparse-bitfield": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
+ "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=",
+ "optional": true,
+ "requires": {
+ "memory-pager": "^1.0.2"
+ }
+ },
"statuses": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
},
+ "string_decoder": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
+ "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
+ "requires": {
+ "safe-buffer": "~5.1.0"
+ }
+ },
"to-array": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz",
@@ -839,6 +1079,11 @@
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
},
+ "util-deprecate": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
+ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
+ },
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
diff --git a/package.json b/package.json
index 758cb99..6e1f213 100644
--- a/package.json
+++ b/package.json
@@ -12,7 +12,10 @@
"@feathersjs/express": "^4.5.4",
"@feathersjs/feathers": "^4.5.3",
"@feathersjs/socketio": "^4.5.4",
- "@feathersjs/transport-commons": "^4.5.3"
+ "@feathersjs/transport-commons": "^4.5.3",
+ "@types/mongoose": "^5.7.23",
+ "feathers-mongoose": "^8.3.0",
+ "mongoose": "^5.9.18"
},
"repository": {
"type": "git",
diff --git a/services/index.ts b/services/index.ts
index eeaf485..441f9ad 100644
--- a/services/index.ts
+++ b/services/index.ts
@@ -1,3 +1,4 @@
+import { Application } from '@feathersjs/express';
import Users from './users/users.service';
import Polls from './polls/polls.service';
diff --git a/services/polls/polls.class.ts b/services/polls/polls.class.ts
deleted file mode 100644
index 82ef155..0000000
--- a/services/polls/polls.class.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-interface ImageData {
- url: string;
- votes: number;
-}
-
-interface User {
- name: string;
- avatarUrl: string;
-}
-
-interface Poll {
- author: User;
- contents: {
- left: ImageData;
- right: ImageData;
- };
-}
-
-const defaultUser: User = {
- name: 'John Doe',
- avatarUrl: 'https://github.com/eug-vs.png'
-};
-
-
-export default class Polls {
- polls: Poll[] = [];
-
- async find () {
- return this.polls;
- }
-
- async create (data: Pick<Poll, 'contents'>) {
- const poll: Poll = { ...data, author: defaultUser };
- this.polls.push(poll);
- return poll;
- }
-}
-
diff --git a/services/polls/polls.service.ts b/services/polls/polls.service.ts
index a4bd816..ca75d5a 100644
--- a/services/polls/polls.service.ts
+++ b/services/polls/polls.service.ts
@@ -1,7 +1,10 @@
import { Application } from '@feathersjs/express';
-import Polls from './polls.class';
+import Model from '../../models/polls/poll.model';
+import service from 'feathers-mongoose';
+
+const PollService = service({ Model });
export default (app: Application): void => {
- app.use('/polls', new Polls());
+ app.use('/polls', PollService);
};
diff --git a/services/users/users.class.ts b/services/users/users.class.ts
deleted file mode 100644
index db6b5a9..0000000
--- a/services/users/users.class.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-interface User {
- name: string;
- avatarUrl?: string;
- age?: number;
-}
-
-export default class Users {
- users: User[] = [];
-
- async find (){
- return this.users;
- }
-
- async create(data: Pick<User, 'name' | 'avatarUrl' | 'age'>){
- const user: User = { ...data };
- this.users.push(user);
- return user;
- }
-}
-
diff --git a/services/users/users.service.ts b/services/users/users.service.ts
index bf608fe..47dac3d 100644
--- a/services/users/users.service.ts
+++ b/services/users/users.service.ts
@@ -1,7 +1,10 @@
import { Application } from '@feathersjs/express';
-import Users from './users.class';
+import Model from '../../models/users/user.model';
+import service from 'feathers-mongoose';
+
+const UserService = service({ Model });
export default (app: Application): void => {
- app.use('/users', new Users());
+ app.use('/users', UserService);
};