Socket
Socket
Sign inDemoInstall

alphapolls

Package Overview
Dependencies
449
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.4 to 1.3.0

2

package.json
{
"name": "alphapolls",
"version": "1.2.4",
"version": "1.3.0",
"description": "polling api",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -13,4 +13,5 @@ exports.objectIds = [

exports.secondaryArgs = [
'filter',
'limit',
'sort'
'cursor'
]

@@ -17,0 +18,0 @@

const models = require('../models')
const defaultLimit = 20
const constructQuery = args => {
let query = args.primary
args.secondary = args.secondary || {}
// deal with secondary args after primary args so that in the event of a conflict, secondary args take precedence
if (args.secondary.filter) {
args.secondary.filter.forEach(filter => {
query[filter.field] = filter.expression.reduce((agg, expression) => {
let value
if (expression.type === 'Number') {
value = Number(expression.value)
}
if (expression.type === 'Date') {
value = new Date(expression.value)
}
agg[expression.operator] = value
return agg
}, {})
})
}
if (args.secondary.cursor) {
query['_id'] = { $lt: args.secondary.cursor }
}
return query
}
exports.user = async args => {
return await models.User.find(args.primary).lean()
return await models.User.find(constructQuery(args)).sort({_id: -1}).limit(args.secondary.limit || defaultLimit).lean()
}
exports.response = async args => {
return await models.Response.find(args.primary).lean()
return await models.Response.find(constructQuery(args)).sort({_id: -1}).limit(args.secondary.limit || defaultLimit).lean()
}
exports.survey_instance = async args => {
return await models.SurveyInstance.find(args.primary).lean()
return await models.SurveyInstance.find(constructQuery(args)).sort({_id: -1}).limit(args.secondary.limit || defaultLimit).lean()
}
exports.survey = async args => {
return await models.Survey.find(args.primary).lean()
return await models.Survey.find(constructQuery(args)).sort({_id: -1}).limit(args.secondary.limit || defaultLimit).lean()
}
exports.media = async args => {
return await models.Media.find(args.primary).lean()
return await models.Media.find(constructQuery(args)).sort({_id: -1}).limit(args.secondary.limit || defaultLimit).lean()
}
exports.source = async args => {
return await models.Source.find(args.primary).lean()
return await models.Source.find(constructQuery(args)).sort({_id: -1}).limit(args.secondary.limit || defaultLimit).lean()
}
exports.answer = async args => {
return await models.Answer.find(args.primary).lean()
return await models.Answer.find(constructQuery(args)).sort({_id: -1}).limit(args.secondary.limit || defaultLimit).lean()
}
exports.question = async args => {
return await models.Question.find(args.primary).lean()
return await models.Question.find(constructQuery(args)).sort({_id: -1}).limit(args.secondary.limit || defaultLimit).lean()
}

@@ -34,3 +34,3 @@ const create = require('../database').create

if (survey_instance[0].user) {
if (survey_instance[0].user.indexOf(context.user)) {
if (survey_instance[0].user.map(user => user.toString()).indexOf(context.user) > -1) {
throw new Error('the user has already submitted a response to this survey instance')

@@ -41,3 +41,3 @@ }

// make sure no answer is associated with another response
let answers = await read.answer({ primary: { _id: $in: { args.answer } } })
let answers = await read.answer({ primary: { _id: { $in: args.answer } } })
if (!answers || answers.length === 0) {

@@ -53,3 +53,3 @@ throw new Error('none of the answers specified exist')

addressedQuestions.push(answers[i].question)
addressedQuestions.push(answers[i].question.toString())
}

@@ -60,3 +60,3 @@

// make sure answers address the right questions
let survey = await read.survey({ primary: { _id: survey_instance.survey } })
let survey = await read.survey({ primary: { _id: survey_instance[0].survey } })
if (!survey || survey.length === 0) {

@@ -68,2 +68,9 @@ throw new Error('the specified survey does not exist')

// debug
console.log(answers.length)
console.log("surveyQuestions:")
console.log(surveyQuestions)
console.log("addressedQuestions:")
console.log(addressedQuestions)
if (addressedQuestions.length !== surveyQuestions.length) {

@@ -70,0 +77,0 @@ throw new Error('the addressed questions are not equivalent to the survey questions')

@@ -44,3 +44,3 @@ const read = require('../database').read

out = {
$in: value
$all: value
}

@@ -47,0 +47,0 @@ } else {

@@ -88,11 +88,22 @@ const { gql } = require('apollo-server-express')

input Expression {
type: String!
operator: String!
value: String!
}
input Filter {
field: String!
expression: [Expression!]!
}
type Query {
user(_id: String, auth_provider: String, auth_token: String, clearance: String, survey_instance: [String]): [User]
response(_id: String, survey_instance: String, date_created: String, date_modified: String, answer: [String]): [Response]
survey_instance(_id: String, survey: String, start_date: String, end_date: String, date_created: String, date_modified: String, response: [String], user: [String]): [SurveyInstance]
survey(_id: String, name: String, date_created: String, date_modified: String, topic: [String], media: [String], question: [String], survey_instance: [String]): [Survey]
media(_id: String, uri: String, title: String, content: String, source: String, date_created: String, date_modified: String, survey: [String]): [Media]
source(_id: String, name: String, website: String, date_created: String, date_modified: String, media: [String]): [Source]
answer(_id: String, question: String, value: String, date_created: String, date_modified: String, response: String): [Answer]
question(_id: String, value: String, input_type: String, data_type: String, input_minimum: Float, input_maximum: Float, allow_arbitrary: Boolean, date_created: String, date_modified: String, choice: [String], answer: [String], survey: [String]): [Question]
user(_id: String, auth_provider: String, auth_token: String, clearance: String, survey_instance: [String], filter: [Filter], limit: Int, cursor: String): [User]
response(_id: String, survey_instance: String, date_created: String, date_modified: String, answer: [String], filter: [Filter], limit: Int, cursor: String): [Response]
survey_instance(_id: String, survey: String, start_date: String, end_date: String, date_created: String, date_modified: String, response: [String], user: [String], filter: [Filter], limit: Int, cursor: String): [SurveyInstance]
survey(_id: String, name: String, date_created: String, date_modified: String, topic: [String], media: [String], question: [String], survey_instance: [String], filter: [Filter], limit: Int, cursor: String): [Survey]
media(_id: String, uri: String, title: String, content: String, source: String, date_created: String, date_modified: String, survey: [String], filter: [Filter], limit: Int, cursor: String): [Media]
source(_id: String, name: String, website: String, date_created: String, date_modified: String, media: [String], filter: [Filter], limit: Int, cursor: String): [Source]
answer(_id: String, question: String, value: String, date_created: String, date_modified: String, response: String, filter: [Filter], limit: Int, cursor: String): [Answer]
question(_id: String, value: String, input_type: String, data_type: String, input_minimum: Float, input_maximum: Float, allow_arbitrary: Boolean, date_created: String, date_modified: String, choice: [String], answer: [String], survey: [String], filter: [Filter], limit: Int, cursor: String): [Question]
}

@@ -99,0 +110,0 @@

@@ -38,3 +38,3 @@ const express = require('express')

clearance: 'admin',
user: '5c101d2275866c42526fb639'
user: '5c101d2275866c42526fc639'
}

@@ -41,0 +41,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc