环回-如何从一种模型访问另一种模型并发送电子邮件?

时间:2019-04-05 11:51:36

标签: javascript node.js loopbackjs email-attachments strongloop

我有一份职业表格,其中包含所有带有文件附件的详细信息。现在我可以存储文件了。我能够发送电子邮件,但是都不会发送带有附件的电子邮件,因为我有两个模型,一个是附件模型,另一个是持久模型。在 attachment.js 中,我可以获取文件名,但无法发送带有附件的电子邮件。这是代码。

career.js

 'use strict';
    const app = require('../../server/server');
    module.exports = function(Career) {

        Career.afterRemote('create', function(context, remoteMethodOutput, next) { 
            next(); 
          console.log(context.result) //here i dont have the file name
        Career.app.models.Email.send({ 
                to: 'lakshmipriya.l@gmail.com', 
                from: 'lakshmi@gmail.com', 
                subject: 'my Career Form', 
                html: 'my message'
                }, function(err, mail) { 
                    // console.log(context.result.email)
                console.log('email sent!'); 
                cb(err); 
            }); 
        }); 
    };

career.json

{
  "name": "career",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "id": {
      "type": "number"
    },
    "firstname": {
      "type": "string",
      "required": true
    },

    "email": {
      "type": "string",
      "required": true
    },

    "message": {
      "type": "string",
      "required": true
    },
    "resume": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

attachment.js

 'use strict';

    module.exports = function(Attachment) {
        Attachment.afterRemote('upload',function(ctx, modelInstance, next){ 
            console.log('create file',modelInstance.result.files.file);
             next();
         }); 
    };

如果我同时应用这两个代码,则会出错。 如何从一个模型到另一个模型获取文件名并发送电子邮件?

0 个答案:

没有答案