diff --git a/README.md b/README.md index 02bb6f2..80d4e48 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,10 @@ 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 + +Jeremiah Anim / CS @ JWU '23 +Lorena Burrell / CS @ GSU +Ekow Thompson / CS @UA +Tarah Thompson / CS @GT +Edwin Garcia-Flores / CpE @UC'22 +Colby Thompson / CS @ Cornell '23 \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8c3740e..2bab96b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7140,9 +7140,9 @@ } }, "typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.3.tgz", + "integrity": "sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA==", "dev": true }, "unbox-primitive": { diff --git a/package.json b/package.json index 6647255..41ac0a9 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,6 @@ "ts-jest": "^27.0.3", "ts-loader": "^9.2.4", "ts-node-dev": "^1.1.6", - "typescript": "^4.3.2" + "typescript": "^4.4.3" } } diff --git a/src/models/AuthCode.test.ts b/src/models/AuthCode.test.ts index 7cd879e..42ba138 100644 --- a/src/models/AuthCode.test.ts +++ b/src/models/AuthCode.test.ts @@ -8,7 +8,8 @@ import AuthCode from './AuthCode'; * npm run test AuthCode * - Delete this comment. */ -describe.skip('Model: AuthCode', () => { + +describe('Model: AuthCode', () => { test('Should auto generate an OTP for value.', async () => { // Even though we don't specify a value for the OTP code, it should // automatically generate. diff --git a/src/models/AuthCode.ts b/src/models/AuthCode.ts index 3c566a9..2b9dafa 100644 --- a/src/models/AuthCode.ts +++ b/src/models/AuthCode.ts @@ -38,10 +38,15 @@ const authCodeSchema: Schema = new Schema( * - 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 }, + phoneNumer: {required: true, type: String, unique: true}, + // value: { default: AuthUtils.generateOTP, required: true, type: Number } + value: { default: AuthUtils.generateOTP, required: true, type: Number } }, - { timestamps: true } + // { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } } + { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } } + ); /** @@ -54,6 +59,10 @@ const authCodeSchema: Schema = new Schema( * to the code you found in a comment. * */ + +// pulled from ColorStack notion helpful info +authCodeSchema.index({ createdAt: 1 }, { expireAfterSeconds: 60 * 5 }); + const AuthCode: mongoose.Model = mongoose.model(Model.AUTH_CODE, authCodeSchema); diff --git a/src/models/Comment.ts b/src/models/Comment.ts index 1f0e82e..ce7d764 100644 --- a/src/models/Comment.ts +++ b/src/models/Comment.ts @@ -32,25 +32,21 @@ export type CommentDocument = Document<{}, {}, IComment> & IComment; const commentSchema: Schema = new Schema( { - /** - * (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 } + 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', function () { +commentSchema.pre('save', async 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 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 + }); } }); diff --git a/src/models/Post.ts b/src/models/Post.ts index a12f147..89fcf3d 100644 --- a/src/models/Post.ts +++ b/src/models/Post.ts @@ -7,22 +7,12 @@ import { CommentDocument } from './Comment'; import { ReactionDocument } from './Reaction'; import User, { UserDocument } from './User'; -/** - * TODO: (3.01) - * - Read this enum. - * - Delete this comment. - */ export enum PostType { HELP = 'HELP', // Asking for help... TIL = 'TIL', // Today I learned... WIN = 'WIN' // Sharing a win... } -/** - * TODO: (3.02) - * - Read this interface. - * - Delete this comment once you've done so. - */ interface IPost extends BaseModel { /** * User that is associated with the creation of the post. @@ -55,14 +45,8 @@ export type PostDocument = Document<{}, {}, IPost> & IPost; const postSchema: Schema = new Schema( { - /** - * TODO: (3.03) - * - Create the schema for the Posts 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: true, type: String } + author: { ref: Model.USER, required: true, type: ID }, + content: { required: true, type: String } }, { timestamps: true, @@ -74,11 +58,16 @@ const postSchema: Schema = new Schema( const sendNotification = async function ( author: PopulatedDoc ) { - /** - * TODO: (6.04) - * - Send a text to all the users except for the author of this post letting - * them know that their podmate shared an update! - */ + const allUSers: UserDocument[] = await User.find(); + allUSers.map((user) => { + if (user != author) { + TextService.sendText( { + message: 'One of your podmates shared an update!', + to: user.phoneNumber + + }); + } + }); }; postSchema.pre('save', function () { diff --git a/src/routes/HelloWorldRoute.ts b/src/routes/HelloWorldRoute.ts index 3be9b5e..d76490e 100644 --- a/src/routes/HelloWorldRoute.ts +++ b/src/routes/HelloWorldRoute.ts @@ -19,7 +19,13 @@ export default class HelloWorldRoute extends BaseRoute { async content(): Promise { return { message: 'Looks like the server is up and running!', - podmates: [] + podmates: [ + 'Lorena Burrell', + 'Jeremiah Anim', + 'Ekow Thompson', + 'Tarah Thompson', + 'Edwin Garcia-Flores' + ] }; } } diff --git a/src/services/TextService.test.ts b/src/services/TextService.test.ts index 9dc4894..5c1ff8c 100644 --- a/src/services/TextService.test.ts +++ b/src/services/TextService.test.ts @@ -1,14 +1,8 @@ import { APP } from '../utils/constants'; import TextService, { client } from './TextService'; -/** - * TODO: (6.05) - * - Remove the ".skip" from the following function. - * - Go to your terminal and run the following command: - * npm run test TextService - * - Delete this comment. - */ -describe.skip('TextService.sendText()', () => { + +describe('TextService.sendText()', () => { // Mock the twilio "sending" functionality. client.messages.create = jest.fn(); diff --git a/src/services/TextService.ts b/src/services/TextService.ts index f5565d9..c16d03e 100644 --- a/src/services/TextService.ts +++ b/src/services/TextService.ts @@ -40,8 +40,15 @@ const sendText = async ({ message, to }: SendTextArgs): Promise => { try { // Send the text + await client.messages.create({ + body: message, + from: APP.TWILIO_PHONE_NUMBER, + to: to + + }); } catch (e) { // What should be return if sending the text was unsuccessful? + return false; } return true; diff --git a/src/utils/AuthUtils.ts b/src/utils/AuthUtils.ts index f42d3b2..25cef76 100644 --- a/src/utils/AuthUtils.ts +++ b/src/utils/AuthUtils.ts @@ -14,7 +14,8 @@ const generateOTP = (): number => { * - Make sure tall the tests pass. * - Delete this comment. */ - return 123456; + return Math.floor(100000 + Math.random() * 900000); + }; /**