Skip to content

Commit

Permalink
- npm publish 2015.5.19-a
Browse files Browse the repository at this point in the history
- add _testCase_crudGetXxx_default
  • Loading branch information
kaizhu256 committed May 19, 2015
1 parent 2fdbd2e commit 8e65bce
Show file tree
Hide file tree
Showing 4 changed files with 340 additions and 118 deletions.
46 changes: 7 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ instruction
// export local
module.exports = local;
// init assets
local.utility2.cacheDict.assets['/'] = String() +
local.utility2.cacheDict.assets['/'] = '<!DOCTYPE html>\n' +
/* jslint-ignore-begin */
'<!DOCTYPE html>\n' +
'<html>\n' +
'<head>\n' +
' <meta charset="UTF-8">\n' +
Expand Down Expand Up @@ -160,9 +159,8 @@ width="100%" \
' </script>\n' +
' {{envDict.npm_config_html_body_extra}}\n' +
'</body>\n' +
'</html>\n' +
/* jslint-ignore-end */
String();
'</html>\n';
local.utility2.cacheDict.assets['/'] = local.utility2.stringFormat(
local.utility2.cacheDict.assets['/'],
{ envDict: local.utility2.envDict },
Expand Down Expand Up @@ -213,36 +211,6 @@ width="100%" \
properties: {},
'x-inheritList': [{ $ref: '#/definitions/JsonApiResource' }]
},
TestModel: {
_collectionName: 'SwmgTestCollection',
_crudApi: true,
properties: {
fieldArray: { items: {}, type: 'array' },
fieldArraySubdoc: {
items: { $ref: '#/definitions/TestModel' },
type: 'array'
},
fieldBoolean: { type: 'boolean' },
fieldInteger: { type: 'integer' },
fieldIntegerInt32: { format: 'int32', type: 'integer' },
fieldIntegerInt64: { format: 'int64', type: 'integer' },
fieldNumber: { type: 'number' },
fieldNumberDouble: { format: 'double', type: 'number' },
fieldNumberFloat: { format: 'float', type: 'number' },
fieldObject: { type: 'object' },
fieldObjectSubdoc: { $ref: '#/definitions/TestModel' },
fieldRequired: {},
fieldString: { type: 'string' },
fieldStringByte: { format: 'byte', type: 'string' },
fieldStringDate: { format: 'date', type: 'string' },
fieldStringDatetime: { format: 'date-time', type: 'string' },
fieldStringEmail: { format: 'email', type: 'string' },
fieldStringJson: { format: 'json', type: 'string' },
fieldUndefined: {}
},
required: ['fieldRequired'],
'x-inheritList': [{ $ref: '#/definitions/JsonApiResource' }]
},
UserModel: {
_collectionName: 'SwmgUserCollection',
_crudApi: true,
Expand Down Expand Up @@ -336,24 +304,24 @@ node_modules/.bin/utility2 shRun node test.js",
"test": "node_modules/.bin/utility2 shRun shReadmeExportPackageJson && \
node_modules/.bin/utility2 test test.js"
},
"version": "2015.5.17-e"
"version": "2015.5.19-a"
}
```



# todo
- add user /login /logout paths
- remove bson compiled dependency
- cap test collections
- add formData swagger parameter type
- none



# change since f7d802fd
- npm publish 2015.5.17-e
- rename namespace swmgdb to swmg
- add passwordSalt field to UserModel
# change since 2fdbd2e3
- npm publish 2015.5.19-a
- add _testCase_crudGetXxx_default
- none


Expand Down
51 changes: 30 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,10 @@
switch (options.operationId) {
case 'crudCountByQuery':
// count data
options.collection.count(JSON.parse(options.data.query), onNext);
options.collection.count(
local.swmg.normalizeIdMongodb(JSON.parse(options.data.query)),
onNext
);
break;
case 'crudCreateOne':
// insert data
Expand All @@ -342,8 +345,7 @@
options.collection.findOne({ _id: options.data._id }, onNext);
break;
case 'crudGetByQueryMany':
// find data
options.cursor = options.collection.find(
data = local.swmg.normalizeIdMongodb([
JSON.parse(options.data.query),
JSON.parse(options.data.fields),
{
Expand All @@ -352,7 +354,9 @@
skip: options.data.skip,
sort: JSON.parse(options.data.sort)
}
);
]);
// find data
options.cursor = options.collection.find(data[0], data[1], data[2]);
options.cursor.toArray(onNext);
break;
case 'crudReplaceOne':
Expand Down Expand Up @@ -390,7 +394,7 @@
);
break;
default:
onNext(new Error('invalid crud operation - ' +
onNext(new Error('undefined crud operation - ' +
options.schemaName + '.' + options.operationId));
}
break;
Expand All @@ -401,9 +405,11 @@
switch (options.operationId) {
case 'crudCountByQuery':
case 'crudGetByIdOne':
case 'crudGetByQueryMany':
options.response.data = [data];
break;
case 'crudGetByQueryMany':
options.response.data = data;
break;
case 'crudCreateOne':
case 'crudReplaceOne':
case 'crudReplaceOrCreateOne':
Expand Down Expand Up @@ -470,22 +476,25 @@
// update paths
Object.keys(options.paths).forEach(function (path) {
Object.keys(options.paths[path]).forEach(function (method) {
methodPath = options.paths[path][method];
methodPath._method = method;
methodPath._path = path;
// init methodPath.responses
local.utility2.objectSetDefault(methodPath, { responses: {
200: {
description: 'ok - ' +
'http://jsonapi.org/format/#document-structure-top-level',
schema: { $ref: '#/definitions/JsonApiResponseData' }
methodPath = local.utility2.objectSetDefault(options.paths[path][method], {
_method: method,
_path: path,
parameters: [],
responses: {
200: {
description: 'ok - ' +
'http://jsonapi.org/format/#document-structure-top-level',
schema: { $ref: '#/definitions/JsonApiResponseData' }
},
default: {
description: 'internal server error - ' +
'http://jsonapi.org/format/#errors',
schema: { $ref: '#/definitions/JsonApiResponseError' }
}
},
default: {
description: 'internal server error - ' +
'http://jsonapi.org/format/#errors',
schema: { $ref: '#/definitions/JsonApiResponseError' }
}
} }, 2);
tags: []
}, 2);
// update cacheDict.methodPath
local.swmg.cacheDict.methodPath[method.toUpperCase() + ' ' + path.replace(
(/\{.*/),
Expand Down Expand Up @@ -667,7 +676,7 @@ case 2:
break;
// parse header param
case 'header':
request.swmgParameters[param.name] = request.headers[param.name];
request.swmgParameters[param.name] = request.headers[param.name.toLowerCase()];
break;
// parse query param
case 'query':
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
"start": "npm_config_mode_auto_restart=1 node_modules/.bin/utility2 shRun node test.js",
"test": "node_modules/.bin/utility2 shRun shReadmeExportPackageJson && node_modules/.bin/utility2 test test.js"
},
"version": "2015.5.17-e"
"version": "2015.5.19-a"
}
Loading

0 comments on commit 8e65bce

Please sign in to comment.