Skip to content
Open
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
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module.exports = {
'max-lines-per-function': ['error', { max: 75, skipComments: true }],
'no-underscore-dangle': 0,
'react/jsx-props-no-spreading': 0,
'react/prop-types': 0
'react/prop-types': 0,
'no-unused-vars': 'off',
//'@typescipt-eslint/no-unused-vars': ['error'],
'prettier/prettier': ['error', { endOfLine: 'auto' }]
}
};
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
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

Joan Nandaula / Computer Science at Georgia Tech
Ana Leonardo / Computer Science at Lehman College
Glory Ugwu / CS @ Smith College '23
14,960 changes: 7,490 additions & 7,470 deletions package-lock.json

Large diffs are not rendered by default.

129 changes: 65 additions & 64 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
{
"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.12.1",
"helmet": "^4.6.0",
"jsonwebtoken": "^8.5.1",
"mongodb": "^3.6.9",
"mongoose": "^5.13.10",
"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/mocha": "^9.0.0",
"@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"
}
}
3 changes: 2 additions & 1 deletion src/models/AuthCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const authCodeSchema: Schema<AuthCodeDocument> = new Schema<AuthCodeDocument>(
*/
{
// 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: Number }
},
{ timestamps: true }
);
Expand Down
2 changes: 1 addition & 1 deletion src/models/Reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UserDocument } from './User';
/**
* TODO: (4.01)
* - Read this enum.
* - Delete this comment.
* - Delete this comment
*/
export enum ReactionType {
FIRE = 'FIRE', // 🔥
Expand Down
2 changes: 1 addition & 1 deletion src/models/User.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import User, { UserDocument } from './User';
* npm run test User
* - Delete this comment.
*/
describe.skip('Model: User', () => {
describe('Model: User', () => {
test('User.renewToken() - Should update the refresh token.', async () => {
const { _id, refreshToken } = TEST_USER;
await TEST_USER.renewToken();
Expand Down
32 changes: 11 additions & 21 deletions src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import AuthUtils from '../utils/AuthUtils';
import { Model } from '../utils/constants';
import { AuthTokens, BaseModel } from '../utils/types';

/**
* (2.01) TODO:
* - Read this interface.
* - Delete this comment once you've done so.
*/
interface IUser extends BaseModel {
email?: string;

Expand Down Expand Up @@ -68,18 +63,18 @@ export type UserDocument = Document<{}, {}, IUser> &

const userSchema: Schema<UserDocument> = new Schema<UserDocument>(
{
/**
* (2.02) TODO:
* - Create the schema for the Users 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: { required: false, type: String, unique: false },

email: { required: false, sparse: true, type: String, unique: true },
firstName: { required: false, type: String },
instagramUrl: { required: false, type: String },
lastName: { required: false, type: String },
linkedInUrl: { required: false, type: String },
phoneNumber: { required: true, type: String, unique: true },
profilePictureKey: { required: false, type: String },
// We shouldn't be returning the refreshToken when fetching a user from
// the database, since that is sensitive information.
refreshToken: { required: false, select: false, type: String }
refreshToken: { required: false, select: false, type: String },

twitterUrl: { required: false, type: String }
},
{
timestamps: true,
Expand All @@ -93,12 +88,7 @@ type TokenArgs = {
id: string;
};

/**
* (2.03) TODO:
* - Read the below function and try to explain to yourself what's going on!
* - Delete this comment.
*/
/**
/*
* Creates and returns a new access and refresh token for the user. It also
* persists the refresh token to the database, so we can associate the token
* and lookup a user by their refresh token in our authentication flows.
Expand Down
2 changes: 1 addition & 1 deletion src/routes/HelloWorldRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class HelloWorldRoute extends BaseRoute<HelloWorldResult> {
async content(): Promise<HelloWorldResult> {
return {
message: 'Looks like the server is up and running!',
podmates: []
podmates: ['Joan B Nandaula', 'Ana Leonardo', 'Glory C Ugwu']
};
}
}
2 changes: 1 addition & 1 deletion src/routes/LoginRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TestUtils from '../utils/TestUtils';
* npm run test LoginRoute
* - Delete this comment.
*/
describe.skip('POST /login', () => {
describe('POST /login', () => {
test('If the phone number is not valid, should return a 400.', async () => {
await TestUtils.agent
.post('/login')
Expand Down
35 changes: 21 additions & 14 deletions src/routes/LoginRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,22 @@ type LoginBody = Pick<UserDocument, 'phoneNumber'>;
export default class LoginRoute extends BaseRoute<boolean> {
constructor() {
super({
/**
* TODO: (7.01)
* - Replace null with the correct route type from the RouteMethod enum
* in the constants.ts file.
* - Fill in the path string with the appropriate path to this endpoint.
* - Delete this comment.
*/
method: null,
path: '/'
method: RouteMethod.POST,
path: '/login'
});
}

/**
* Validate the following inputs:
* - body.phoneNumber
*/
middleware() {
/**
* TODO: (7.02)
* - Add a validation the returned array ensureing that the phoneNumber
* field in the body is a valid US phone number.
*/
return [];
return [
body('phoneNumber')
.isMobilePhone('en-US')
.withMessage('This is not a valid phone number')
];
}

/**
Expand All @@ -56,16 +49,30 @@ export default class LoginRoute extends BaseRoute<boolean> {
* - Send a text to the user with the code.
*/
// TODO: (7.03) Get the phone number from the request body.
const { phoneNumber } = req.body;

// TODO: (7.03) We should delete all codes that previously existed for the
// user.
await AuthCode.deleteMany({ phoneNumber });

// TODO: (7.03) Create a new AuthCode document in the database.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const authCode: AuthCodeDocument = await AuthCode.create({ phoneNumber });

// TODO: (7.03) Send a text to the user.
const wasTextSent: boolean = await TextService.sendText({
message: 'Your OTP code: $(authCode.value)',
to: phoneNumber
});

// TODO: (7.03) If the text was not sent, throw a new RouteError with status
// code 500.
if (!wasTextSent) {
throw new RouteError({
message: 'Failed to send OTP code text, please try again',
statusCode: 500
});
}

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/UpdateMeRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TestUtils from '../utils/TestUtils';
* npm run test UpdateMe
* - Delete this comment.
*/
describe.skip('PATCH /me', () => {
describe('PATCH /me', () => {
test('If the user is not authenticated, should return a 401.', async () => {
await TestUtils.agent.patch('/me').expect(401);
});
Expand Down
21 changes: 18 additions & 3 deletions src/routes/UpdateMeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export default class UpdateMeRoute extends BaseRoute<UserDocument> {
* - Fill in the path string with the appropriate path to this endpoint.
* - Delete this comment.
*/
authenticated: false,
method: null,
path: '/'
authenticated: true,
method: RouteMethod.PATCH,
path: '/me'
});
}

Expand All @@ -54,6 +54,21 @@ export default class UpdateMeRoute extends BaseRoute<UserDocument> {
.isURL()
.withMessage('The Instagram URL must be a valid URL.'),

body('linkedInUrl')
.if((value: string) => Utils.isDefined(value) && !!value.length)
.isURL()
.withMessage('The LinkedIn URL must be a valid URL.'),

body('twitterUrl')
.if((value: string) => Utils.isDefined(value) && !!value.length)
.isURL()
.withMessage('The Twitter URL must be a valid URL.'),

body('lastName')
.if((value: string) => Utils.isDefined(value))
.isLength({ min: 1 })
.withMessage('Last name cannot be empty.'),

multer().single('profilePicture')
];
}
Expand Down
33 changes: 17 additions & 16 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"outDir": "./dist",
"target": "es2018"
},
"include": ["src/**/*.ts"],
"exclude": [
"node_modules",
"src/**/*.test.ts",
"./*.config.ts",
"./jest.*.ts"
],
"typeRoots": ["./node_modules/@types"]
}
{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"outDir": "./dist",
"target": "es2018"

},
"include": ["src/**/*.ts"],
"exclude": [
"node_modules",
"src/**/*.test.ts",
"./*.config.ts",
"./jest.*.ts"
],
"typeRoots": ["./node_modules/@types"]
}