Skip to content

Commit 302a769

Browse files
committed
feat: improve votes
1 parent e63122d commit 302a769

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

hooks/signAuthority.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { HookContext } from '@feathersjs/feathers';
2+
3+
export default async (context: HookContext): Promise<HookContext> => {
4+
const { params: { user } } = context;
5+
context.data.authorId = user._id;
6+
return context;
7+
};
8+

models/votes/vote.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Model, model } from 'mongoose';
22
import { VoteSchema, voteSchema } from './vote.schema';
33

4-
voteSchema.index({ pollId: 1, userId: 1 }, { unique: true }); // Unique together
4+
voteSchema.index({ pollId: 1, authorId: 1 }, { unique: true }); // Unique together
55

66
export default model<VoteSchema, Model<VoteSchema>>('Vote', voteSchema);
77

models/votes/vote.schema.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { Document, Schema, Types } from 'mongoose';
22
import { Vote } from 'which-types';
33

4-
export interface VoteSchema extends Document, Omit<Vote, '_id'> {
5-
password: string;
6-
}
4+
export interface VoteSchema extends Document, Omit<Vote, '_id'> {};
75

86
export const voteSchema = new Schema({
9-
userId: {
7+
authorId: {
108
type: Types.ObjectId,
119
ref: 'user',
1210
required: true

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"mongoose": "^5.9.18",
3434
"ts-node": "^8.10.2",
3535
"typescript": "^3.9.5",
36-
"which-types": "^1.4.2"
36+
"which-types": "^1.5.1"
3737
},
3838
"repository": {
3939
"type": "git",

services/votes/votes.hooks.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import { HookContext } from '@feathersjs/feathers';
21
import requireAuth from '../../hooks/requireAuth';
3-
4-
const addUserId = async (context: HookContext): Promise<HookContext> => {
5-
const { params: { user } } = context;
6-
context.data.userId = user._id;
7-
return context;
8-
};
2+
import signAuthority from '../../hooks/signAuthority';
93

104
export default {
115
before: {
12-
create: [requireAuth, addUserId]
6+
create: [requireAuth, signAuthority]
137
}
148
};
159

0 commit comments

Comments
 (0)