Skip to content

Instantly share code, notes, and snippets.

@dancgray
Created November 6, 2019 16:20
Show Gist options
  • Save dancgray/ef659fcfbd938ab3f2f247a097a3d728 to your computer and use it in GitHub Desktop.
Save dancgray/ef659fcfbd938ab3f2f247a097a3d728 to your computer and use it in GitHub Desktop.
Assets AbstractApiModule test
const AbstractApiModule = require('adapt-authoring-api');
const AssetSchema = require('../schema/asset.schema.js');
/**
* Abstract module which handles course assets
* @extends {AbstractApiModule}
*/
class AssetApiModule extends AbstractApiModule {
/** @override */
static get def() {
return {
name: 'assets',
model: 'asset',
schemas: [ AssetSchema ],
routes: [
{
route: '/:_id?',
handlers: {
get: getFunction
}
}
]
};
}
getFunction(req, res, next) {
console.log('Assets getFunction called');
}
}
module.exports = AssetApiModule;
@taylortom
Copy link

taylortom commented Nov 6, 2019

Have just tested this out, and while there's nothing immediately wrong with the above, I think you're missing the module: true attribute from your package.json (see this doc page for an example).

The original reasoning behind this was to allow the inclusion of dependencies which don't export a module (e.g. the testing, lint and doc modules). It may be an idea to change this so the package config is no longer needed, and the module export is required, i.e.

// index.js
module.exports = { 
  module: ModuleClass, 
  utility: UtilityClass 
};

You'll also need to change where getFunction is declared, as the def is a static function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment