From faf10edc2d68013218e552947177cee8dee5e019 Mon Sep 17 00:00:00 2001 From: lukew3 Date: Tue, 25 May 2021 20:47:43 -0400 Subject: [PATCH] moved subschemas --- backend/models/model.js | 65 ------------------------ backend/models/subschemas/config.js | 78 +++++++++++++++++++++++++++++ backend/models/subschemas/preset.js | 10 ++++ backend/models/subschemas/result.js | 38 ++++++++++++++ backend/models/subschemas/tag.js | 9 ++++ backend/models/user.js | 51 ++----------------- backend/mongo-todo.md | 5 +- 7 files changed, 144 insertions(+), 112 deletions(-) delete mode 100644 backend/models/model.js create mode 100644 backend/models/subschemas/config.js create mode 100644 backend/models/subschemas/preset.js create mode 100644 backend/models/subschemas/result.js create mode 100644 backend/models/subschemas/tag.js diff --git a/backend/models/model.js b/backend/models/model.js deleted file mode 100644 index 262fa2059..000000000 --- a/backend/models/model.js +++ /dev/null @@ -1,65 +0,0 @@ -/* -//This is the mongo model for a user -{ - "uid": 'uid', - "presets": [ - //unknown whats inside here - //can be added once one is added, and not created as blank - ], - "name", - "discordId", - "pairingCode", - "discordPairingCode", - "config", - "favouriteThemes", - "refactored", - "globalStats": { - "timeTests", - "startedTests", - "completedTests" - }, - "banned", - "verified", - "emailVerified", - "lbMemory": { - "time15", - "time60" - } - snap.name = data.name; - snap.discordId = data.discordId; - snap.pairingCode = - data.discordPairingCode == null ? undefined : data.discordPairingCode; - snap.config = data.config; - snap.favouriteThemes = - data.favouriteThemes === undefined ? [] : data.favouriteThemes; - snap.refactored = data.refactored === true ? true : false; - snap.globalStats = { - time: data.timeTyping, - started: data.startedTests, - completed: data.completedTests, - }; - snap.banned = data.banned; - snap.verified = data.verified; - snap.emailVerified = user.emailVerified; - try { - if (data.lbMemory.time15 !== undefined) { - snap.lbMemory.time15 = data.lbMemory.time15; - } - if (data.lbMemory.time60 !== undefined) { - snap.lbMemory.time60 = data.lbMemory.time60; - } - } catch {} -} - -//The user object returned by firebase.auth().currentUser - // should this be retrieved from the server everytime or is it stored in the browser - // probably browser -{ - "uid", - "name", - "emailVerified", - "displayName", - "refreshToken", - //guessing there is an access token in there somewhere, but I really don't know how this works -} -*/ diff --git a/backend/models/subschemas/config.js b/backend/models/subschemas/config.js new file mode 100644 index 000000000..179ff3079 --- /dev/null +++ b/backend/models/subschemas/config.js @@ -0,0 +1,78 @@ +const mongoose = require("mongoose"); +const Schema = mongoose.Schema; + +const configSchema = new Schema({ + theme: { type: String }, + customTheme: Boolean, + customThemeColors: [{ type: String }], + favThemes: [{ type: String }], + showKeyTips: Boolean, + showLiveWpm: Boolean, + showTimerProgress: Boolean, + smoothCaret: Boolean, + quickTab: Boolean, + punctuation: Boolean, + numbers: Boolean, + words: Number, + time: Number, + mode: String, + quoteLength: [{ type: Number }], //not sure why this is an array + language: String, + fontSize: Number, + freedomMode: Boolean, + difficulty: String, + blindMode: Boolean, + quickEnd: Boolean, + caretStyle: String, + paceCaretStyle: String, + flipTestColors: Boolean, + capsLockBackspace: Boolean, + layout: String, + confidenceMode: String, + indicateTypos: Boolean, + timerStyle: String, + colorfulMode: Boolean, + randomTheme: String, //feels like this should be a boolean + timerColor: String, + timerOpacity: String, //maybe should be a number + stopOnError: String, + showAllLines: Boolean, + keymapMode: String, + keymapStyle: String, + keymapLegendStyle: String, + keymapLayout: String, + fontFamily: String, + smoothLineScroll: Boolean, + alwaysShowDecimalPlaces: Boolean, + alwaysShowWordsHistory: Boolean, + singleListCommandLine: String, + playSoundOnError: Boolean, + playSoundOnClick: String, + startGraphsAtZero: Boolean, + swapEscAndTab: Boolean, + showOutOfFocusWarning: Boolean, + paceCaret: String, + paceCaretCustomSpeed: Number, + pageWidth: String, + chartAccuracy: Boolean, + chartStyle: String, + minWpm: String, + minWpmCustomSpeed: Number, + highlightMode: String, + alwaysShowCPM: Boolean, + enableAds: String, + hideExtraLetters: Boolean, + strictSpace: Boolean, + minAcc: String, + minAccCustom: Number, + showLiveAcc: Boolean, + monkey: Boolean, + repeatQuotes: String, + oppositeShiftMode: String, + customBackground: String, + customBackgroundSize: String, + customBackgroundFilter: [{ type: Number }], + customLayoutfluid: String, +}); + +module.exports = { configSchema }; diff --git a/backend/models/subschemas/preset.js b/backend/models/subschemas/preset.js new file mode 100644 index 000000000..303ec8cf3 --- /dev/null +++ b/backend/models/subschemas/preset.js @@ -0,0 +1,10 @@ +const mongoose = require("mongoose"); +const Schema = mongoose.Schema; +const { configSchema } = require("./config"); + +const presetSchema = new Schema({ + name: { type: String, required: true }, + config: { type: configSchema }, //not sure if preset config always follows config schema +}); + +module.exports = { presetSchema }; diff --git a/backend/models/subschemas/result.js b/backend/models/subschemas/result.js new file mode 100644 index 000000000..a1cc04b69 --- /dev/null +++ b/backend/models/subschemas/result.js @@ -0,0 +1,38 @@ +const mongoose = require("mongoose"); +const Schema = mongoose.Schema; + +const resultSchema = new Schema({ + wpm: { type: Number, required: true }, + rawWpm: { type: Number, required: true }, + correctChars: { type: Number, required: true }, + incorrectChars: { type: Number, required: true }, + allChars: { type: Number, required: true }, + acc: { type: Number, required: true }, + mode: { type: String, required: true }, //is this always string type? + mode2: { type: Number, required: true }, //is this always number type? + quoteLength: { type: Number, required: true }, + timestamp: { type: Number, required: true }, //can this be removed if timestamps are added to mongoose + language: { type: String, required: true }, + restartCount: { type: Number, required: true }, + incompleteTestSeconds: { type: Number, required: true }, + testDuration: { type: Number, required: true }, + afkDuration: { type: Number, required: true }, + theme: { type: String, required: true }, + tags: [{ type: String }], //the id of each tag + keySpacing: { type: String, required: true }, + keyDuration: { type: String, required: true }, + consistency: { type: Number, required: true }, + keyConsistency: { type: Number, required: true }, + chartData: { + //should chartData have it's own schema? + wpm: [{ type: Number }], + raw: [{ type: Number }], + err: [{ type: Number }], + }, + customText: { type: Schema.Types.Mixed }, + keySpacingStats: { type: Schema.Types.Mixed }, //not sure that this needs to exist, it's set as null in all of mine + name: { type: String, required: true }, //name of the user who took the test //should probably be typistName/username or something + isPb: { type: Boolean, required: true }, +}); + +module.exports = { resultSchema }; diff --git a/backend/models/subschemas/tag.js b/backend/models/subschemas/tag.js new file mode 100644 index 000000000..a0af7766f --- /dev/null +++ b/backend/models/subschemas/tag.js @@ -0,0 +1,9 @@ +const mongoose = require("mongoose"); +const Schema = mongoose.Schema; + +const tagSchema = new Schema({ + name: { type: String, required: true }, + personalBests: { type: Schema.Types.Mixed }, +}); + +module.exports = { tagSchema }; diff --git a/backend/models/user.js b/backend/models/user.js index 3852bdff9..9486847d5 100644 --- a/backend/models/user.js +++ b/backend/models/user.js @@ -1,51 +1,10 @@ const mongoose = require("mongoose"); const Schema = mongoose.Schema; -const tagSchema = new Schema({ - name: { type: String, required: true }, - personalBests: { type: Schema.Types.Mixed }, -}); - -const presetSchema = new Schema({ - name: { type: String, required: true }, - config: { type: Schema.Types.Mixed }, //will be config schema after it's created -}); - -const resultSchema = new Schema({ - wpm: { type: Number, required: true }, - rawWpm: { type: Number, required: true }, - correctChars: { type: Number, required: true }, - incorrectChars: { type: Number, required: true }, - allChars: { type: Number, required: true }, - acc: { type: Number, required: true }, - mode: { type: String, required: true }, //is this always string type? - mode2: { type: Number, required: true }, //is this always number type? - quoteLength: { type: Number, required: true }, - timestamp: { type: Number, required: true }, //can this be removed if timestamps are added to mongoose - language: { type: String, required: true }, - restartCount: { type: Number, required: true }, - incompleteTestSeconds: { type: Number, required: true }, - testDuration: { type: Number, required: true }, - afkDuration: { type: Number, required: true }, - theme: { type: String, required: true }, - tags: [{ type: String }], //the id of each tag - keySpacing: { type: String, required: true }, - keyDuration: { type: String, required: true }, - consistency: { type: Number, required: true }, - keyConsistency: { type: Number, required: true }, - chartData: { - //should chartData have it's own schema? - wpm: [{ type: Number }], - raw: [{ type: Number }], - err: [{ type: Number }], - }, - customText: { type: Schema.Types.Mixed }, - keySpacingStats: { type: Schema.Types.Mixed }, //not sure that this needs to exist, it's set as null in all of mine - name: { type: String, required: true }, //name of the user who took the test //should probably be typistName/username or something - isPb: { type: Boolean, required: true }, -}); - -const configSchema = new Schema({}); +const { configSchema } = require("./subschemas/config"); +const { resultSchema } = require("./subschemas/result"); +const { tagSchema } = require("./subschemas/tag"); +const { presetSchema } = require("./subschemas/preset"); const userSchema = new Schema( { @@ -83,7 +42,7 @@ const userSchema = new Schema( email: { type: String, required: true }, password: { type: String, required: true }, refreshTokens: [{ type: String, required: true }], - config: { type: Schema.Types.Mixed, default: {} }, + config: { type: configSchema, default: {} }, }, { timestamps: true, diff --git a/backend/mongo-todo.md b/backend/mongo-todo.md index d7f9e114e..0b6f65142 100644 --- a/backend/mongo-todo.md +++ b/backend/mongo-todo.md @@ -2,7 +2,6 @@ - Get google login working - Transfer leaderboard and other cloud functions -- Reverse list of results on account page - spinning wheel on account page should dissapear after data is loaded - Account data should be updated when new result is added/test completed - Add email verification @@ -22,6 +21,10 @@ - Create configSchema - Figure out if filteredResults.reverse(); in account.js is going to cause efficiency issues - Could reverse processing of results, but that would add more complexity to code +- In order to transfer users over, users should be able to be validated through firebase until they login again, when they will use their password to login. If firebase confirms that the password and email are valid, the new password will be hashed and saved to the new database + - All data is moved and retrieved via the mongo server, just authentication uses firebase + - Could force users to sign in again immediately in order to transfer users' passwords faster + - Is it worth the inconvenience though. ## After beta is ready