aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-24 00:58:45 +0300
committereug-vs <eug-vs@keemail.me>2020-06-24 00:58:45 +0300
commit75e527334e4e9a94b63704f87aa650c75f13891c (patch)
treec05aef37007c85321aa75b118de7d4ffe0c58b6a
parentb054bd6cf5be0eed0c17fbacec8bcc09cf013d44 (diff)
downloadwhich-api-75e527334e4e9a94b63704f87aa650c75f13891c.tar.gz
feat: migrate to latest which-types
-rw-r--r--config/default.json2
-rw-r--r--models/polls/poll.model.ts3
-rw-r--r--models/polls/poll.schema.ts3
-rw-r--r--models/users/user.schema.ts10
-rw-r--r--package-lock.json7
-rw-r--r--package.json6
-rw-r--r--populateDb.ts4
7 files changed, 20 insertions, 15 deletions
diff --git a/config/default.json b/config/default.json
index e112f3e..3d8ffd2 100644
--- a/config/default.json
+++ b/config/default.json
@@ -8,7 +8,7 @@
"local"
],
"local": {
- "usernameField": "name",
+ "usernameField": "username",
"passwordField": "password"
}
}
diff --git a/models/polls/poll.model.ts b/models/polls/poll.model.ts
index 11d0cfa..6749e5c 100644
--- a/models/polls/poll.model.ts
+++ b/models/polls/poll.model.ts
@@ -1,8 +1,9 @@
import { Model, model } from 'mongoose';
import { PollSchema, pollSchema } from './poll.schema';
import { Types } from 'mongoose';
+import { Which } from 'which-types';
-pollSchema.methods.vote = function(userId: string, which: 'left' | 'right'): PollSchema {
+pollSchema.methods.vote = function(userId: string, which: Which): PollSchema {
const participants: Types.ObjectId[] = ['left', 'right'].reduce((acc, option) => {
const { votes } = this.contents[option];
return acc.concat(votes);
diff --git a/models/polls/poll.schema.ts b/models/polls/poll.schema.ts
index 380c069..d495e4b 100644
--- a/models/polls/poll.schema.ts
+++ b/models/polls/poll.schema.ts
@@ -10,6 +10,7 @@ export interface PollSchema extends Document {
left: ImageDataSchema;
right: ImageDataSchema;
};
+ createdAt: Date;
authorId: string;
vote: (userId: string, which: 'left' | 'right') => PollSchema;
}
@@ -28,5 +29,5 @@ export const pollSchema = new Schema({
type: Types.ObjectId,
ref: 'User'
}
-});
+}, { timestamps: true });
diff --git a/models/users/user.schema.ts b/models/users/user.schema.ts
index 9030d61..ff6cbe9 100644
--- a/models/users/user.schema.ts
+++ b/models/users/user.schema.ts
@@ -1,19 +1,21 @@
import { Document, Schema } from 'mongoose';
import { User } from 'which-types';
-export interface UserSchema extends Document, User {
+export interface UserSchema extends Document, Omit<User, '_id'> {
password: string;
}
export const userSchema = new Schema({
- name: String,
+ username: String,
password: String,
+ email: String,
avatarUrl: {
type: String,
required: false
},
age: {
- type: Number
+ type: Number,
+ required: false
}
-});
+}, { timestamps: true });
diff --git a/package-lock.json b/package-lock.json
index 6f78e7c..51ac1a5 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3051,9 +3051,10 @@
}
},
"which-types": {
- "version": "1.0.3",
- "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.0.3.tgz",
- "integrity": "sha512-anON+pR6+GeT+aCRhxK0Vj3AQvo6COSOG1zPy24VDxXnxluCvK5tNmlV+1Oe771lOjl0z3LEvc1B7YL5xYtFqQ=="
+ "version": "1.3.1",
+ "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.3.1.tgz",
+ "integrity": "sha512-UU7+/FRfELIrUyZiTJkTDJ9dNxhW/ZVcWTjXn9TMtaqdIEDtu+NDFe13jZkFhlPVsVwwXa5R4n6MUa1iuLhAlg==",
+ "dev": true
},
"word-wrap": {
"version": "1.2.3",
diff --git a/package.json b/package.json
index 7b27466..3986b6c 100644
--- a/package.json
+++ b/package.json
@@ -21,8 +21,7 @@
"cors": "^2.8.5",
"feathers-mongoose": "^8.3.0",
"lodash": "^4.17.15",
- "mongoose": "^5.9.18",
- "which-types": "^1.0.3"
+ "mongoose": "^5.9.18"
},
"repository": {
"type": "git",
@@ -43,6 +42,7 @@
"eslint": "^7.2.0",
"eslint-config-airbnb-typescript": "^8.0.2",
"eslint-plugin-import": "^2.21.2",
- "typescript": "^3.9.5"
+ "typescript": "^3.9.5",
+ "which-types": "^1.3.1"
}
}
diff --git a/populateDb.ts b/populateDb.ts
index a666427..1a3b016 100644
--- a/populateDb.ts
+++ b/populateDb.ts
@@ -39,11 +39,11 @@ const createPoll = (authorId: string, generateImageData:()=> ImageDataSchema): P
});
};
-const createUser = (name: string): Promise<UserSchema> => {
+const createUser = (username: string): Promise<UserSchema> => {
return app.service('users').create({
avatarUrl: _.sample(imageUrls) || '',
password: 'supersecret',
- name
+ username
});
};