Skip to content

Commit

Permalink
update models
Browse files Browse the repository at this point in the history
  • Loading branch information
minhd-vu committed Feb 9, 2024
1 parent 7f5f063 commit 1029a67
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
46 changes: 33 additions & 13 deletions nextjs/models/party.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
import mongoose from "mongoose";
import { User } from "./user";
import mongoose, { Types, Schema, Document } from "mongoose";
import { User } from "./User";

export interface Party extends mongoose.Document {
export interface Party extends Document {
code: string;
players: User[];
players: Types.DocumentArray<User>;
isStarted: boolean;
gameMode: string;
showPlayers: boolean;
winner: User;
winner?: User;
}

const PartySchema = new mongoose.Schema<Party>(
const PartySchema = new Schema<Party>(
{
code: { type: String, required: true, unique: true },
players: [{ type: mongoose.Schema.Types.ObjectId, ref: "User" }],
isStarted: { type: Boolean, default: false },
gameMode: { type: String, default: "Classic" },
showPlayers: { type: Boolean, default: true },
code: {
type: String,
required: true,
unique: true,
},
players: [
{
type: Types.ObjectId,
ref: "User",
},
],
isStarted: {
type: Boolean,
default: false,
},
gameMode: {
type: String,
default: "Classic",
},
showPlayers: {
type: Boolean,
default: true,
},
winner: {
type: mongoose.Schema.Types.ObjectId,
type: Types.ObjectId,
ref: "User",
default: null,
},
},
{ timestamps: true },
{
timestamps: true,
},
);

export default mongoose.models.Party ||
Expand Down
9 changes: 5 additions & 4 deletions nextjs/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import mongoose from "mongoose";
import { Document, Schema, Types } from "mongoose";
import { Party } from "./party";
import mongoose, { Document, Schema, Types } from "mongoose";
import { Party } from "./Party";

export interface User extends Document {
email: string;
Expand Down Expand Up @@ -65,7 +64,9 @@ const UserSchema = new Schema<User>(
},
},
},
{ timestamps: true },
{
timestamps: true,
},
);

export default mongoose.models.User || mongoose.model<User>("User", UserSchema);

0 comments on commit 1029a67

Please sign in to comment.