Skip to content

Commit 02b0da0

Browse files
committed
feat: create feedback service
1 parent 302a769 commit 02b0da0

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

models/feedback/feedback.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface FeedbackSchema extends Document {
88
createdAt: Date;
99
}
1010

11-
export const FeedbackSchema = new Schema({
11+
export const feedbackSchema = new Schema({
1212
contents: String,
1313
authorId: {
1414
type: Types.ObjectId,

populateDb.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import mongoose from 'mongoose';
22
import bluebird from 'bluebird';
33
import _ from 'lodash';
4-
import { User, Poll, Vote } from 'which-types';
4+
import { User, Poll, Vote, Feedback } from 'which-types';
55

66
import app from './app';
77

@@ -71,6 +71,13 @@ const createVote = (userId: string, pollId: string): Promise<Vote> => {
7171
}, { user: { _id: userId }, authenticated: true });
7272
};
7373

74+
const createFeedback = (userId: string): Promise<Feedback> => {
75+
return app.service('feedback').create({
76+
version: 'v1.0.0',
77+
score: _.sample([1, 2, 3, 4, 5]),
78+
content: 'Absolutely amazing!'
79+
}, { user: { _id: userId }, authenticated: true });
80+
};
7481

7582
const populate = async () => {
7683
const users = await bluebird.map(names, name => createUser(name));
@@ -80,6 +87,10 @@ const populate = async () => {
8087
return createPoll(user?._id || '');
8188
});
8289

90+
await bluebird.map(users, user => {
91+
return createFeedback(user?._id || '');
92+
});
93+
8394
await bluebird.map(users, user => {
8495
const pollsToVote = _.sampleSize(polls, _.random(0, POLLS_AMOUNT));
8596
return bluebird.map(pollsToVote, poll => createVote(user?._id || '', poll?._id || ''));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { HookContext } from '@feathersjs/feathers';
2+
import requireAuth from '../../hooks/requireAuth';
3+
import signAuthority from '../../hooks/signAuthority';
4+
5+
export default {
6+
before: {
7+
create: [requireAuth, signAuthority]
8+
}
9+
};
10+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Application } from '@feathersjs/express';
2+
import service from 'feathers-mongoose';
3+
import Model from '../../models/feedback/feedback.model';
4+
5+
import hooks from './feedback.hooks';
6+
7+
const FeebackService = service({ Model });
8+
9+
export default (app: Application): void => {
10+
app.use('/feedback', FeebackService);
11+
app.service('feedback').hooks(hooks);
12+
};
13+

services/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Profiles from './profiles/profiles.service';
55
import Votes from './votes/votes.service';
66
import Auth from './auth/auth.service';
77
import Feed from './feed/feed.service';
8+
import Feedback from './feedback/feedback.service';
89

910
import tryAuthenticate from '../hooks/tryAuthenticate';
1011
import logging from '../hooks/logging';
@@ -17,6 +18,7 @@ export default (app: Application): void => {
1718
app.configure(Profiles);
1819
app.configure(Votes);
1920
app.configure(Feed);
21+
app.configure(Feedback);
2022

2123
app.hooks({
2224
before: {

0 commit comments

Comments
 (0)