From 551d109a201a7c94bd44cc4f33e75ce630dbd961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 10 Oct 2014 13:49:21 +0200 Subject: [PATCH] models: move Email LDL def into `email.json` --- common/models/email.js | 87 ++++++++++++++++++---------------------- common/models/email.json | 11 +++++ lib/builtin-models.js | 4 +- 3 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 common/models/email.json diff --git a/common/models/email.js b/common/models/email.js index 0d0e7993..7c5c44f6 100644 --- a/common/models/email.js +++ b/common/models/email.js @@ -1,57 +1,50 @@ -/*! - * Module Dependencies. - */ - -var Model = require('../../lib/loopback').Model - , loopback = require('../../lib/loopback'); - -var properties = { - to: {type: String, required: true}, - from: {type: String, required: true}, - subject: {type: String, required: true}, - text: {type: String}, - html: {type: String} -}; - /** * @property {String} to Email addressee. Required. * @property {String} from Email sender address. Required. * @property {String} subject Email subject string. Required. - * @property {String} text Text body of email. + * @property {String} text Text body of email. * @property {String} html HTML body of email. - * - * @class + * + * @class Email * @inherits {Model} */ -var Email = module.exports = Model.extend('Email', properties); +module.exports = function(Email) { -/** - * Send an email with the given `options`. - * - * Example Options: - * - * ```js - * { - * from: "Fred Foo ", // sender address - * to: "bar@blurdybloop.com, baz@blurdybloop.com", // list of receivers - * subject: "Hello", // Subject line - * text: "Hello world", // plaintext body - * html: "Hello world" // html body - * } - * ``` - * - * See https://github.com/andris9/Nodemailer for other supported options. - * - * @options {Object} options See below - * @prop {String} from Senders's email address - * @prop {String} to List of one or more recipient email addresses (comma-delimited) - * @prop {String} subject Subject line - * @prop {String} text Body text - * @prop {String} html Body HTML (optional) - * @param {Function} callback Called after the e-mail is sent or the sending failed - */ + /** + * Send an email with the given `options`. + * + * Example Options: + * + * ```js + * { + * from: "Fred Foo ", // sender address + * to: "bar@blurdybloop.com, baz@blurdybloop.com", // list of receivers + * subject: "Hello", // Subject line + * text: "Hello world", // plaintext body + * html: "Hello world" // html body + * } + * ``` + * + * See https://github.com/andris9/Nodemailer for other supported options. + * + * @options {Object} options See below + * @prop {String} from Senders's email address + * @prop {String} to List of one or more recipient email addresses (comma-delimited) + * @prop {String} subject Subject line + * @prop {String} text Body text + * @prop {String} html Body HTML (optional) + * @param {Function} callback Called after the e-mail is sent or the sending failed + */ -Email.prototype.send = function() { - throw new Error('You must connect the Email Model to a Mail connector'); -} + Email.send = function() { + throw new Error('You must connect the Email Model to a Mail connector'); + }; + + /** + * A shortcut for Email.send(this). + */ + Email.prototype.send = function() { + throw new Error('You must connect the Email Model to a Mail connector'); + }; +}; diff --git a/common/models/email.json b/common/models/email.json new file mode 100644 index 00000000..6def3834 --- /dev/null +++ b/common/models/email.json @@ -0,0 +1,11 @@ +{ + "name": "Email", + "base": "Model", + "properties": { + "to": {"type": "String", "required": true}, + "from": {"type": "String", "required": true}, + "subject": {"type": "String", "required": true}, + "text": {"type": "String"}, + "html": {"type": "String"} + } +} diff --git a/lib/builtin-models.js b/lib/builtin-models.js index c57351ad..f95433b7 100644 --- a/lib/builtin-models.js +++ b/lib/builtin-models.js @@ -1,7 +1,9 @@ module.exports = function(loopback) { // NOTE(bajtos) we must use static require() due to browserify limitations - loopback.Email = require('../common/models/email'); + loopback.Email = createModel( + require('../common/models/email.json'), + require('../common/models/email.js')); loopback.Application = require('../common/models/application'); loopback.AccessToken = require('../common/models/access-token');