MCPcopy
hub / github.com/mickhansen/graphql-sequelize / argsToFindOptions

Function argsToFindOptions

src/argsToFindOptions.js:3–31  ·  view source on GitHub ↗
(args, targetAttributes)

Source from the content-addressed store, hash-verified

1import { replaceWhereOperators } from './replaceWhereOperators';
2
3export default function argsToFindOptions(args, targetAttributes) {
4 var result = {};
5
6 if (args) {
7 Object.keys(args).forEach(function (key) {
8 if (typeof args[key] !== 'undefined') {
9 if (key === 'limit') {
10 result.limit = parseInt(args[key], 10);
11 } else if (key === 'offset') {
12 result.offset = parseInt(args[key], 10);
13 } else if (key === 'order') {
14 if (args[key].indexOf('reverse:') === 0) {
15 result.order = [[args[key].substring(8), 'DESC']];
16 } else {
17 result.order = [[args[key], 'ASC']];
18 }
19 } else if (key === 'where') {
20 // setup where
21 result.where = replaceWhereOperators(args.where);
22 } else if (~targetAttributes.indexOf(key)) {
23 result.where = result.where || {};
24 result.where[key] = args[key];
25 }
26 }
27 });
28 }
29
30 return result;
31}

Callers 2

resolverFactoryFunction · 0.85

Calls 1

replaceWhereOperatorsFunction · 0.90

Tested by

no test coverage detected