feat: began adding db get methods

This commit is contained in:
Rushil Umaretiya 2021-04-10 18:59:08 -04:00
parent 956ba14e29
commit 32aa0d0a9c
No known key found for this signature in database
GPG Key ID: 4E8FAF9C926AF959
4 changed files with 10 additions and 7 deletions

View File

@ -92,6 +92,6 @@ export async function getAccountIDFromIonCode(code: string) {
if (user == null) {
return await registerUserFromIonProfile(profile);
} else {
return user.id;
return user.uuid;
}
}

View File

@ -7,7 +7,7 @@ import { UserModel } from './models';
*/
export const users: Record<string, Carpool.User> = {
myfatemi04: {
id: '3baeaed6-05cb-4c03-9b43-1d74beafdbb7',
uuid: '3baeaed6-05cb-4c03-9b43-1d74beafdbb7',
email: '2022mfatemi@tjhsst.edu',
username: 'myfatemi04',
first_name: 'Michael',
@ -72,16 +72,18 @@ export function getGroupByID(groupID: string): Carpool.Group | undefined {
export async function getUserByEmail(
email: string
): Promise<Carpool.User | undefined> {
return ((await UserModel.findOne({
email,
}).exec()) as unknown) as Carpool.User;
return ((
await UserModel.findOne({
email,
}).exec()
).toJSON() as unknown) as Carpool.User;
}
export async function registerUserFromIonProfile(
profile: IonProfile
): Promise<string> {
const user = new UserModel({
id: v4(),
uuid: v4(),
username: profile.ion_username,
email: profile.tj_email,
first_name: profile.first_name,

View File

@ -1,6 +1,7 @@
import { model, Schema } from 'mongoose';
const UserSchema: Schema = new Schema({
uuid: { type: String, required: true },
email: { type: String, required: true },
username: { type: String, required: true },
first_name: { type: String, required: true },

View File

@ -5,7 +5,7 @@ namespace Carpool {
}
export interface User {
id: string;
uuid: string;
email: string;
username: string;
first_name: string;