mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-04-20 11:40:16 -04:00
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
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 {
|
|
name: string;
|
|
member_ids: string[];
|
|
}
|
|
|
|
export interface Comment {
|
|
body: string;
|
|
author_id: string;
|
|
}
|
|
|
|
const UserSchema: Schema = new Schema({
|
|
email: { type: String, required: true },
|
|
username: { type: String, required: true },
|
|
first_name: { type: String, required: true },
|
|
last_name: { type: String, required: true },
|
|
});
|
|
|
|
UserSchema.virtual('fullName').get(function (this) {
|
|
return this.firstName + this.lastName;
|
|
});
|
|
|
|
const UserModel: Model<User> = model('User', UserSchema);
|
|
|
|
const GroupSchema: Schema = new Schema({
|
|
name: { type: String, required: true },
|
|
member_ids: { type: [String], required: true },
|
|
creator_id: { type: String, required: true },
|
|
});
|
|
|
|
const GroupModel: Model<Group> = model('Group', GroupSchema);
|
|
|
|
const CommentSchema: Schema = new Schema({
|
|
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({
|
|
title: { type: String, required: true },
|
|
description: { type: String, required: true },
|
|
participant_ids: { type: [String], required: true },
|
|
driver_id: { type: String, required: false },
|
|
create_time: { type: String, required: true },
|
|
update_time: { type: String, required: true },
|
|
comments: { type: [CommentSchema], required: true },
|
|
group_id: { type: String, required: true },
|
|
status: { type: String, required: true },
|
|
capacity: { type: Number, required: true },
|
|
direction: { type: String, required: true },
|
|
author_id: { type: String, required: true },
|
|
type: { type: String, required: true },
|
|
});
|
|
|
|
const PoolModel: Model<Pool> = model('Pool', PoolSchema);
|
|
|
|
export { UserModel, GroupModel, CommentModel, PoolModel };
|