mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-04-21 12:10:17 -04:00
feat: began adding db get methods
This commit is contained in:
parent
956ba14e29
commit
32aa0d0a9c
|
@ -92,6 +92,6 @@ export async function getAccountIDFromIonCode(code: string) {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return await registerUserFromIonProfile(profile);
|
return await registerUserFromIonProfile(profile);
|
||||||
} else {
|
} else {
|
||||||
return user.id;
|
return user.uuid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
src/data.ts
12
src/data.ts
|
@ -7,7 +7,7 @@ import { UserModel } from './models';
|
||||||
*/
|
*/
|
||||||
export const users: Record<string, Carpool.User> = {
|
export const users: Record<string, Carpool.User> = {
|
||||||
myfatemi04: {
|
myfatemi04: {
|
||||||
id: '3baeaed6-05cb-4c03-9b43-1d74beafdbb7',
|
uuid: '3baeaed6-05cb-4c03-9b43-1d74beafdbb7',
|
||||||
email: '2022mfatemi@tjhsst.edu',
|
email: '2022mfatemi@tjhsst.edu',
|
||||||
username: 'myfatemi04',
|
username: 'myfatemi04',
|
||||||
first_name: 'Michael',
|
first_name: 'Michael',
|
||||||
|
@ -72,16 +72,18 @@ export function getGroupByID(groupID: string): Carpool.Group | undefined {
|
||||||
export async function getUserByEmail(
|
export async function getUserByEmail(
|
||||||
email: string
|
email: string
|
||||||
): Promise<Carpool.User | undefined> {
|
): Promise<Carpool.User | undefined> {
|
||||||
return ((await UserModel.findOne({
|
return ((
|
||||||
email,
|
await UserModel.findOne({
|
||||||
}).exec()) as unknown) as Carpool.User;
|
email,
|
||||||
|
}).exec()
|
||||||
|
).toJSON() as unknown) as Carpool.User;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function registerUserFromIonProfile(
|
export async function registerUserFromIonProfile(
|
||||||
profile: IonProfile
|
profile: IonProfile
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const user = new UserModel({
|
const user = new UserModel({
|
||||||
id: v4(),
|
uuid: 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,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { model, Schema } from 'mongoose';
|
import { model, Schema } from 'mongoose';
|
||||||
|
|
||||||
const UserSchema: Schema = new Schema({
|
const UserSchema: Schema = new Schema({
|
||||||
|
uuid: { type: String, required: true },
|
||||||
email: { type: String, required: true },
|
email: { type: String, required: true },
|
||||||
username: { type: String, required: true },
|
username: { type: String, required: true },
|
||||||
first_name: { type: String, required: true },
|
first_name: { type: String, required: true },
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace Carpool {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
id: string;
|
uuid: string;
|
||||||
email: string;
|
email: string;
|
||||||
username: string;
|
username: string;
|
||||||
first_name: string;
|
first_name: string;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user