Skip to content

Commit

Permalink
Merge pull request #45 from DataScience-GT/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
vicente6j authored Oct 11, 2023
2 parents 9d41601 + b4f4748 commit 083a88f
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 10 deletions.
14 changes: 13 additions & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion data/migrations/20230920150004_create_project_app_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function up(knex: Knex): Promise<void> {
.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);
Expand Down
18 changes: 18 additions & 0 deletions data/migrations/20231011002038_update_project_apps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Knex } from "knex";


export async function up(knex: Knex): Promise<void> {
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<void> {
return knex.schema.table('project_apps', function (table) {
table.dropColumn('project_hosts');
table.dropColumn("contact_email");
});
}

2 changes: 2 additions & 0 deletions interfaces/ProjectApp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface ProjectAppInfo {
projectName: string;
projectLocation: string;
projectHosts: string;
projectContactEmail: string;
relatedFields: string;
relatedFieldOther: string;
projectDescription: string;
Expand Down
17 changes: 11 additions & 6 deletions model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions routes/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
}
Expand Down

0 comments on commit 083a88f

Please sign in to comment.