diff --git a/CHANGELOG.md b/CHANGELOG.md index 8120274e..8ec3b78a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,70 @@ +#### 1.6.0 (2019-08-29) + +##### Chores + +- **deps:** + - remove unused ([e2934b4f](https://github.com/CodeTanzania/majifix-status/commit/e2934b4fb0645ec83869a602af0b861b7f599596)) + - force latest version & audit fix ([90ca36a1](https://github.com/CodeTanzania/majifix-status/commit/90ca36a1d9ac28bb4fc86d14f36e5509fd3d4913)) + - force latest version & audit fix ([2e007ae7](https://github.com/CodeTanzania/majifix-status/commit/2e007ae7a493876a3d1b6dd14de4d9c5af43e9aa)) + - update dependency rollup to v1.20.3 ([34a3fc34](https://github.com/CodeTanzania/majifix-status/commit/34a3fc3497fc8de6f61e01520f78012f9f5e680a)) + - add express-test-helpers ([7d8a89fd](https://github.com/CodeTanzania/majifix-status/commit/7d8a89fd02a4aa7b8d4704dc714ffe3e436357cd)) + - update dependency lint-staged to v9.2.5 ([de854894](https://github.com/CodeTanzania/majifix-status/commit/de854894d4750c35bf8da0079d7adebabb24fcd5)) + - update dependency mongoose to v5.6.11 ([04570c05](https://github.com/CodeTanzania/majifix-status/commit/04570c05c731b16fb14a6fdc9bde868ae627ee7f)) + - update dependency lint-staged to v9.2.4 ([904daba3](https://github.com/CodeTanzania/majifix-status/commit/904daba30212dc36c61bcbc440b0840793cac8c3)) + - update dependency rollup to v1.20.2 ([5246a5ba](https://github.com/CodeTanzania/majifix-status/commit/5246a5ba4c7d49299ef013f9cb4e244e5adc9626)) + - update dependency eslint to v6.2.2 ([26c29c22](https://github.com/CodeTanzania/majifix-status/commit/26c29c229a49ffc4caa9b22b35c6ff26567e83c3)) + - update dependency rollup to v1.20.1 ([5f95401f](https://github.com/CodeTanzania/majifix-status/commit/5f95401f9e7cb78d79dad14d0c4e646a5a6d1395)) + - update dependency eslint-plugin-mocha to v6.1.0 ([641975bd](https://github.com/CodeTanzania/majifix-status/commit/641975bd4999f0743b7968e95b44779cded8b0b2)) + - update dependency rollup to v1.20.0 ([578a1c19](https://github.com/CodeTanzania/majifix-status/commit/578a1c19d5df4d0ed75361eb3e14626bee3414f3)) + - update dependency mongoose to v5.6.10 ([f2d1aa56](https://github.com/CodeTanzania/majifix-status/commit/f2d1aa5642a886e75ba2864f86f7bb525d025bf0)) + - update dependency eslint to v6.2.1 ([ffbb7bac](https://github.com/CodeTanzania/majifix-status/commit/ffbb7bac1d45a7b1399e277e895db3cf5713b6c1)) +- **examples:** improve sample app & seed ([b3055332](https://github.com/CodeTanzania/majifix-status/commit/b30553329f9ba779f0485304b47e57a937fdb449)) +- **lint:** ignore apidoc ([2643646d](https://github.com/CodeTanzania/majifix-status/commit/2643646d2d5b10755bb4ea9b01bac09d4cb86b3b)) +- **configs:** + - update eslint configs ([c4232330](https://github.com/CodeTanzania/majifix-status/commit/c4232330d61ce7482ef9ac1c62538600832c6784)) + - update prettier configs ([530472ef](https://github.com/CodeTanzania/majifix-status/commit/530472ef5ff1611f179ea5d38b198becf4418e5d)) + - update npm files ([5e6dff2f](https://github.com/CodeTanzania/majifix-status/commit/5e6dff2f6c4d6acf65e1c04386ee09f7b397de9b)) + - update git files ([bfe1f0ea](https://github.com/CodeTanzania/majifix-status/commit/bfe1f0ea731e2a0cb8108b94bce8effbea8cf388)) + - update editor configs ([a1fb9244](https://github.com/CodeTanzania/majifix-status/commit/a1fb92442b86ed867d6f57d70a4128e06dac5334)) + - update babel configs ([e575b353](https://github.com/CodeTanzania/majifix-status/commit/e575b353713e290b7b263360b08ec38be3f13cca)) +- **ci:** update travis configs ([dec3b175](https://github.com/CodeTanzania/majifix-status/commit/dec3b175dd05aa40b92ef0be4c11a4f4c062d22c)) +- remove unused apidocs ([a1ecff01](https://github.com/CodeTanzania/majifix-status/commit/a1ecff01d6fd378f1a7af4aa04f5ee1fe9a324f3)) + +##### Documentation Changes + +- update usage docs ([e6d93f52](https://github.com/CodeTanzania/majifix-status/commit/e6d93f529f0b4767a02f4bb045985c2e55caf135)) +- update requirements version ([c7764e44](https://github.com/CodeTanzania/majifix-status/commit/c7764e448b9ea0ec607400f1293c9d7108872687)) +- update status badges ([9518aeb0](https://github.com/CodeTanzania/majifix-status/commit/9518aeb0a3ff22c819f9635ed16baeaba05a2f72)) +- update contributor guide and code of conduct ([51997a9b](https://github.com/CodeTanzania/majifix-status/commit/51997a9b0d21a786465c59e48de4e7f5f23f3541)) +- **changelog:** generate latest release notes ([4ad28c85](https://github.com/CodeTanzania/majifix-status/commit/4ad28c85a703587f9a701ed330f039fd93a67dfb)) + +##### Bug Fixes + +- **model:** ensure name for all locales ([a6915ded](https://github.com/CodeTanzania/majifix-status/commit/a6915dedafee00cf56f0a4881d525d6088d8abae)) + +##### Refactors + +- **test:** improve local imports ([dd7d41a1](https://github.com/CodeTanzania/majifix-status/commit/dd7d41a1257c429c464a3e544877be476f78dafb)) +- improve package script & main export style ([eb6680b0](https://github.com/CodeTanzania/majifix-status/commit/eb6680b0c9c4a10601b07b4ccad25f29ef047426)) +- **router:** + - extract apidoc & use jsdocs ([d4913ff4](https://github.com/CodeTanzania/majifix-status/commit/d4913ff4b2f88fbb7cacb459689989c6fb5cd6e0)) + - rename http router ([fb93840f](https://github.com/CodeTanzania/majifix-status/commit/fb93840fad0f4b630b50b820ee16000ced82d281)) +- **src:** re-structure ([cd4fea5b](https://github.com/CodeTanzania/majifix-status/commit/cd4fea5bd7a9c1e1b04915d1b615f2e793d422d2)) + +##### Code Style Changes + +- fix jsdoc warnings ([496a6acc](https://github.com/CodeTanzania/majifix-status/commit/496a6accea97226aed3de030d8e306c82e6b902b)) +- **lint:** run lint fix style ([b724f962](https://github.com/CodeTanzania/majifix-status/commit/b724f96256e64c0a18d4cd0a1b75aae7970bff64)) + +##### Tests + +- **integration:** + - improve test ([91bc0279](https://github.com/CodeTanzania/majifix-status/commit/91bc0279687b04eeab1a3b2d9db22fedb5f164c7)) + - rename file and missing tests ([e3ee12aa](https://github.com/CodeTanzania/majifix-status/commit/e3ee12aa7f29ecdc9f95b8fc13feb70d90b1b157)) +- **unit:** + - improve tests and structure ([ab0b1956](https://github.com/CodeTanzania/majifix-status/commit/ab0b19565638d05f2ad7bad013ba5fdde7cc83cd)) + - refactor and add expose autopopulate test ([34abb055](https://github.com/CodeTanzania/majifix-status/commit/34abb055a11783969e4846b1302cd6ac626e5b2c)) + #### 1.5.1 (2019-08-20) #### 1.5.0 (2019-08-19) diff --git a/es/index.js b/es/index.js index 459c68b0..d3ae7479 100644 --- a/es/index.js +++ b/es/index.js @@ -5,13 +5,25 @@ import { compact, pkg, } from '@lykmapipo/common'; +import { getString, apiVersion as apiVersion$1 } from '@lykmapipo/env'; +import { + Router, + getFor, + schemaFor, + downloadFor, + postFor, + getByIdFor, + patchFor, + putFor, + deleteFor, +} from '@lykmapipo/express-rest-actions'; import _ from 'lodash'; import { model, createSchema, ObjectId } from '@lykmapipo/mongoose-common'; import { localizedIndexesFor, localize, - localizedKeysFor, localizedValuesFor, + localizedKeysFor, } from 'mongoose-locale-schema'; import actions from 'mongoose-rest-actions'; import exportable from '@lykmapipo/mongoose-exportable'; @@ -25,18 +37,17 @@ import { MODEL_NAME_SERVICEREQUEST, PATH_NAME_STATUS, } from '@codetanzania/majifix-common'; -import { getString } from '@lykmapipo/env'; -import { - Router, - getFor, - schemaFor, - downloadFor, - postFor, - getByIdFor, - patchFor, - putFor, - deleteFor, -} from '@lykmapipo/express-rest-actions'; + +export { start } from '@lykmapipo/express-rest-actions'; + +/* constants */ +const OPTION_SELECT = { name: 1, color: 1 }; +const OPTION_AUTOPOPULATE = { + select: OPTION_SELECT, + maxDepth: POPULATION_MAX_DEPTH, +}; +const SCHEMA_OPTIONS = { collection: COLLECTION_NAME_STATUS }; +const INDEX_UNIQUE = { jurisdiction: 1, ...localizedIndexesFor('name') }; /** * @module Status @@ -55,23 +66,6 @@ import { * @version 1.0.0 * @public */ - -/* constants */ -const OPTION_SELECT = { name: 1, color: 1 }; -const OPTION_AUTOPOPULATE = { - select: OPTION_SELECT, - maxDepth: POPULATION_MAX_DEPTH, -}; -const SCHEMA_OPTIONS = { collection: COLLECTION_NAME_STATUS }; -const INDEX_UNIQUE = { jurisdiction: 1, ...localizedIndexesFor('name') }; - -/** - * @name StatusSchema - * @type {Schema} - * @since 0.1.0 - * @version 1.0.0 - * @private - */ const StatusSchema = createSchema( { /** @@ -246,7 +240,8 @@ StatusSchema.index(INDEX_UNIQUE, { unique: true }); /** * @name validate * @description status schema pre validation hook - * @param {function} done callback to invoke on success or error + * @param {Function} done callback to invoke on success or error + * @returns {object|Error} valid instance or error * @since 0.1.0 * @version 1.0.0 * @private @@ -264,27 +259,31 @@ StatusSchema.pre('validate', function preValidate(next) { /** * @name preValidate * @description status schema pre validation hook logic - * @param {function} done callback to invoke on success or error + * @param {Function} done callback to invoke on success or error + * @returns {object|Error} valid instance or error * @since 0.1.0 * @version 1.0.0 * @instance */ StatusSchema.methods.preValidate = function preValidate(done) { + // ensure name for all locales + this.name = localizedValuesFor(this.name); + // set default color if not set if (_.isEmpty(this.color)) { this.color = randomColor(); } // continue - return done(); + return done(null, this); }; /** * @name beforeDelete * @function beforeDelete * @description pre delete status logics - * @param {function} done callback to invoke on success or error - * + * @param {Function} done callback to invoke on success or error + * @returns {object|Error} valid instance or error * @since 0.1.0 * @version 1.0.0 * @instance @@ -317,8 +316,8 @@ StatusSchema.statics.OPTION_AUTOPOPULATE = OPTION_AUTOPOPULATE; * @name findDefault * @function findDefault * @description find default status - * @param {function} done a callback to invoke on success or failure - * @return {Status} default status + * @param {Function} done a callback to invoke on success or failure + * @returns {Status} default status * @since 0.1.0 * @version 1.0.0 * @static @@ -335,8 +334,8 @@ StatusSchema.statics.findDefault = done => { * @name prepareSeedCriteria * @function prepareSeedCriteria * @description define seed data criteria - * @param {Object} seed status to be seeded - * @returns {Object} packed criteria for seeding + * @param {object} seed status to be seeded + * @returns {object} packed criteria for seeding * * @author lally elias * @since 1.5.0 @@ -360,9 +359,9 @@ StatusSchema.statics.prepareSeedCriteria = seed => { * @name getOneOrDefault * @function getOneOrDefault * @description Find existing status or default based on given criteria - * @param {Object} criteria valid query criteria + * @param {object} criteria valid query criteria * @param {Function} done callback to invoke on success or error - * @returns {Object|Error} found status or error + * @returns {object|Error} found status or error * * @author lally elias * @since 1.5.0 @@ -403,10 +402,19 @@ StatusSchema.statics.getOneOrDefault = (criteria, done) => { /* export status model */ const Status = model(MODEL_NAME_STATUS, StatusSchema); +/* constants */ +const API_VERSION = getString('API_VERSION', '1.0.0'); +const PATH_SINGLE = '/statuses/:id'; +const PATH_LIST = '/statuses'; +const PATH_EXPORT = '/statuses/export'; +const PATH_SCHEMA = '/statuses/schema/'; +const PATH_JURISDICTION = '/jurisdictions/:jurisdiction/statuses'; + /** - * @apiDefine Status Status + * @name StatusHttpRouter + * @namespace StatusHttpRouter * - * @apiDescription A representation of an entity which provides a way + * @description A representation of an entity which provides a way * to set flags on service requests(issues) in order to track * their progress. * @@ -417,36 +425,14 @@ const Status = model(MODEL_NAME_STATUS, StatusSchema); * @version 1.0.0 * @public */ - -/* constants */ -const API_VERSION = getString('API_VERSION', '1.0.0'); -const PATH_SINGLE = '/statuses/:id'; -const PATH_LIST = '/statuses'; -const PATH_EXPORT = '/statuses/export'; -const PATH_SCHEMA = '/statuses/schema/'; -const PATH_JURISDICTION = '/jurisdictions/:jurisdiction/statuses'; - -/* declarations */ const router = new Router({ version: API_VERSION, }); /** - * @api {get} /statuses List Statuses - * @apiVersion 1.0.0 - * @apiName GetStatuses - * @apiGroup Status - * @apiDescription Returns a list of statuses - * @apiUse RequestHeaders - * @apiUse Statuses - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusesSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name GetStatuses + * @memberof StatusHttpRouter + * @description Returns a list of statuses */ router.get( PATH_LIST, @@ -456,12 +442,9 @@ router.get( ); /** - * @api {get} /statuses/schema Get Status Schema - * @apiVersion 1.0.0 - * @apiName GetStatusSchema - * @apiGroup Status - * @apiDescription Returns status json schema definition - * @apiUse RequestHeaders + * @name GetStatusSchema + * @memberof StatusHttpRouter + * @description Returns status json schema definition */ router.get( PATH_SCHEMA, @@ -474,12 +457,9 @@ router.get( ); /** - * @api {get} /statuses/export Export Statuses - * @apiVersion 1.0.0 - * @apiName ExportStatuses - * @apiGroup Status - * @apiDescription Export statuses as csv - * @apiUse RequestHeaders + * @name ExportStatuses + * @memberof StatusHttpRouter + * @description Export statuses as csv */ router.get( PATH_EXPORT, @@ -493,21 +473,9 @@ router.get( ); /** - * @api {post} /statuses Create New Status - * @apiVersion 1.0.0 - * @apiName PostStatus - * @apiGroup Status - * @apiDescription Create new status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name PostStatus + * @memberof StatusHttpRouter + * @description Create new status */ router.post( PATH_LIST, @@ -517,21 +485,9 @@ router.post( ); /** - * @api {get} /statuses/:id Get Existing Status - * @apiVersion 1.0.0 - * @apiName GetStatus - * @apiGroup Status - * @apiDescription Get existing status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name GetStatus + * @memberof StatusHttpRouter + * @description Get existing status */ router.get( PATH_SINGLE, @@ -541,21 +497,9 @@ router.get( ); /** - * @api {patch} /statuses/:id Patch Existing Status - * @apiVersion 1.0.0 - * @apiName PatchStatus - * @apiGroup Status - * @apiDescription Patch existing status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name PatchStatus + * @memberof StatusHttpRouter + * @description Patch existing status */ router.patch( PATH_SINGLE, @@ -565,21 +509,9 @@ router.patch( ); /** - * @api {put} /statuses/:id Put Existing Status - * @apiVersion 1.0.0 - * @apiName PutStatus - * @apiGroup Status - * @apiDescription Put existing status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name PutStatus + * @memberof StatusHttpRouter + * @description Put existing status */ router.put( PATH_SINGLE, @@ -589,21 +521,9 @@ router.put( ); /** - * @api {delete} /statuses/:id Delete Existing Status - * @apiVersion 1.0.0 - * @apiName DeleteStatus - * @apiGroup Status - * @apiDescription Delete existing status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name DeleteStatus + * @memberof StatusHttpRouter + * @description Delete existing status */ router.delete( PATH_SINGLE, @@ -614,21 +534,9 @@ router.delete( ); /** - * @api {get} /jurisdictions/:jurisdiction/statuses List Jurisdiction Statuses - * @apiVersion 1.0.0 - * @apiName GetJurisdictionStatuses - * @apiGroup Status - * @apiDescription Returns a list of statuses of specified jurisdiction - * @apiUse RequestHeaders - * @apiUse Statuses - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusesSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name GetJurisdictionStatuses + * @memberof StatusHttpRouter + * @description Returns a list of statuses of specified jurisdiction */ router.get( PATH_JURISDICTION, @@ -650,16 +558,21 @@ router.get( * @license MIT * @example * - * const { app } = require('@codetanzania/majifix-status'); - * - * ... - * - * app.start(); + * const { Status, start } = require('@codetanzania/majifix-status'); + * start(error => { ... }); * */ -/* declarations */ -/* extract information from package.json */ +/** + * @name info + * @description package information + * @type {object} + * + * @author lally elias + * @author rijkerd + * @since 1.0.0 + * @version 0.1.0 + */ const info = pkg( `${__dirname}/package.json`, 'name', @@ -673,7 +586,16 @@ const info = pkg( 'contributors' ); -/* extract api version from router version */ -const apiVersion = router.version; +/** + * @name apiVersion + * @description http router api version + * @type {string} + * + * @author lally elias + * @author rijkerd + * @since 0.1.0 + * @version 0.1.0 + */ +const apiVersion = apiVersion$1(); -export { Status, apiVersion, info, router }; +export { Status, apiVersion, info, router as statusRouter }; diff --git a/lib/index.js b/lib/index.js index 6fd6e09a..916ebc69 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,6 @@ const common = require('@lykmapipo/common'); +const env = require('@lykmapipo/env'); +const expressRestActions = require('@lykmapipo/express-rest-actions'); const _ = require('lodash'); const mongooseCommon = require('@lykmapipo/mongoose-common'); const mongooseLocaleSchema = require('mongoose-locale-schema'); @@ -6,8 +8,18 @@ const actions = require('mongoose-rest-actions'); const exportable = require('@lykmapipo/mongoose-exportable'); const majifixJurisdiction = require('@codetanzania/majifix-jurisdiction'); const majifixCommon = require('@codetanzania/majifix-common'); -const env = require('@lykmapipo/env'); -const expressRestActions = require('@lykmapipo/express-rest-actions'); + +/* constants */ +const OPTION_SELECT = { name: 1, color: 1 }; +const OPTION_AUTOPOPULATE = { + select: OPTION_SELECT, + maxDepth: majifixCommon.POPULATION_MAX_DEPTH, +}; +const SCHEMA_OPTIONS = { collection: majifixCommon.COLLECTION_NAME_STATUS }; +const INDEX_UNIQUE = { + jurisdiction: 1, + ...mongooseLocaleSchema.localizedIndexesFor('name'), +}; /** * @module Status @@ -26,26 +38,6 @@ const expressRestActions = require('@lykmapipo/express-rest-actions'); * @version 1.0.0 * @public */ - -/* constants */ -const OPTION_SELECT = { name: 1, color: 1 }; -const OPTION_AUTOPOPULATE = { - select: OPTION_SELECT, - maxDepth: majifixCommon.POPULATION_MAX_DEPTH, -}; -const SCHEMA_OPTIONS = { collection: majifixCommon.COLLECTION_NAME_STATUS }; -const INDEX_UNIQUE = { - jurisdiction: 1, - ...mongooseLocaleSchema.localizedIndexesFor('name'), -}; - -/** - * @name StatusSchema - * @type {Schema} - * @since 0.1.0 - * @version 1.0.0 - * @private - */ const StatusSchema = mongooseCommon.createSchema( { /** @@ -223,7 +215,8 @@ StatusSchema.index(INDEX_UNIQUE, { unique: true }); /** * @name validate * @description status schema pre validation hook - * @param {function} done callback to invoke on success or error + * @param {Function} done callback to invoke on success or error + * @returns {object|Error} valid instance or error * @since 0.1.0 * @version 1.0.0 * @private @@ -241,27 +234,31 @@ StatusSchema.pre('validate', function preValidate(next) { /** * @name preValidate * @description status schema pre validation hook logic - * @param {function} done callback to invoke on success or error + * @param {Function} done callback to invoke on success or error + * @returns {object|Error} valid instance or error * @since 0.1.0 * @version 1.0.0 * @instance */ StatusSchema.methods.preValidate = function preValidate(done) { + // ensure name for all locales + this.name = mongooseLocaleSchema.localizedValuesFor(this.name); + // set default color if not set if (_.isEmpty(this.color)) { this.color = common.randomColor(); } // continue - return done(); + return done(null, this); }; /** * @name beforeDelete * @function beforeDelete * @description pre delete status logics - * @param {function} done callback to invoke on success or error - * + * @param {Function} done callback to invoke on success or error + * @returns {object|Error} valid instance or error * @since 0.1.0 * @version 1.0.0 * @instance @@ -297,8 +294,8 @@ StatusSchema.statics.OPTION_AUTOPOPULATE = OPTION_AUTOPOPULATE; * @name findDefault * @function findDefault * @description find default status - * @param {function} done a callback to invoke on success or failure - * @return {Status} default status + * @param {Function} done a callback to invoke on success or failure + * @returns {Status} default status * @since 0.1.0 * @version 1.0.0 * @static @@ -315,8 +312,8 @@ StatusSchema.statics.findDefault = done => { * @name prepareSeedCriteria * @function prepareSeedCriteria * @description define seed data criteria - * @param {Object} seed status to be seeded - * @returns {Object} packed criteria for seeding + * @param {object} seed status to be seeded + * @returns {object} packed criteria for seeding * * @author lally elias * @since 1.5.0 @@ -340,9 +337,9 @@ StatusSchema.statics.prepareSeedCriteria = seed => { * @name getOneOrDefault * @function getOneOrDefault * @description Find existing status or default based on given criteria - * @param {Object} criteria valid query criteria + * @param {object} criteria valid query criteria * @param {Function} done callback to invoke on success or error - * @returns {Object|Error} found status or error + * @returns {object|Error} found status or error * * @author lally elias * @since 1.5.0 @@ -386,10 +383,19 @@ const Status = mongooseCommon.model( StatusSchema ); +/* constants */ +const API_VERSION = env.getString('API_VERSION', '1.0.0'); +const PATH_SINGLE = '/statuses/:id'; +const PATH_LIST = '/statuses'; +const PATH_EXPORT = '/statuses/export'; +const PATH_SCHEMA = '/statuses/schema/'; +const PATH_JURISDICTION = '/jurisdictions/:jurisdiction/statuses'; + /** - * @apiDefine Status Status + * @name StatusHttpRouter + * @namespace StatusHttpRouter * - * @apiDescription A representation of an entity which provides a way + * @description A representation of an entity which provides a way * to set flags on service requests(issues) in order to track * their progress. * @@ -400,36 +406,14 @@ const Status = mongooseCommon.model( * @version 1.0.0 * @public */ - -/* constants */ -const API_VERSION = env.getString('API_VERSION', '1.0.0'); -const PATH_SINGLE = '/statuses/:id'; -const PATH_LIST = '/statuses'; -const PATH_EXPORT = '/statuses/export'; -const PATH_SCHEMA = '/statuses/schema/'; -const PATH_JURISDICTION = '/jurisdictions/:jurisdiction/statuses'; - -/* declarations */ const router = new expressRestActions.Router({ version: API_VERSION, }); /** - * @api {get} /statuses List Statuses - * @apiVersion 1.0.0 - * @apiName GetStatuses - * @apiGroup Status - * @apiDescription Returns a list of statuses - * @apiUse RequestHeaders - * @apiUse Statuses - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusesSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name GetStatuses + * @memberof StatusHttpRouter + * @description Returns a list of statuses */ router.get( PATH_LIST, @@ -439,12 +423,9 @@ router.get( ); /** - * @api {get} /statuses/schema Get Status Schema - * @apiVersion 1.0.0 - * @apiName GetStatusSchema - * @apiGroup Status - * @apiDescription Returns status json schema definition - * @apiUse RequestHeaders + * @name GetStatusSchema + * @memberof StatusHttpRouter + * @description Returns status json schema definition */ router.get( PATH_SCHEMA, @@ -457,12 +438,9 @@ router.get( ); /** - * @api {get} /statuses/export Export Statuses - * @apiVersion 1.0.0 - * @apiName ExportStatuses - * @apiGroup Status - * @apiDescription Export statuses as csv - * @apiUse RequestHeaders + * @name ExportStatuses + * @memberof StatusHttpRouter + * @description Export statuses as csv */ router.get( PATH_EXPORT, @@ -476,21 +454,9 @@ router.get( ); /** - * @api {post} /statuses Create New Status - * @apiVersion 1.0.0 - * @apiName PostStatus - * @apiGroup Status - * @apiDescription Create new status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name PostStatus + * @memberof StatusHttpRouter + * @description Create new status */ router.post( PATH_LIST, @@ -500,21 +466,9 @@ router.post( ); /** - * @api {get} /statuses/:id Get Existing Status - * @apiVersion 1.0.0 - * @apiName GetStatus - * @apiGroup Status - * @apiDescription Get existing status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name GetStatus + * @memberof StatusHttpRouter + * @description Get existing status */ router.get( PATH_SINGLE, @@ -524,21 +478,9 @@ router.get( ); /** - * @api {patch} /statuses/:id Patch Existing Status - * @apiVersion 1.0.0 - * @apiName PatchStatus - * @apiGroup Status - * @apiDescription Patch existing status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name PatchStatus + * @memberof StatusHttpRouter + * @description Patch existing status */ router.patch( PATH_SINGLE, @@ -548,21 +490,9 @@ router.patch( ); /** - * @api {put} /statuses/:id Put Existing Status - * @apiVersion 1.0.0 - * @apiName PutStatus - * @apiGroup Status - * @apiDescription Put existing status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name PutStatus + * @memberof StatusHttpRouter + * @description Put existing status */ router.put( PATH_SINGLE, @@ -572,21 +502,9 @@ router.put( ); /** - * @api {delete} /statuses/:id Delete Existing Status - * @apiVersion 1.0.0 - * @apiName DeleteStatus - * @apiGroup Status - * @apiDescription Delete existing status - * @apiUse RequestHeaders - * @apiUse Status - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name DeleteStatus + * @memberof StatusHttpRouter + * @description Delete existing status */ router.delete( PATH_SINGLE, @@ -597,21 +515,9 @@ router.delete( ); /** - * @api {get} /jurisdictions/:jurisdiction/statuses List Jurisdiction Statuses - * @apiVersion 1.0.0 - * @apiName GetJurisdictionStatuses - * @apiGroup Status - * @apiDescription Returns a list of statuses of specified jurisdiction - * @apiUse RequestHeaders - * @apiUse Statuses - * - * - * @apiUse RequestHeadersExample - * @apiUse StatusesSuccessResponse - * @apiUse JWTError - * @apiUse JWTErrorExample - * @apiUse AuthorizationHeaderError - * @apiUse AuthorizationHeaderErrorExample + * @name GetJurisdictionStatuses + * @memberof StatusHttpRouter + * @description Returns a list of statuses of specified jurisdiction */ router.get( PATH_JURISDICTION, @@ -633,16 +539,21 @@ router.get( * @license MIT * @example * - * const { app } = require('@codetanzania/majifix-status'); - * - * ... - * - * app.start(); + * const { Status, start } = require('@codetanzania/majifix-status'); + * start(error => { ... }); * */ -/* declarations */ -/* extract information from package.json */ +/** + * @name info + * @description package information + * @type {object} + * + * @author lally elias + * @author rijkerd + * @since 1.0.0 + * @version 0.1.0 + */ const info = common.pkg( `${__dirname}/package.json`, 'name', @@ -656,10 +567,25 @@ const info = common.pkg( 'contributors' ); -/* extract api version from router version */ -const apiVersion = router.version; +/** + * @name apiVersion + * @description http router api version + * @type {string} + * + * @author lally elias + * @author rijkerd + * @since 0.1.0 + * @version 0.1.0 + */ +const apiVersion = env.apiVersion(); +Object.defineProperty(exports, 'start', { + enumerable: true, + get() { + return expressRestActions.start; + }, +}); exports.Status = Status; exports.apiVersion = apiVersion; exports.info = info; -exports.router = router; +exports.statusRouter = router; diff --git a/package-lock.json b/package-lock.json index ea8522d6..68d740de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@codetanzania/majifix-status", - "version": "1.5.1", + "version": "1.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index dbd4bded..f65df726 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codetanzania/majifix-status", - "version": "1.5.1", + "version": "1.6.0", "description": "A representation of an entity which provides a way to set flags on service requests(issues) in order to track their progress.", "main": "lib/index.js", "module": "es/index.js", @@ -31,8 +31,12 @@ "codetanzania", "majifix", "majifix-module", + "open311", "status", - "open311" + "pipeline", + "flag", + "state", + "label" ], "contributors": [ {