diff options
| author | eug-vs <eug-vs@keemail.me> | 2020-06-28 16:13:34 +0300 | 
|---|---|---|
| committer | eug-vs <eug-vs@keemail.me> | 2020-06-28 16:13:34 +0300 | 
| commit | 302a76985cef867f509a4180387cc45e934452d5 (patch) | |
| tree | c79d2d95a79a9b452c7161ef0303e873fe7be0c1 | |
| parent | e63122d84c65f30eb1e063504e7f16a05eb769f1 (diff) | |
| download | which-api-302a76985cef867f509a4180387cc45e934452d5.tar.gz | |
feat: improve votes
| -rw-r--r-- | hooks/signAuthority.ts | 8 | ||||
| -rw-r--r-- | models/votes/vote.model.ts | 2 | ||||
| -rw-r--r-- | models/votes/vote.schema.ts | 6 | ||||
| -rw-r--r-- | package-lock.json | 6 | ||||
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | services/votes/votes.hooks.ts | 10 | 
6 files changed, 17 insertions, 17 deletions
| diff --git a/hooks/signAuthority.ts b/hooks/signAuthority.ts new file mode 100644 index 0000000..b4d74b8 --- /dev/null +++ b/hooks/signAuthority.ts @@ -0,0 +1,8 @@ +import { HookContext } from '@feathersjs/feathers'; + +export default async (context: HookContext): Promise<HookContext> => { +  const { params: { user } } = context; +  context.data.authorId = user._id; +  return context; +}; + diff --git a/models/votes/vote.model.ts b/models/votes/vote.model.ts index df2307e..bf2dcf6 100644 --- a/models/votes/vote.model.ts +++ b/models/votes/vote.model.ts @@ -1,7 +1,7 @@  import { Model, model } from 'mongoose';  import { VoteSchema, voteSchema } from './vote.schema'; -voteSchema.index({ pollId: 1, userId: 1 }, { unique: true }); // Unique together +voteSchema.index({ pollId: 1, authorId: 1 }, { unique: true }); // Unique together  export default model<VoteSchema, Model<VoteSchema>>('Vote', voteSchema); diff --git a/models/votes/vote.schema.ts b/models/votes/vote.schema.ts index 63ba212..d8128b3 100644 --- a/models/votes/vote.schema.ts +++ b/models/votes/vote.schema.ts @@ -1,12 +1,10 @@  import { Document, Schema, Types } from 'mongoose';  import { Vote } from 'which-types'; -export interface VoteSchema extends Document, Omit<Vote, '_id'> { -  password: string; -} +export interface VoteSchema extends Document, Omit<Vote, '_id'> {};  export const voteSchema = new Schema({ -  userId: { +  authorId: {      type: Types.ObjectId,      ref: 'user',      required: true diff --git a/package-lock.json b/package-lock.json index c0621bf..7907c1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3093,9 +3093,9 @@        }      },      "which-types": { -      "version": "1.4.2", -      "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.4.2.tgz", -      "integrity": "sha512-nwcohvhH+VEA11cReLi/BgeuKHJYH7VM2BWe9OIX89CB+iaZ0+wb6oLFcIP6Vp6jw3k93yoPMe9pMBsOi4kj6w==" +      "version": "1.5.1", +      "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.5.1.tgz", +      "integrity": "sha512-/WqGky5CFI1fiBFKSZz26aUjJ1F+OAnu2QiOIjFGH4V48tL6sdiDOVZsJaZJHXYa6p/y3vql7PdX+jadfI6kvw=="      },      "word-wrap": {        "version": "1.2.3", diff --git a/package.json b/package.json index c55255c..6f48dfa 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@      "mongoose": "^5.9.18",      "ts-node": "^8.10.2",      "typescript": "^3.9.5", -    "which-types": "^1.4.2" +    "which-types": "^1.5.1"    },    "repository": {      "type": "git", diff --git a/services/votes/votes.hooks.ts b/services/votes/votes.hooks.ts index 7d0b3ba..56e9000 100644 --- a/services/votes/votes.hooks.ts +++ b/services/votes/votes.hooks.ts @@ -1,15 +1,9 @@ -import { HookContext } from '@feathersjs/feathers';  import requireAuth from '../../hooks/requireAuth'; - -const addUserId = async (context: HookContext): Promise<HookContext> => { -  const { params: { user } } = context; -  context.data.userId = user._id; -  return context; -}; +import signAuthority from '../../hooks/signAuthority';  export default {    before: { -    create: [requireAuth, addUserId] +    create: [requireAuth, signAuthority]    }  }; | 
