diff --git a/app.ts b/app.ts index 5d13968..6cc242b 100644 --- a/app.ts +++ b/app.ts @@ -8,7 +8,19 @@ const app = express(); app.use("/api/webhook", express.raw({ type: "*/*" })); app.use(express.json({ limit: "50mb" })); - +const allowedOrigins = [ + "http://localhost:3000", + "http://localhost:3001", + "http://localhost:3002" +] + +const corsOptions = { + origin: allowedOrigins, + optionsSuccessStatus: 200, +} + +const cors = require("cors"); +app.use(cors(corsOptions)); //setup logger // import { log, warning, error } from "./Logger"; diff --git a/data/migrations/20230920150004_create_project_app_table.ts b/data/migrations/20230920150004_create_project_app_table.ts index 958ad61..e118b9b 100644 --- a/data/migrations/20230920150004_create_project_app_table.ts +++ b/data/migrations/20230920150004_create_project_app_table.ts @@ -6,7 +6,7 @@ export async function up(knex: Knex): Promise { .createTable("project_apps", function (table) { table.increments("project_inc").primary(); table.string("project_name", 255).unique(); - table.string("project_location", 255); + table.string("contact_email", 255); table.string("related_fields", 1000); table.string("project_description", 1000); table.integer("num_students").defaultTo(0); diff --git a/data/migrations/20231011002038_update_project_apps.ts b/data/migrations/20231011002038_update_project_apps.ts new file mode 100644 index 0000000..49265e6 --- /dev/null +++ b/data/migrations/20231011002038_update_project_apps.ts @@ -0,0 +1,18 @@ +import { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { + return knex.schema.table('project_apps', function (table) { + table.string('project_hosts', 255); + table.string("contact_email", 255); + }); +} + + +export async function down(knex: Knex): Promise { + return knex.schema.table('project_apps', function (table) { + table.dropColumn('project_hosts'); + table.dropColumn("contact_email"); + }); +} + diff --git a/interfaces/ProjectApp.ts b/interfaces/ProjectApp.ts index b3ba513..0a29715 100644 --- a/interfaces/ProjectApp.ts +++ b/interfaces/ProjectApp.ts @@ -1,6 +1,8 @@ export interface ProjectAppInfo { projectName: string; projectLocation: string; + projectHosts: string; + projectContactEmail: string; relatedFields: string; relatedFieldOther: string; projectDescription: string; diff --git a/model.ts b/model.ts index 53bba4b..c6835c5 100644 --- a/model.ts +++ b/model.ts @@ -1155,22 +1155,27 @@ export const getUserDemographics = async () => { * attempts to insert prjoect application info into db * @param projectApp project application object */ - export const submitProjectAppInfo = async (projectApp: ProjectAppInfo) => { - const newRelatedFields = projectApp.relatedFields.concat(projectApp.relatedFieldOther) - .replaceAll("Other-Option", ""); - const newDesiredSkills = projectApp.skillsDesired.concat(projectApp.skillDesiredOther) - .replaceAll("Other-Option2", ""); + let newRelatedFields = projectApp.relatedFields.replaceAll(", Other-Option", "").replaceAll("-Option", ""); + if (projectApp.relatedFieldOther) { + newRelatedFields = newRelatedFields.concat(", " + projectApp.relatedFieldOther); + } + let newSkills = projectApp.skillsDesired.replaceAll(", Other-Option2", "").replaceAll("-Option", "");; + if (projectApp.skillDesiredOther) { + newSkills = newSkills.concat(", " + projectApp.skillDesiredOther); + } await db.insert({ project_name: projectApp.projectName, project_location: projectApp.projectLocation, + project_hosts: projectApp.projectHosts, + contact_email: projectApp.projectContactEmail, related_fields: newRelatedFields, project_description: projectApp.projectDescription, num_students: projectApp.numStudentsDesired, term_length: projectApp.termLength, compensation_hour: projectApp.compensationHour, start_date: projectApp.startDate, - desired_skills: newDesiredSkills + desired_skills: newSkills, }).into("project_apps"); } diff --git a/package-lock.json b/package-lock.json index 1cf8c83..a9782b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@types/supertest": "^2.0.12", "concurrently": "^7.2.2", + "cors": "^2.8.5", "dotenv": "^16.0.1", "express": "^4.18.1", "fs": "^0.0.1-security", @@ -1925,6 +1926,18 @@ "integrity": "sha512-JxbCBUdrfr6AQjOXrxoTvAMJO4HBTUIlBzslcJPAz+/KT8yk53fXun51u+RenNYvad/+Vc2DIz5o9UxlCDymFQ==", "dev": true }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -3940,6 +3953,14 @@ "node": ">=8" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.12.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", @@ -6832,6 +6853,15 @@ "integrity": "sha512-JxbCBUdrfr6AQjOXrxoTvAMJO4HBTUIlBzslcJPAz+/KT8yk53fXun51u+RenNYvad/+Vc2DIz5o9UxlCDymFQ==", "dev": true }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -8295,6 +8325,11 @@ "path-key": "^3.0.0" } }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==" + }, "object-inspect": { "version": "1.12.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", diff --git a/package.json b/package.json index 70e8cc3..405b3c4 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "dependencies": { "@types/supertest": "^2.0.12", "concurrently": "^7.2.2", + "cors": "^2.8.5", "dotenv": "^16.0.1", "express": "^4.18.1", "fs": "^0.0.1-security", diff --git a/routes/projects.ts b/routes/projects.ts index 775ecd9..16350bb 100644 --- a/routes/projects.ts +++ b/routes/projects.ts @@ -8,12 +8,14 @@ const router = express.Router(); router.post( "/create", - RateLimit(20, 1000 * 60 * 60), + RateLimit(100, 1000 * 60 * 60), async (req: Request, res: Response, next: NextFunction) => { let p: ProjectAppInfo = { projectName: req.body.projectName, projectLocation: req.body.projectLocation, + projectHosts: req.body.projectHosts, + projectContactEmail: req.body.projectContactEmail, relatedFields: req.body.relatedFields, relatedFieldOther: req.body.relatedFieldOther, projectDescription: req.body.projectDescription, @@ -28,7 +30,7 @@ router.post( if (!( p.projectName && p.projectLocation && p.relatedFields && p.projectDescription && p.numStudentsDesired && p.termLength && p.compensationHour && p.startDate - && p.skillsDesired + && p.skillsDesired && p.projectHosts && p.projectContactEmail )) { next(new StatusErrorPreset(ErrorPreset.MissingRequiredFields)); }