Skip to content

Commit

Permalink
feat: initialize campaign model
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Jun 15, 2019
1 parent 1c3a69c commit 2ff2031
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 4 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -33,6 +34,9 @@ function postman() {

}

/* export postman campaign model */
postman.Campaign = Campaign;


/* export postman message model */
postman.Message = Message;
Expand Down Expand Up @@ -79,4 +83,4 @@ postman.listen = listen;


/* export postman */
exports = module.exports = postman;
module.exports = exports = postman;
83 changes: 83 additions & 0 deletions lib/campaign.model.js
Original file line number Diff line number Diff line change
@@ -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 <lallyelias87@gmail.com>
* @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 <lallyelias87@gmail.com>
* @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);
6 changes: 3 additions & 3 deletions lib/message.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -1173,7 +1173,7 @@ MessageSchema.plugin(runInBackground, { types: TYPES });


/**
* export message schema
* export message model
* @type {Model}
* @private
*/
Expand Down
11 changes: 11 additions & 0 deletions test/unit/campaign.schema.spec.js
Original file line number Diff line number Diff line change
@@ -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;
});

0 comments on commit 2ff2031

Please sign in to comment.