Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4727f82
adding the .env.development and .env.production txt files
KitilCode Oct 5, 2021
79edd16
Rename: .env.development.txt to .env.development
KitilCode Oct 5, 2021
dba0100
rename: .env.production.txt to .env.production
KitilCode Oct 5, 2021
1e79ca6
removing the quotes in env.dev
KitilCode Oct 5, 2021
1c8456d
adding package.json
KitilCode Oct 5, 2021
15fe3c8
undoing changes to package files
KitilCode Oct 5, 2021
ba2581e
putting the twilio number in quotation marks
KitilCode Oct 5, 2021
1be5e71
deleting extra spaces in enviornments
KitilCode Oct 5, 2021
9253372
Delete .env.production
KitilCode Oct 6, 2021
c43f638
Delete .env.development
KitilCode Oct 6, 2021
b86a9e2
editing readme file
KitilCode Oct 9, 2021
2f4fd19
dusk add name to HelloWorldROute
KitilCode Oct 9, 2021
0f529cf
first commit
Othniel9 Oct 13, 2021
21f205a
Merge pull request #1 from duskkitil/Othniel_Bondah/first-commit
Othniel9 Oct 13, 2021
4b7aae1
adding .env.development file
Othniel9 Oct 13, 2021
fa74976
Merge pull request #2 from duskkitil/Othniel_Bondah/first-commit
Othniel9 Oct 13, 2021
e2a2936
ticket 1 complete
KitilCode Oct 13, 2021
867740f
Merge pull request #3 from duskkitil/week1tickets
KitilCode Oct 13, 2021
042b973
ticket two complete
KitilCode Oct 13, 2021
715d127
Merge pull request #4 from duskkitil/week1tickets
KitilCode Oct 13, 2021
bc6f661
tickets 3, 4, 5, and 6
KitilCode Oct 13, 2021
fcfbd64
Merge pull request #5 from duskkitil/week1tickets
KitilCode Oct 13, 2021
07aeb17
Ticket #10 still need little fixes in order to pass test successfully
Othniel9 Oct 15, 2021
f1502ad
Update README.md
KitilCode Oct 16, 2021
f24bb8a
fix error: string -> String in postSchema type parameter
KitilCode Oct 17, 2021
54ee50e
ticket 11 completed, all test passed
KitilCode Oct 17, 2021
239192c
Merge pull request #6 from duskkitil/ticket11
KitilCode Oct 17, 2021
df17ec4
Ticket #10 complete
Othniel9 Oct 21, 2021
c1df794
Merge pull request #7 from duskkitil/Ticket_10
Othniel9 Oct 21, 2021
1da6289
Ticket_13 done
Othniel9 Oct 26, 2021
9c01b73
Merge pull request #8 from duskkitil/Ticket_13
Othniel9 Oct 26, 2021
5741384
rewriting to make sure it works
KitilCode Nov 12, 2021
eb18760
ticket 16 complete, all tests passed
KitilCode Nov 12, 2021
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
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# PodSpace Template README

Skeleton code for the ColorStack Sprout Fall '21 pod project. PodSpace is a private social network for pods to stay connected with each other after the program.

## Collaborators
# PodSpace Template README

Skeleton code for the ColorStack Sprout Fall '21 pod project. PodSpace is a private social network for pods to stay connected with each other after the program.

## Collaborators

Dusk Kitil / CS @ Cornell University '25 <br>
Othniel Bondah / CS @ WPI '23
24,769 changes: 17,299 additions & 7,470 deletions package-lock.json

Large diffs are not rendered by default.

130 changes: 66 additions & 64 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,66 @@
{
"name": "@colorstack/podspace-server",
"author": "ColorStack, Inc.",
"license": "MIT",
"version": "0.1.0",
"description": "Skeleton backend code for the Sprout Fellowship '21 project.",
"scripts": {
"build": "tsc",
"copy-env:dev": "openssl base64 < ./.env.development | tr -d '\n' | pbcopy",
"copy-env:prod": "openssl base64 < ./.env.production | tr -d '\n' | pbcopy",
"dev": "env-cmd -f ./.env.development ts-node-dev src/index.ts",
"format": "prettier --ignore-path .gitignore --list-different \"**/*.+(ts|tsx)\"",
"format:fix": "prettier --ignore-path .gitignore --write \"**/*.+(ts|tsx)\"",
"lint": "eslint --ignore-path .gitignore . --ext .ts,.tsx src",
"lint:fix": "eslint --ignore-path .gitignore . --ext .ts,.tsx src --fix",
"test": "env-cmd -f ./.env.development jest --runInBand --verbose"
},
"dependencies": {
"aws-sdk": "^2.978.0",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-validator": "^6.12.1",
"helmet": "^4.6.0",
"jsonwebtoken": "^8.5.1",
"mongodb": "^3.6.9",
"mongoose": "^5.12.13",
"multer": "^1.4.3",
"twilio": "^3.67.0"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.2",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.12",
"@types/jest-in-case": "^1.0.3",
"@types/jsonwebtoken": "^8.5.4",
"@types/multer": "^1.4.7",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^4.26.1",
"@typescript-eslint/parser": "^4.26.1",
"env-cmd": "^10.1.0",
"eslint": "^7.28.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-config-rami": "^1.0.9",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sort-keys-fix": "^1.1.1",
"jest": "^27.0.4",
"jest-in-case": "^1.0.2",
"prettier": "^2.3.1",
"supertest": "^6.1.6",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.4",
"ts-node-dev": "^1.1.6",
"typescript": "^4.3.2"
}
}
{
"name": "@colorstack/podspace-server",
"author": "ColorStack, Inc.",
"license": "MIT",
"version": "0.1.0",
"description": "Skeleton backend code for the Sprout Fellowship '21 project.",
"scripts": {
"build": "tsc",
"copy-env:dev": "openssl base64 < ./.env.development | tr -d '\n' | pbcopy",
"copy-env:prod": "openssl base64 < ./.env.production | tr -d '\n' | pbcopy",
"dev": "env-cmd -f ./.env.development ts-node-dev src/index.ts",
"format": "prettier --ignore-path .gitignore --list-different \"**/*.+(ts|tsx)\"",
"format:fix": "prettier --ignore-path .gitignore --write \"**/*.+(ts|tsx)\"",
"lint": "eslint --ignore-path .gitignore . --ext .ts,.tsx src",
"lint:fix": "eslint --ignore-path .gitignore . --ext .ts,.tsx src --fix",
"test": "env-cmd -f ./.env.development jest --runInBand --verbose"
},
"dependencies": {
"aws-sdk": "^2.978.0",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-validator": "^6.13.0",
"helmet": "^4.6.0",
"jsonwebtoken": "^8.5.1",
"mathjs": "^9.5.1",
"mongodb": "^3.6.9",
"mongoose": "^5.12.13",
"multer": "^1.4.3",
"twilio": "^3.67.0"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.2",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.12",
"@types/jest-in-case": "^1.0.3",
"@types/jsonwebtoken": "^8.5.4",
"@types/multer": "^1.4.7",
"@types/node": "^16.10.9",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^4.26.1",
"@typescript-eslint/parser": "^4.26.1",
"env-cmd": "^10.1.0",
"eslint": "^7.28.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-config-rami": "^1.0.9",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sort-keys-fix": "^1.1.1",
"jest": "^27.0.4",
"jest-in-case": "^1.0.2",
"prettier": "^2.3.1",
"supertest": "^6.1.6",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.4",
"ts-node-dev": "^1.1.6",
"typescript": "^4.3.2"
}
}
125 changes: 65 additions & 60 deletions src/models/AuthCode.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,65 @@
import mongoose, { Document, Schema } from 'mongoose';

import AuthUtils from '../utils/AuthUtils';
import { Model } from '../utils/constants';
import { BaseModel } from '../utils/types';

/**
* (1.01) TODO:
* - Read this interface.
* - Delete this comment once you've done so.
*/
interface IAuthCode extends BaseModel {
/**
* Phone number in which the OTP code is associated with.
*
* There should a MAXIMUM of 1 AuthCode document per phone number. For
* example, if they submit their phone number twice at the login screen,
* and they receive 2 text messages (and different codes), then only the
* latter one will be associated with this phone number.
*/
phoneNumber: string;

/**
* 6-digit OTP code that is generated randomly. This code is
* automatically generated upon creation of an AuthCode document.

*/
value: number;
}

export type AuthCodeDocument = Document<{}, {}, IAuthCode> & IAuthCode;

const authCodeSchema: Schema<AuthCodeDocument> = new Schema<AuthCodeDocument>(
/**
* (1.03) TODO:
* - Create the schema for the AuthCodes that we'll save in the database.
* - Delete this comment and the example field.
* - Add comment(s) to explain your work.
*/
{
// Here's an example of how to add a field to the schema.
exampleField: { required: true, type: String, unique: false }
},
{ timestamps: true }
);

/**
* (1.04) TODO:
* - Add a line of code here that will elete every document in the "AuthCode"
* collection after 5 minutes (60 seconds * 5).
* - To be very clear, the only way you're going to figure this out is by
* Googling around for the answer. The solution is one line.
* - Once you find something, add the code to this document and include a link
* to the code you found in a comment.
* */

const AuthCode: mongoose.Model<AuthCodeDocument> =
mongoose.model<AuthCodeDocument>(Model.AUTH_CODE, authCodeSchema);

export default AuthCode;
/* eslint-disable prettier/prettier */
import { string } from 'mathjs';
import mongoose, { Document, Schema } from 'mongoose';

import AuthUtils from '../utils/AuthUtils';
import { Model } from '../utils/constants';
import { BaseModel } from '../utils/types';

/**
* (1.01) TODO:
* - Read this interface.
* - Delete this comment once you've done so.
*/
interface IAuthCode extends BaseModel {
/**
* Phone number in which the OTP code is associated with.
*
* There should a MAXIMUM of 1 AuthCode document per phone number. For
* example, if they submit their phone number twice at the login screen,
* and they receive 2 text messages (and different codes), then only the
* latter one will be associated with this phone number.
*/
phoneNumber: string;

/**
* 6-digit OTP code that is generated randomly. This code is
* automatically generated upon creation of an AuthCode document.

*/
value: number;
}

export type AuthCodeDocument = Document<{}, {}, IAuthCode> & IAuthCode;

const authCodeSchema: Schema<AuthCodeDocument> = new Schema<AuthCodeDocument>(
/**
* (1.03) TODO:
* - Create the schema for the AuthCodes that we'll save in the database.
* - Delete this comment and the example field.
* - Add comment(s) to explain your work.
*/
{
// Here's an example of how to add a field to the schema.
// exampleField: { required: true, type: String, unique: false }
phoneNumber: { required: true, type: String, unique: true },
value: { default: AuthUtils.generateOTP, required: true, type: String }
},
{ timestamps: true }
);

/**
* (1.04) TODO:
* - Add a line of code here that will elete every document in the "AuthCode"
* collection after 5 minutes (60 seconds * 5).
* - To be very clear, the only way you're going to figure this out is by
* Googling around for the answer. The solution is one line.
* - Once you find something, add the code to this document and include a link
* to the code you found in a comment.
* */
authCodeSchema.index({ createdAt: 1 }, { expireAfterSeconds: 60 * 2 });

const AuthCode: mongoose.Model<AuthCodeDocument> =
mongoose.model<AuthCodeDocument>(Model.AUTH_CODE, authCodeSchema);

export default AuthCode;
112 changes: 52 additions & 60 deletions src/models/Comment.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,52 @@
import mongoose, { Document, PopulatedDoc, Schema } from 'mongoose';

import TextService from '../services/TextService';
import { Model } from '../utils/constants';
import { BaseModel, ID } from '../utils/types';
import Post, { PostDocument } from './Post';
import User, { UserDocument } from './User';

/**
* TODO: (5.01)
* - Read this interface.
* - Delete this comment once you've done so.
*/
interface IComment extends BaseModel {
/**
* User that is associated with the creation of the comment.
*/
author: PopulatedDoc<UserDocument>;

/**
* Text content of the comment.
*/
content: string;

/**
* Post that the comment was created on.
*/
post: PopulatedDoc<PostDocument>;
}

export type CommentDocument = Document<{}, {}, IComment> & IComment;

const commentSchema: Schema<CommentDocument> = new Schema<CommentDocument>(
{
/**
* (5.02) TODO:
* - Create the schema for the Comments that we'll save in the database using
* the interface above as a reference.
* - Delete this comment and the example field.
* - Add comment(s) to explain your work.
*/
exampleField: { ref: Model.USER, required: false, type: ID, unique: false }
},
{ timestamps: true }
);

commentSchema.pre('save', function () {
if (this.isNew) {
/**
* TODO: (6.05)
* - Send a text to the author of the post notifying them that a podmate
* commented under it!
*/
}
});

const Comment: mongoose.Model<CommentDocument> =
mongoose.model<CommentDocument>(Model.COMMENT, commentSchema);

export default Comment;
import mongoose, { Document, PopulatedDoc, Schema } from 'mongoose';

import TextService from '../services/TextService';
import { Model } from '../utils/constants';
import { BaseModel, ID } from '../utils/types';
import Post, { PostDocument } from './Post';
import User, { UserDocument } from './User';

interface IComment extends BaseModel {
/**
* User that is associated with the creation of the comment.
*/
author: PopulatedDoc<UserDocument>;

/**
* Text content of the comment.
*/
content: string;

/**
* Post that the comment was created on.
*/
post: PopulatedDoc<PostDocument>;
}

export type CommentDocument = Document<{}, {}, IComment> & IComment;

const commentSchema: Schema<CommentDocument> = new Schema<CommentDocument>(
{
author: { ref: Model.USER, required: true, type: ID },
content: { required: true, type: String },
post: { ref: Model.POST, required: true, type: ID }
},
{ timestamps: true }
);

commentSchema.pre('save', async function () {
if (this.isNew) {
const post: PostDocument = await Post.findById(this.post);
const postAuthor: UserDocument = await User.findById(post.author);

TextService.sendText({
message: 'One of your podmates commented on your post',
to: postAuthor.phoneNumber
});
}
});

const Comment: mongoose.Model<CommentDocument> =
mongoose.model<CommentDocument>(Model.COMMENT, commentSchema);

export default Comment;
Loading