diff --git a/README.md b/README.md index 6fc772d..3013b64 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,10 @@ PORT = The following environment variables are required for connecting the application to a MongoDB account ``` -DATABASE_USER = -DATABASE_PW = -DATABASE_NAME = -DATABASE_TEST_NAME = +DATABASE_URI = ``` -> It is recommended to use a different `test-database-name` for repository forks and local testing +> It is recommended to use a different database name for repository forks and local testing #### Deployment diff --git a/config/config.server.config.ts b/config/config.server.config.ts index 93079e0..1d959c6 100644 --- a/config/config.server.config.ts +++ b/config/config.server.config.ts @@ -3,7 +3,7 @@ import convict from 'convict'; export default convict({ environment: { format: String, - default: 'development', + default: 'production', env: 'NODE_ENV', }, authToken: { diff --git a/config/db.server.config.ts b/config/db.server.config.ts index 2a3a48b..08fd710 100644 --- a/config/db.server.config.ts +++ b/config/db.server.config.ts @@ -10,7 +10,8 @@ import config from './config.server.config'; export function connect( uri?: string, options?: database.ConnectOptions, -): Promise { +): Promise { + if (config.get('environment') === 'testing') return; const databaseURI = uri ?? config.get('databaseURI'); const databaseOptions = options ?? config.get('databaseOptions'); return database.connect(databaseURI, databaseOptions); diff --git a/config/db_schemas/comment.schema.ts b/config/db_schemas/comment.schema.ts index f0d66d3..f79b092 100644 --- a/config/db_schemas/comment.schema.ts +++ b/config/db_schemas/comment.schema.ts @@ -62,6 +62,5 @@ const commentSchema = new Schema( export type CommentDocument = HydratedDocument; // User can be used to create new documents with the userSchema -const CommentModel = - mongoose.models.Comment || mongoose.model('Comment', commentSchema); +const CommentModel = mongoose.model('Comment', commentSchema); export default CommentModel; diff --git a/config/db_schemas/community.schema.ts b/config/db_schemas/community.schema.ts index 1478d4c..e7a9b71 100644 --- a/config/db_schemas/community.schema.ts +++ b/config/db_schemas/community.schema.ts @@ -38,7 +38,5 @@ const communitySchema = new Schema( export type CommunityDocument = HydratedDocument; -const CommunityModel = - mongoose.models.Community || - mongoose.model('Community', communitySchema); +const CommunityModel = mongoose.model('Community', communitySchema); export default CommunityModel; diff --git a/config/db_schemas/post.schema.ts b/config/db_schemas/post.schema.ts index 07c4dc7..960b487 100644 --- a/config/db_schemas/post.schema.ts +++ b/config/db_schemas/post.schema.ts @@ -87,6 +87,5 @@ const postSchema = new Schema( export type PostDocument = HydratedDocument; // Forum can be used to create new documents with the postSchema -const PostModel = - mongoose.models.Post || mongoose.model('Post', postSchema); +const PostModel = mongoose.model('Post', postSchema); export default PostModel; diff --git a/config/db_schemas/user.schema.ts b/config/db_schemas/user.schema.ts index fec4c40..5459daa 100644 --- a/config/db_schemas/user.schema.ts +++ b/config/db_schemas/user.schema.ts @@ -74,6 +74,5 @@ const userSchema = new Schema( export type UserDocument = HydratedDocument; // User can be used to create new documents with the userSchema -const UserModel = - mongoose.models.User || mongoose.model('User', userSchema); +const UserModel = mongoose.model('User', userSchema); export default UserModel; diff --git a/controllers/user.server.controller.ts b/controllers/user.server.controller.ts index 1860e8b..6396c5c 100644 --- a/controllers/user.server.controller.ts +++ b/controllers/user.server.controller.ts @@ -220,7 +220,7 @@ export async function userViewCurrent( * @param res HTTP request response object status code and updated user data in JSON format or error message */ export async function userUpdateCurrent( - req: Request, + req: TypedRequestBody, res: Response, ) { const authToken = req.get(config.get('authToken')); diff --git a/models/db.server.model.ts b/models/db.server.model.ts index e4b659c..34ee89b 100644 --- a/models/db.server.model.ts +++ b/models/db.server.model.ts @@ -55,6 +55,7 @@ export async function generateFakeData( displayName: faker.name.findName(firstName, lastName), hashedPassword: password.hash, salt: password.salt, + profilePicture: 'https://source.unsplash.com/random/1920x1080', }), ); } @@ -71,7 +72,7 @@ export async function generateFakeData( 'COMPSCI', ]) + Crypto.randomInt(0, 999).toString().padStart(3, '0'), description: faker.commerce.productDescription(), - img: faker.image.business(), + img: 'https://source.unsplash.com/random/1920x1080', owner: faker.random.arrayElement(users)._id, }); communities.push(community); @@ -87,7 +88,11 @@ export async function generateFakeData( upVotes: Crypto.randomInt(0, 100), downVotes: Crypto.randomInt(0, 100), attachments: faker.random.arrayElements( - [faker.image.image(), faker.image.image(), faker.image.image()], + [ + 'https://source.unsplash.com/random/1920x1080', + 'https://source.unsplash.com/random/1920x1080', + 'https://source.unsplash.com/random/1920x1080', + ], Crypto.randomInt(0, 4), ), community: community._id, @@ -108,7 +113,11 @@ export async function generateFakeData( owner: faker.random.arrayElement(users)._id, edited: false, attachments: faker.random.arrayElements( - [faker.image.image(), faker.image.image(), faker.image.image()], + [ + 'https://source.unsplash.com/random/1920x1080', + 'https://source.unsplash.com/random/1920x1080', + 'https://source.unsplash.com/random/1920x1080', + ], Crypto.randomInt(0, 4), ), upVotes: Crypto.randomInt(0, 100), diff --git a/server.ts b/server.ts index 4e47a77..f8612d5 100644 --- a/server.ts +++ b/server.ts @@ -8,9 +8,8 @@ import { logger } from './lib/middleware.lib'; const app = createApp(); const PORT = config.get('port'); -const connectFn = config.get('environment') == 'testing' ? resolve : connect; // Connect to MongoDB database -connectFn().then( +connect().then( () => { if (require.main === module) { app.listen(PORT, function () {