From 1c48408ecb9e149aae74da851ea342808c9a5af9 Mon Sep 17 00:00:00 2001 From: Rushil Umaretiya Date: Sat, 10 Apr 2021 18:33:24 -0400 Subject: [PATCH] feat: finished connected mongodb --- .env.sample | 8 ++++---- src/data.ts | 16 ++++++++++------ src/models.ts | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.env.sample b/.env.sample index e69eeae..e9acfb6 100644 --- a/.env.sample +++ b/.env.sample @@ -1,5 +1,5 @@ NODE_ENV='dev' -APP_PORT=3000 -DB_USER= -DB_PASS= -DB_URL= \ No newline at end of file +APP_PORT=5000 +DB_URL= +ION_CLIENT_ID= +ION_CLIENT_SECRET= \ No newline at end of file diff --git a/src/data.ts b/src/data.ts index 5c081bc..9f359b4 100644 --- a/src/data.ts +++ b/src/data.ts @@ -1,5 +1,6 @@ import { v4 } from 'uuid'; import { IonProfile } from './auth_ion'; +import { UserModel } from './models'; /** * Records users by id @@ -77,15 +78,18 @@ export async function getUserByEmail( export async function registerUserFromIonProfile( profile: IonProfile ): Promise { - const id = v4(); - const user: Carpool.User = { - id, + const user = new UserModel({ + id: v4(), username: profile.ion_username, email: profile.tj_email, first_name: profile.first_name, last_name: profile.last_name, - }; - users[id] = user; + }); + + user.save(function (err) { + if (err) return console.error(err); + }); + console.log('Registered user', user); - return id; + return user.id; } diff --git a/src/models.ts b/src/models.ts index 6ca9a91..f6b9308 100644 --- a/src/models.ts +++ b/src/models.ts @@ -47,4 +47,4 @@ const PoolSchema: Schema = new Schema({ const PoolModel = model('Pool', PoolSchema); -export { UserModel, GroupModel, CommentModel }; +export { UserModel, GroupModel, CommentModel, PoolModel };