Skip to content

Commit

Permalink
Merge pull request #74 from dusek2/database
Browse files Browse the repository at this point in the history
Database schemas added for user data, quests and settings
  • Loading branch information
dusek2 authored Apr 5, 2024
2 parents 1bb7973 + ed62144 commit 4fa4f35
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.env.development.local
.env.test.local
.env.production.local
yarn.lock

# Logs
npm-debug.log*
Expand Down
35 changes: 35 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

# Dependencies
/node_modules

# Production
/build

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.log

# Editor directories and files
.idea
.vscode/
*.swp
*.swo
*.swn

# OS-specific
Thumbs.db

20 changes: 20 additions & 0 deletions backend/models/quests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const mongoose = require("mongoose");
const { Schema } = mongoose;

const questSchema = new Schema({
// quest info
title: String,
description: String,
// changes that will be made to the user's stats
statImprovements: {
MeStat: Number,
WorkStat: Number,
LoveStat: Number,
},
// requirements to complete the quest
requirements: String,
});

const Quest = mongoose.model("Quest", questSchema);

module.exports = Quest;
21 changes: 21 additions & 0 deletions backend/models/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const mongoose = require("mongoose");
const { Schema } = mongoose;

const settingsSchema = new Schema({
// relates to user
userId: {
type: Schema.Types.ObjectId,
ref: "User",
required: true,
unique: true,
},
// relates to adjustments of user interface
uiPreferences: {
fontSize: { type: Number, default: 14 },
theme: { type: String, default: "light" },
},
});

const Settings = mongoose.model("Settings", settingsSchema);

module.exports = Settings;
29 changes: 23 additions & 6 deletions backend/models/user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
const mongoose = require("mongoose")
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const userSchema = new mongoose.Schema({
username: String,
password: String
})
const userSchema = new Schema({
// user info
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
name: {
first: String,
last: String,
},
completedQuiz: { type: Boolean, default: false },
// life stats
stats: {
MeStat: { type: Number, default: 0 },
WorkStat: { type: Number, default: 0 },
LoveStat: { type: Number, default: 0 },
},
// user's quests
quests: [{ type: Schema.Types.ObjectId, ref: "Quest" }],
// user's settings
settings: { type: Schema.Types.ObjectId, ref: "Settings" },
});

module.exports = mongoose.model("User", userSchema)
module.exports = mongoose.model("User", userSchema);

0 comments on commit 4fa4f35

Please sign in to comment.