mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-04-21 20:19:49 -04:00
improve registerUserFromIonProfile
This commit is contained in:
parent
01aa0f45d7
commit
9ccb0c8045
26
src/data.ts
26
src/data.ts
|
@ -1,6 +1,6 @@
|
|||
import { v4 } from 'uuid';
|
||||
import { IonProfile } from './auth_ion';
|
||||
import { UserModel } from './models';
|
||||
import { PoolModel, UserModel } from './models';
|
||||
|
||||
/**
|
||||
* Records users by id
|
||||
|
@ -58,20 +58,18 @@ export function getPoolsWithUser(userID: string) {
|
|||
}
|
||||
|
||||
export async function getUserByID(userID: string) {
|
||||
return await UserModel.findById(userID).exec();
|
||||
return (await UserModel.findById(userID).exec()).toJSON() as Carpool.User;
|
||||
}
|
||||
|
||||
export function getPoolByID(poolID: string): Carpool.Pool | undefined {
|
||||
return pools[poolID];
|
||||
export async function getPoolByID(poolID: string) {
|
||||
return (await PoolModel.findById(poolID).exec()).toJSON() as Carpool.Pool;
|
||||
}
|
||||
|
||||
export function getGroupByID(groupID: string): Carpool.Group | undefined {
|
||||
return groups[groupID];
|
||||
}
|
||||
|
||||
export async function getUserByEmail(
|
||||
email: string
|
||||
): Promise<Carpool.User | undefined> {
|
||||
export async function getUserByEmail(email: string) {
|
||||
return ((
|
||||
await UserModel.findOne({
|
||||
email,
|
||||
|
@ -83,17 +81,19 @@ export async function registerUserFromIonProfile(
|
|||
profile: IonProfile
|
||||
): Promise<string> {
|
||||
const user = new UserModel({
|
||||
id: v4(),
|
||||
username: profile.ion_username,
|
||||
email: profile.tj_email,
|
||||
first_name: profile.first_name,
|
||||
last_name: profile.last_name,
|
||||
});
|
||||
|
||||
user.save(function (err) {
|
||||
if (err) return console.error(err);
|
||||
return new Promise((resolve, reject) => {
|
||||
user.save((err, doc) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(doc._id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
console.log('Registered user', user);
|
||||
return user.id;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user