feat: add support for multiple emails

This commit is contained in:
tdurieux
2021-09-06 09:48:49 +02:00
parent ebf104750e
commit 3fbf00c37b
3 changed files with 18 additions and 5 deletions

View File

@@ -64,19 +64,24 @@ async function connect(db) {
}).save()
);
}
const user = await new UserModel({
const user = new UserModel({
accessTokens: {
github: r.accessToken,
},
username: r.username,
email: r.profile.emails[0]?.value,
emails: r.profile.emails.map((email) => {
return { email: email.value, default: false };
}),
photo: r.profile.photos[0]?.value,
repositories: (await Promise.all(repositoryModels)).map((d) => d._id),
default: {
terms: r.default.terms,
options: r.default.options,
},
}).save();
});
if (user.emails.length) user.emails[0].default = true;
await user.save();
localResolve(user);
});

View File

@@ -9,7 +9,12 @@ const UserSchema = new Schema({
type: String,
index: { unique: true },
},
email: String,
emails: [
{
email: { type: String },
default: Boolean,
},
],
photo: String,
repositories: [String],
default: {

View File

@@ -6,7 +6,10 @@ export interface IUser {
};
username: string;
email: string;
emails: {
email: string;
default: boolean;
}[];
photo?: string;
repositories?: number[];