identity-code-api-controllers

1.0.0 • Public • Published

identity-code-api-controllers

Supplies the controller functions for the Identity Code APIs.

Setup

To initialize your controllers, you must first supply the module with an object of configuration options:

The options are:

  • bucketName - the name of the s3 bucket where the resources and resource logs are stored.
  • storageFile - the name of the file where the resources are stored.
  • logFile - the name of the file where the logs are stored.
  • resourceNameSingular - the singular form of the resource name.
  • resourceNamePlural - the plural form of the resource name.
  • sortNameSingular - (Optional) the singular form of the sort group name (ex: state codes are grouped by country codes).
  • sortNamePlural - (Optional) The plural form of the sort group name.
  • paginate - (Optional) An object that sets the default properties for pagination. Can be a boolean value (true) instead of an object to use all the default values. Any property not specified is set to the default. Below are the properties that can be specified and their defaults:
    • default_start - Defaults to 1.
    • default_size - Defaults to 50.
    • max_page_size - Defaults to 100.

All this will be passed in to the init function and should be placed in the code where the server is initialized.

Setup Example:

Note: sortNameSingular and sortNamePlural are not used in this example.

const controllers = require('identity-code-api-controllers');

controllers.init({
    bucketName: 'identity-level-of-education-dev-bucket-s3',
    storageFile: 'identity-level-of-education-dev-bucket-s3.json',
    logFile: 'logs.json',
    resourceNameSingular: 'level_of_education',
    resourceNamePlural: 'levels_of_education'
});

Verify Controller Initialization

If, for some reason, you want to verify that the controllers have been initialized, call the configured function:

Example:
controllers.configured() // returns true if configured and false if not.

Verify Pagination Initialization

If you want to check that the the server has configured pagination options:

controllers.paginated() // returns true if configured and false if not.

Access Configuration Options

To access these configuration options later in your code, call the controller retrieve functions.

Example:
const config = controllers.retrieve;

// General controller settings
config.bucketName();
config.storageFile();
config.logFile();
config.resourceNameSingular();
config.resourceNamePlural();

// Sort name setting for identity code APIs with two parameters
config.sortNameSingular();
config.sortNamePlural();

// Pagination options (only used in large data identity code APIs)
config.pageDefaultStart();
config.pageDefaultSize();
config.pageMaxSize();

// General link properties
config.resourceNameInfo(); // `${resourceNamePlural}__info`
config.resourceNameCreate(); // `${resourceNamePlural}__create`
config.resourceNameModify(); // `${resourceNamePlural}__modify`
config.resourceNameRemove(); // `${resourceNamePlural}__remove`
config.resourceLogsInfo(); // `${resourceNameSingular}_logs__info`

// Pagination link properties
config.resourcePageFirst(); // `${resourceNamePlural}__first`
config.resourcePageLast(); // `${resourceNamePlural}__last`
config.resourcePagePrev(); // `${resourceNamePlural}__prev`
config.resourcePageNext(); // `${resourceNamePlural}__next`

Define The Controllers

To define the controllers, call the controller functions.

  • getAllResources
  • createResource
  • getResource
  • modifyResource
  • deleteResource
  • getResourceLogs
Example:
exports.getLevelsOfEducation = controllers.getAllResources;
exports.createLevelOfEducation = controllers.createResource;
exports.getLevelOfEducation = controllers.getResource;
exports.modifyLevelOfEducation = controllers.modifyResource;
exports.removeLevelOfEducation = controllers.deleteResource;
exports.getLevelOfEducationLogs = controllers.getResourceLogs;

Readme

Keywords

none

Package Sidebar

Install

npm i identity-code-api-controllers

Weekly Downloads

9

Version

1.0.0

License

Apache-2.0

Unpacked Size

46.2 kB

Total Files

13

Last publish

Collaborators

  • grahamc32
  • lmr99
  • stuft2