loopback- how to access from one model to another and send email?

只谈情不闲聊 提交于 2019-12-25 00:06:31

问题


I have the career form where i have all the details with the file attachment. now i can able to store the file. I am able to send email, but both sending email with attachment is not happening because i have two model one is for attachment and the other is Persisted model. In the attachment.js i am able to get the file file name but i could not send email with attachment. Here is code.

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();
         }); 
    };

Here if i apply both the code I am getting error. How to fetch the file name from one model to another and send email?

来源:https://stackoverflow.com/questions/55534760/loopback-how-to-access-from-one-model-to-another-and-send-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!