diff --git a/index.js b/index.js index c8b2577..2c2cbc3 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ const { listen } = require('@lykmapipo/kue-common'); const { worker } = require('mongoose-kue'); const libPath = path.join(__dirname, 'lib'); const Message = require(path.join(libPath, 'message.model')); +const Campaign = require(path.join(libPath, 'campaign.model')); /* constants */ @@ -33,6 +34,9 @@ function postman() { } +/* export postman campaign model */ +postman.Campaign = Campaign; + /* export postman message model */ postman.Message = Message; @@ -79,4 +83,4 @@ postman.listen = listen; /* export postman */ -exports = module.exports = postman; \ No newline at end of file +module.exports = exports = postman; \ No newline at end of file diff --git a/lib/campaign.model.js b/lib/campaign.model.js new file mode 100644 index 0000000..aee8543 --- /dev/null +++ b/lib/campaign.model.js @@ -0,0 +1,83 @@ +'use strict'; + + +/** + * @module Campaign + * @name Campaign + * @description A representation of communication intended by the source(sender) + * for consumption by some recipient(receiver) or group of recipients(receivers). + * + * A campaign may be delivered by various means(transports or channels) + * including email, sms, push notification etc. + * + * @see {@link https://en.wikipedia.org/wiki/Campaign} + * @see {@link https://en.wikipedia.org/wiki/Advertising_campaign} + * @author lally elias + * @license MIT + * @version 0.1.0 + * @since 0.9.0 + * @public + */ + + +const { getString } = require('@lykmapipo/env'); +const { model, Schema, SCHEMA_OPTIONS } = require('@lykmapipo/mongoose-common'); +const actions = require('mongoose-rest-actions'); + + +/* constants */ +const MODEL_NAME = getString('CAMPAIGN_MODEL_NAME', 'Campaign'); + + +const FORM_ALERT = 'Alert'; +const FORM_INFORMATION = 'Information'; +const FORM_WARNING = 'Warning'; +const FORM_ANNOUNCEMENT = 'Announcement'; +const FORM_REMINDER = 'Reminder'; +const FORMS = [ + FORM_ALERT, FORM_INFORMATION, FORM_WARNING, + FORM_ANNOUNCEMENT, FORM_REMINDER +]; + + +/** + * @name CampaignSchema + * @type {Schema} + * @author lally elias + * @since 0.1.0 + * @version 0.1.0 + * @private + */ +const CampaignSchema = new Schema({ + +}, SCHEMA_OPTIONS); + + +/* + *------------------------------------------------------------------------------ + * Statics + *------------------------------------------------------------------------------ + */ + + +CampaignSchema.statics.MODEL_NAME = MODEL_NAME; + + +CampaignSchema.statics.FORM_ALERT = FORM_ALERT; +CampaignSchema.statics.FORM_INFORMATION = FORM_INFORMATION; +CampaignSchema.statics.FORM_WARNING = FORM_WARNING; +CampaignSchema.statics.FORM_ANNOUNCEMENT = FORM_ANNOUNCEMENT; +CampaignSchema.statics.FORM_REMINDER = FORM_REMINDER; +CampaignSchema.statics.FORMS = FORMS; + + +/* + *------------------------------------------------------------------------------ + * Plugins + *------------------------------------------------------------------------------ + */ +CampaignSchema.plugin(actions); + + +/* export campaign model */ +module.exports = exports = model(MODEL_NAME, CampaignSchema); \ No newline at end of file diff --git a/lib/message.model.js b/lib/message.model.js index 1832f8b..3aee6cf 100644 --- a/lib/message.model.js +++ b/lib/message.model.js @@ -90,11 +90,11 @@ const SEND_MODES = [SEND_MODE_PULL, SEND_MODE_PUSH]; /* model name for the message */ -const MODEL_NAME = getString('MODEL_NAME', 'Message'); +const MODEL_NAME = getString('MESSAGE_MODEL_NAME', 'Message'); /* collection name for the message */ -const COLLECTION_NAME = getString('COLLECTION_NAME', 'messages'); +const COLLECTION_NAME = getString('MESSAGE_COLLECTION_NAME', 'messages'); /* schema options */ @@ -1173,7 +1173,7 @@ MessageSchema.plugin(runInBackground, { types: TYPES }); /** - * export message schema + * export message model * @type {Model} * @private */ diff --git a/test/unit/campaign.schema.spec.js b/test/unit/campaign.schema.spec.js new file mode 100644 index 0000000..22a4c0b --- /dev/null +++ b/test/unit/campaign.schema.spec.js @@ -0,0 +1,11 @@ +'use strict'; + + +/* dependencies */ +const path = require('path'); +const { expect } = require('@lykmapipo/mongoose-test-helpers'); +const { Campaign } = require(path.join(__dirname, '..', '..')); + +describe('Campaign Schema', () => { + expect(Campaign).to.exist; +}); \ No newline at end of file