Skip to content

Commit 75e5273

Browse files
committed
feat: migrate to latest which-types
1 parent b054bd6 commit 75e5273

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

config/default.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"local"
99
],
1010
"local": {
11-
"usernameField": "name",
11+
"usernameField": "username",
1212
"passwordField": "password"
1313
}
1414
}

models/polls/poll.model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Model, model } from 'mongoose';
22
import { PollSchema, pollSchema } from './poll.schema';
33
import { Types } from 'mongoose';
4+
import { Which } from 'which-types';
45

5-
pollSchema.methods.vote = function(userId: string, which: 'left' | 'right'): PollSchema {
6+
pollSchema.methods.vote = function(userId: string, which: Which): PollSchema {
67
const participants: Types.ObjectId[] = ['left', 'right'].reduce((acc, option) => {
78
const { votes } = this.contents[option];
89
return acc.concat(votes);

models/polls/poll.schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface PollSchema extends Document {
1010
left: ImageDataSchema;
1111
right: ImageDataSchema;
1212
};
13+
createdAt: Date;
1314
authorId: string;
1415
vote: (userId: string, which: 'left' | 'right') => PollSchema;
1516
}
@@ -28,5 +29,5 @@ export const pollSchema = new Schema({
2829
type: Types.ObjectId,
2930
ref: 'User'
3031
}
31-
});
32+
}, { timestamps: true });
3233

models/users/user.schema.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { Document, Schema } from 'mongoose';
22
import { User } from 'which-types';
33

4-
export interface UserSchema extends Document, User {
4+
export interface UserSchema extends Document, Omit<User, '_id'> {
55
password: string;
66
}
77

88
export const userSchema = new Schema({
9-
name: String,
9+
username: String,
1010
password: String,
11+
email: String,
1112
avatarUrl: {
1213
type: String,
1314
required: false
1415
},
1516
age: {
16-
type: Number
17+
type: Number,
18+
required: false
1719
}
18-
});
20+
}, { timestamps: true });
1921

package-lock.json

Lines changed: 4 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"cors": "^2.8.5",
2222
"feathers-mongoose": "^8.3.0",
2323
"lodash": "^4.17.15",
24-
"mongoose": "^5.9.18",
25-
"which-types": "^1.0.3"
24+
"mongoose": "^5.9.18"
2625
},
2726
"repository": {
2827
"type": "git",
@@ -43,6 +42,7 @@
4342
"eslint": "^7.2.0",
4443
"eslint-config-airbnb-typescript": "^8.0.2",
4544
"eslint-plugin-import": "^2.21.2",
46-
"typescript": "^3.9.5"
45+
"typescript": "^3.9.5",
46+
"which-types": "^1.3.1"
4747
}
4848
}

populateDb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ const createPoll = (authorId: string, generateImageData:()=> ImageDataSchema): P
3939
});
4040
};
4141

42-
const createUser = (name: string): Promise<UserSchema> => {
42+
const createUser = (username: string): Promise<UserSchema> => {
4343
return app.service('users').create({
4444
avatarUrl: _.sample(imageUrls) || '',
4545
password: 'supersecret',
46-
name
46+
username
4747
});
4848
};
4949

0 commit comments

Comments
 (0)