mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-04-21 12:10:17 -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 { v4 } from 'uuid';
|
||||||
import { IonProfile } from './auth_ion';
|
import { IonProfile } from './auth_ion';
|
||||||
import { UserModel } from './models';
|
import { PoolModel, UserModel } from './models';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records users by id
|
* Records users by id
|
||||||
|
@ -58,20 +58,18 @@ export function getPoolsWithUser(userID: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserByID(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 {
|
export async function getPoolByID(poolID: string) {
|
||||||
return pools[poolID];
|
return (await PoolModel.findById(poolID).exec()).toJSON() as Carpool.Pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getGroupByID(groupID: string): Carpool.Group | undefined {
|
export function getGroupByID(groupID: string): Carpool.Group | undefined {
|
||||||
return groups[groupID];
|
return groups[groupID];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserByEmail(
|
export async function getUserByEmail(email: string) {
|
||||||
email: string
|
|
||||||
): Promise<Carpool.User | undefined> {
|
|
||||||
return ((
|
return ((
|
||||||
await UserModel.findOne({
|
await UserModel.findOne({
|
||||||
email,
|
email,
|
||||||
|
@ -83,17 +81,19 @@ export async function registerUserFromIonProfile(
|
||||||
profile: IonProfile
|
profile: IonProfile
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const user = new UserModel({
|
const user = new UserModel({
|
||||||
id: v4(),
|
|
||||||
username: profile.ion_username,
|
username: profile.ion_username,
|
||||||
email: profile.tj_email,
|
email: profile.tj_email,
|
||||||
first_name: profile.first_name,
|
first_name: profile.first_name,
|
||||||
last_name: profile.last_name,
|
last_name: profile.last_name,
|
||||||
});
|
});
|
||||||
|
|
||||||
user.save(function (err) {
|
return new Promise((resolve, reject) => {
|
||||||
if (err) return console.error(err);
|
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