Skip to content

Commit

Permalink
- npm publish 2015.6.12
Browse files Browse the repository at this point in the history
- fix version breakage with latest npm install
- add crudGetDistinctValueByFieldMany api
  • Loading branch information
kaizhu256 committed Jun 24, 2015
1 parent 96ae5f9 commit b208e67
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 43 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ width="100%" \
"dependencies": {
"mongodb-minimal": "^2.0.33-2015.06.01-f",
"swagger-ui-lite": "^2.1.0-20150619a",
"utility2": "~2015.6.11-a"
"utility2": "~2015.6.12"
},
"description": "lightweight swagger-ui crud-api backed by mongodb",
"devDependencies": {
Expand Down Expand Up @@ -302,27 +302,29 @@ node_modules/.bin/utility2 shRun node test.js",
"test": "node_modules/.bin/utility2 shRun shReadmeExportPackageJson && \
node_modules/.bin/utility2 test test.js"
},
"version": "2015.6.11-a"
"version": "2015.6.12"
}
```



# todo
- add max / min validation
- add crudIncrement
- remove required validation in crudUpdateXxx
- add createIndex feature to apiUpdate
- add distinct and aggregate crud get api
- add aggregate crud api
- add user /login /logout paths
- cap test collections
- add formData swagger parameter type
- none



# change since dbe93c42
- npm publish 2015.6.11-a
- add testCase_crudUpdateXxx_default
- add options parameter to testCase
# change since 96ae5f99
- npm publish 2015.6.12
- fix version breakage with latest npm install
- add crudGetDistinctValueByFieldMany api
- none


Expand Down
35 changes: 35 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@
options.cursor = options.collection.find(data[0], data[1], data[2]);
options.cursor.toArray(onNext);
break;
case 'crudGetDistinctValueByFieldMany':
// find data
options.collection.distinct(
options.data.field.replace((/^id$/), '_id'),
local.swmg.normalizeIdMongodb(JSON.parse(options.data.query)),
onNext
);
break;
case 'crudReplaceOne':
// replace data
options.collection.update(
Expand Down Expand Up @@ -431,6 +439,7 @@
case 'crudGetByIdOne':
options.response.data = [data];
break;
case 'crudGetDistinctValueByFieldMany':
case 'crudGetByQueryMany':
options.response.data = data;
break;
Expand All @@ -440,6 +449,10 @@
case 'crudUpdateOne':
case 'crudUpdateOrCreateOne':
options.response.meta = data;
if (!options.response.meta.n) {
onError(new Error('crud operation failed'));
return;
}
options.collection.findOne({ _id: options.data._id }, onNext);
return;
case 'crudExistsByIdOne':
Expand Down Expand Up @@ -1044,6 +1057,28 @@ local.swmg.crudSwaggerJson = { paths: {
summary: 'delete one {{schemaName}} object by id',
tags: ['{{schemaName}}']
} },
'/{{schemaName}}/crudGetDistinctValueByFieldMany': { get: {
_collectionName: '{{collectionName}}',
_crudApi: true,
operationId: 'crudGetDistinctValueByFieldMany',
parameters: [{
description: 'mongodb query param',
default: 'id',
in: 'query',
name: 'field',
required: true,
type: 'string'
}, {
description: 'mongodb query param',
default: '{}',
format: 'json',
in: 'query',
name: 'query',
type: 'string'
}],
summary: 'get distinct {{schemaName}} values by field',
tags: ['{{schemaName}}']
} },
'/{{schemaName}}/crudExistsByIdOne/{id}': { get: {
_collectionName: '{{collectionName}}',
_crudApi: true,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dependencies": {
"mongodb-minimal": "^2.0.33-2015.06.01-f",
"swagger-ui-lite": "^2.1.0-20150619a",
"utility2": "~2015.6.11-a"
"utility2": "~2015.6.12"
},
"description": "lightweight swagger-ui crud-api backed by mongodb",
"devDependencies": {
Expand Down 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.6.11-a"
"version": "2015.6.12"
}
68 changes: 34 additions & 34 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

local.testCase_crudCreateXxx_default = function (options, onError) {
/*
* this function will test _crudCreateXxx's default handling behavior
* this function will test crudCreateXxx's default handling behavior
*/
var api, modeNext, onNext, onParallel;
if (!options) {
Expand Down Expand Up @@ -87,44 +87,26 @@
case 3:
// validate object
data = data.obj.data[0];
switch (options.operationId) {
case 'crudReplaceOne':
case 'crudUpdateOne':
local.utility2.assert(data === null, data);
break;
default:
options._timeCreated = data._timeCreated;
options._timeModified = data._timeModified;
local.utility2
.assert(data.fieldExtra === 'hello', data.fieldExtra);
local.utility2
.assert(data.fieldRequired === true, data.fieldRequired);
}
options._timeCreated = data._timeCreated;
options._timeModified = data._timeModified;
local.utility2.assert(data.fieldExtra === 'hello', data.fieldExtra);
local.utility2.assert(data.fieldRequired === true, data.fieldRequired);
// get object
api.crudGetByIdOne({ id: options.id }, options, onNext);
break;
case 4:
// validate object
data = data.obj.data[0];
switch (options.operationId) {
case 'crudReplaceOne':
case 'crudUpdateOne':
local.utility2.assert(data === null, data);
break;
default:
local.utility2.assert(
data._timeCreated === options._timeCreated,
[data._timeCreated, options._timeCreated]
);
local.utility2.assert(
data._timeModified === options._timeModified,
[data._timeModified, options._timeModified]
);
local.utility2
.assert(data.fieldExtra === 'hello', data.fieldExtra);
local.utility2
.assert(data.fieldRequired === true, data.fieldRequired);
}
local.utility2.assert(
data._timeCreated === options._timeCreated,
[data._timeCreated, options._timeCreated]
);
local.utility2.assert(
data._timeModified === options._timeModified,
[data._timeModified, options._timeModified]
);
local.utility2.assert(data.fieldExtra === 'hello', data.fieldExtra);
local.utility2.assert(data.fieldRequired === true, data.fieldRequired);
if (options.modeNoDelete) {
onNext();
return;
Expand All @@ -133,6 +115,14 @@
local.testCase_crudDeleteById_default({ id: options.id }, onNext);
break;
default:
switch (options.operationId) {
case 'crudReplaceOne':
case 'crudUpdateOne':
// validate error occurred
local.utility2.assert(error, error);
error = null;
break;
}
onError(error, options);
break;
}
Expand Down Expand Up @@ -178,6 +168,7 @@
'crudCountByQuery',
'crudGetByIdOne',
'crudGetByQueryMany',
'crudGetDistinctValueByFieldMany',
'crudExistsByIdOne'
].forEach(function (operationId) {
onParallel.counter += 1;
Expand All @@ -201,6 +192,7 @@
// init api
api = local.swmg.api.TestCrudModel;
// init options
options.field = 'id';
options.limit = 1;
options.query = JSON.stringify({ id: options.id });
// create object
Expand Down Expand Up @@ -274,7 +266,7 @@

local.testCase_crudUpdateXxx_default = function (options, onError) {
/*
* this function will test _crudUpdateXxx's default handling behavior
* this function will test crudUpdateXxx's default handling behavior
*/
var api, modeNext, onNext, onParallel;
if (!options) {
Expand Down Expand Up @@ -353,6 +345,14 @@
case 4:
// validate object
data = data.obj.data[0];
local.utility2.assert(
data._timeCreated === options._timeCreated,
[data._timeCreated, options._timeCreated]
);
local.utility2.assert(
data._timeModified > options._timeModified,
[data._timeModified, options._timeModified]
);
local.utility2.assert(data.fieldRequired === false, data.fieldRequired);
switch (options.operationId) {
case 'crudReplaceOne':
Expand Down

0 comments on commit b208e67

Please sign in to comment.