Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Multipage Error & Adding Completion Stamps #43

Merged
merged 8 commits into from
Nov 23, 2021
Merged
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,7 @@ dist
# Application outputs
.data
built
*.pem
*.pem

# package lock
package-lock.json
28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,19 @@ Surveyor generates data driven surveys for online participants. It imports surve

## Development
Create an `.env` file in the root directory and add:

For local mongo development
Do not use any of the following config variables with KEY in production.
```PowerShell
PORT=4000
PROD=False
MONGO=True
TEST_URI=mongodb://localhost:27017/
PROD=FALSE
URI=mongodb://localhost:27017
TEST_DB=testDB
PROD_URI=nothing
PROD_DB=nothing
```

For local nedb development
```PowerShell
PORT=4000
PROD=False
MONGO=False
TEST_URI=nothing
TEST_DB=nothing
PROD_URI=nothing
PROD_DB=nothing
PROD_DB=prodDB
RANDOM=TESTISRANDOM
TOKEN_KEY=TESTISRANDOM
SECRET_KEY=TESTISRANDOM
ENCRYPT_KEY=TESTISRANDOM
IV_KEY=a0f5c2b327abb291c7cecdea1b2f8cc5
DOMAIN=http://localhost:4000/
```

Run `npm install` to install all dependencies. Run `npm test` to launch continuous Typescript compilation, watching for changes in any of the `ts` files. Leave this shell alone and, in a new one, run `npm start` to launch the application on the port in `.env`. With this setting it would start a server at [`localhost:4000`](http://localhost:4000).
Expand Down
2 changes: 1 addition & 1 deletion config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import exp = require("constants");

const env_config = {
PORT: parseInt(process.env.PORT),
URI: process.env.PROD.toLowerCase() == "true" ? process.env.PROD_URI : process.env.TEST_URI,
URI: process.env.URI,
DB: process.env.PROD.toLowerCase() == "true" ? process.env.PROD_DB : process.env.TEST_DB,
RANDOM: process.env.RANDOM,
TOKEN_KEY: process.env.TOKEN_KEY,
Expand Down
2 changes: 1 addition & 1 deletion util.ts → helpers/encrypt_utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import crypto = require("crypto")
import {Db_Wrapper, env_config} from "./config"
import {Db_Wrapper, env_config} from "../config"

const private_key = crypto.scryptSync(env_config.ENCRYPT_KEY, "salt", 32)
const iv = Buffer.from(env_config.IV_KEY, 'hex')
Expand Down
56 changes: 56 additions & 0 deletions helpers/survey_helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { response } from "express";
import { Request, Response } from "express-serve-static-core";
import {Db_Wrapper, env_config} from "../config"

export const setPageNums = (survey) => {
var pagefinal = 0

survey.forEach((elem) => {
elem["page"] = Number(elem["page"])
pagefinal = Math.max(Number(elem["page"]), pagefinal)
})

return pagefinal
}

export const setSurveyResponse = (req: Request<{}>) => {
let response = {...req.body}
if (response.start_time) {
response["start_time"] = new Date(response["start_time"])
}

if (response.sent) {
response["sent"] = new Date(response["sent"])
}

response["raw_data"] = "Surveyor_Incomplete"

delete response["_csrf"]
delete response["start"]
delete response["check"]
delete response["final"]
delete response["curr_page"]
return response
}

export const setSurveyCompleted = () => {
const completion_stamp = {}
completion_stamp["paid"] = false
completion_stamp["end_time"] = new Date()
completion_stamp["raw_data"] = "Surveyor"

return completion_stamp
}

export const isSurveyCompleted = async (parsed) => {

let queries: any[] = await Db_Wrapper.find({
"url": parsed.url,
"WorkerId": parsed.WorkerId,
"sent": new Date(parsed.sent),
"paid": {"$exists": 1}
}, "responses")

return !(queries.length == 0)
}

83 changes: 19 additions & 64 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion routes/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express = require('express')
const bycrpyt = require('bcryptjs')
const jwt = require('jsonwebtoken')
import {Db_Wrapper, env_config} from "../config"
import { encrypt, decrypt } from "../util"
import { encrypt, decrypt } from "../helpers/encrypt_utils"
import { verifyAdminToken } from "../middlewares/auth.middleware"
const router = express.Router()

Expand Down
Loading