diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-28 16:18:20 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-28 16:18:20 +0300 |
commit | 02b0da08155c6615a48b8d7f49648c19c1600020 (patch) | |
tree | 5916962aacc99214780cc9c9ede7a0b0df160d1b | |
parent | 302a76985cef867f509a4180387cc45e934452d5 (diff) | |
download | which-api-02b0da08155c6615a48b8d7f49648c19c1600020.tar.gz |
feat: create feedback service
-rw-r--r-- | models/feedback/feedback.schema.ts | 2 | ||||
-rw-r--r-- | populateDb.ts | 13 | ||||
-rw-r--r-- | services/feedback/feedback.hooks.ts | 10 | ||||
-rw-r--r-- | services/feedback/feedback.service.ts | 13 | ||||
-rw-r--r-- | services/index.ts | 2 |
5 files changed, 38 insertions, 2 deletions
diff --git a/models/feedback/feedback.schema.ts b/models/feedback/feedback.schema.ts index a0844d6..ea6f6e7 100644 --- a/models/feedback/feedback.schema.ts +++ b/models/feedback/feedback.schema.ts @@ -8,7 +8,7 @@ export interface FeedbackSchema extends Document { createdAt: Date; } -export const FeedbackSchema = new Schema({ +export const feedbackSchema = new Schema({ contents: String, authorId: { type: Types.ObjectId, diff --git a/populateDb.ts b/populateDb.ts index b3e46af..991c152 100644 --- a/populateDb.ts +++ b/populateDb.ts @@ -1,7 +1,7 @@ import mongoose from 'mongoose'; import bluebird from 'bluebird'; import _ from 'lodash'; -import { User, Poll, Vote } from 'which-types'; +import { User, Poll, Vote, Feedback } from 'which-types'; import app from './app'; @@ -71,6 +71,13 @@ const createVote = (userId: string, pollId: string): Promise<Vote> => { }, { user: { _id: userId }, authenticated: true }); }; +const createFeedback = (userId: string): Promise<Feedback> => { + return app.service('feedback').create({ + version: 'v1.0.0', + score: _.sample([1, 2, 3, 4, 5]), + content: 'Absolutely amazing!' + }, { user: { _id: userId }, authenticated: true }); +}; const populate = async () => { const users = await bluebird.map(names, name => createUser(name)); @@ -81,6 +88,10 @@ const populate = async () => { }); await bluebird.map(users, user => { + return createFeedback(user?._id || ''); + }); + + await bluebird.map(users, user => { const pollsToVote = _.sampleSize(polls, _.random(0, POLLS_AMOUNT)); return bluebird.map(pollsToVote, poll => createVote(user?._id || '', poll?._id || '')); }); diff --git a/services/feedback/feedback.hooks.ts b/services/feedback/feedback.hooks.ts new file mode 100644 index 0000000..04f3af1 --- /dev/null +++ b/services/feedback/feedback.hooks.ts @@ -0,0 +1,10 @@ +import { HookContext } from '@feathersjs/feathers'; +import requireAuth from '../../hooks/requireAuth'; +import signAuthority from '../../hooks/signAuthority'; + +export default { + before: { + create: [requireAuth, signAuthority] + } +}; + diff --git a/services/feedback/feedback.service.ts b/services/feedback/feedback.service.ts new file mode 100644 index 0000000..a15ede9 --- /dev/null +++ b/services/feedback/feedback.service.ts @@ -0,0 +1,13 @@ +import { Application } from '@feathersjs/express'; +import service from 'feathers-mongoose'; +import Model from '../../models/feedback/feedback.model'; + +import hooks from './feedback.hooks'; + +const FeebackService = service({ Model }); + +export default (app: Application): void => { + app.use('/feedback', FeebackService); + app.service('feedback').hooks(hooks); +}; + diff --git a/services/index.ts b/services/index.ts index 1763a17..e5ea703 100644 --- a/services/index.ts +++ b/services/index.ts @@ -5,6 +5,7 @@ import Profiles from './profiles/profiles.service'; import Votes from './votes/votes.service'; import Auth from './auth/auth.service'; import Feed from './feed/feed.service'; +import Feedback from './feedback/feedback.service'; import tryAuthenticate from '../hooks/tryAuthenticate'; import logging from '../hooks/logging'; @@ -17,6 +18,7 @@ export default (app: Application): void => { app.configure(Profiles); app.configure(Votes); app.configure(Feed); + app.configure(Feedback); app.hooks({ before: { |