Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: demo preparation #106

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ PORT = <port>
The following environment variables are required for connecting the application to a MongoDB account

```
DATABASE_USER = <database-username>
DATABASE_PW = <database-password>
DATABASE_NAME = <application-database-name>
DATABASE_TEST_NAME = <test-database-name>
DATABASE_URI = <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

Expand Down
2 changes: 1 addition & 1 deletion config/config.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import convict from 'convict';
export default convict({
environment: {
format: String,
default: 'development',
default: 'production',
env: 'NODE_ENV',
},
authToken: {
Expand Down
3 changes: 2 additions & 1 deletion config/db.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import config from './config.server.config';
export function connect(
uri?: string,
options?: database.ConnectOptions,
): Promise<typeof database> {
): Promise<typeof database | undefined> {
if (config.get('environment') === 'testing') return;
Comment on lines +13 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I really should have done this instead of a resolve hack lol

const databaseURI = uri ?? config.get('databaseURI');
const databaseOptions = options ?? config.get('databaseOptions');
return database.connect(databaseURI, databaseOptions);
Expand Down
3 changes: 1 addition & 2 deletions config/db_schemas/comment.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@ const commentSchema = new Schema<IComment>(
export type CommentDocument = HydratedDocument<IComment>;

// User can be used to create new documents with the userSchema
const CommentModel =
mongoose.models.Comment || mongoose.model<IComment>('Comment', commentSchema);
const CommentModel = mongoose.model<IComment>('Comment', commentSchema);
export default CommentModel;
4 changes: 1 addition & 3 deletions config/db_schemas/community.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@ const communitySchema = new Schema<ICommunity>(

export type CommunityDocument = HydratedDocument<ICommunity>;

const CommunityModel =
mongoose.models.Community ||
mongoose.model<ICommunity>('Community', communitySchema);
const CommunityModel = mongoose.model<ICommunity>('Community', communitySchema);
export default CommunityModel;
3 changes: 1 addition & 2 deletions config/db_schemas/post.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,5 @@ const postSchema = new Schema<IPost>(
export type PostDocument = HydratedDocument<IPost>;

// Forum can be used to create new documents with the postSchema
const PostModel =
mongoose.models.Post || mongoose.model<IPost>('Post', postSchema);
const PostModel = mongoose.model<IPost>('Post', postSchema);
Copy link
Collaborator

@fishmonger45 fishmonger45 Apr 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure I need these in for test:dev because of some recompilation error of with models if it's missing. Are you removing these for any particular reason?

export default PostModel;
3 changes: 1 addition & 2 deletions config/db_schemas/user.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,5 @@ const userSchema = new Schema<IUser>(
export type UserDocument = HydratedDocument<IUser>;

// User can be used to create new documents with the userSchema
const UserModel =
mongoose.models.User || mongoose.model<IUser>('User', userSchema);
const UserModel = mongoose.model<IUser>('User', userSchema);
export default UserModel;
2 changes: 1 addition & 1 deletion controllers/user.server.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpdateUserDTO>,
res: Response<UserResponseDTO>,
) {
const authToken = req.get(config.get('authToken'));
Expand Down
15 changes: 12 additions & 3 deletions models/db.server.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
);
}
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Contributor

@justcrossheaven justcrossheaven Apr 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing "TypeError: Cannot read properties of undefined (reading 'then')" for npm run test

() => {
if (require.main === module) {
app.listen(PORT, function () {
Expand Down