From db8da4a55e5374a7060e1ba896da79fa62267b19 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Sat, 10 Apr 2021 19:15:05 -0400 Subject: [PATCH] update models --- src/auth_ion.ts | 2 +- src/models.ts | 41 +++++++++++++++++++++++++++++++++++------ src/types.ts | 39 --------------------------------------- 3 files changed, 36 insertions(+), 46 deletions(-) delete mode 100644 src/types.ts diff --git a/src/auth_ion.ts b/src/auth_ion.ts index 74a07cd..53b2ee2 100644 --- a/src/auth_ion.ts +++ b/src/auth_ion.ts @@ -92,6 +92,6 @@ export async function getAccountIDFromIonCode(code: string) { if (user == null) { return await registerUserFromIonProfile(profile); } else { - return user.uuid; + return user._id; } } diff --git a/src/models.ts b/src/models.ts index 900e581..ee3095e 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1,7 +1,22 @@ -import { model, Schema } from 'mongoose'; +import { model, Schema, Document, Model } from 'mongoose'; + +export interface User extends Document { + email: string; + username: string; + first_name: string; + last_name: string; +} + +export interface Group extends Document { + member_ids: string[]; +} + +export interface Comment { + body: string; + author_id: string; +} 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 }, @@ -12,23 +27,37 @@ UserSchema.virtual('fullName').get(function (this) { return this.firstName + this.lastName; }); -const UserModel = model('User', UserSchema); +const UserModel: Model = model('User', UserSchema); const GroupSchema: Schema = new Schema({ - id: { type: String, required: true }, member_ids: { type: [String], required: true }, }); const GroupModel = model('Group', GroupSchema); const CommentSchema: Schema = new Schema({ - id: { type: String, required: true }, text: { type: String, required: true }, author_id: { type: String, required: true }, }); const CommentModel = model('Comment', CommentSchema); +export interface Pool extends Document { + title: string; + description: string; + participant_ids: string[]; + driver_id: string; + create_time: string; + update_time: string; + comments: Comment[]; + group_id: string; + status: 'pending' | 'cancelled' | 'completed' | 'interrupted'; + capacity: number; + direction: 'pickup' | 'dropoff'; + author_id: string; + type: 'request' | 'offer'; +} + const PoolSchema: Schema = new Schema({ id: { type: String, required: true }, title: { type: String, required: true }, @@ -46,6 +75,6 @@ const PoolSchema: Schema = new Schema({ type: { type: String, required: true }, }); -const PoolModel = model('Pool', PoolSchema); +const PoolModel: Model = model('Pool', PoolSchema); export { UserModel, GroupModel, CommentModel, PoolModel }; diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index a1c2f08..0000000 --- a/src/types.ts +++ /dev/null @@ -1,39 +0,0 @@ -namespace Carpool { - export interface Group { - id: string; - member_ids: string[]; - } - - export interface User { - uuid: string; - email: string; - username: string; - first_name: string; - last_name: string; - } - - export interface Comment { - id: string; - body: string; - author_id: string; - } - - export type Status = 'pending' | 'cancelled' | 'completed' | 'interrupted'; - - export interface Pool { - id: string; - title: string; - description: string; - participant_ids: string[]; - driver_id: string; - create_time: string; - update_time: string; - comments: Comment[]; - group_id: string; - status: Status; - capacity: number; - direction: 'pickup' | 'dropoff'; - author_id: string; - type: 'request' | 'offer'; - } -}