Loopback get data from one module to anothee

蓝咒 提交于 2019-12-11 17:18:52

问题


I am using loopback3 for file storage attachment.js and i have the persistedmodel career.js for storing the data. Now i want to fetch the file name in the career.js. how to do this.

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) 
    Career.app.models.Email.send({ 
            to: 'john@gmail.com', 
            from: 'noreply@gmail.com', 
            subject: 'Career Form', 
            html: '<em>Hi,</em>'

            },
           function(err, mail) { 
                // console.log(context.result.email)
            console.log('email sent!'); 
            console.log(err); 
        }); 
    });

attachment.js

'use strict';

module.exports = function(Attachment) {

};

回答1:


call your other model over here. as per my understanding, you try to insert file name. so I modified your code.

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

Career.afterRemote('create', function(context, remoteMethodOutput, next) { 
var companyprofile=app.models."yourmodel" // model name from where you want to insert file name
 companyprofile.create({cust_cmp_profile:context.args.data.cust_cmp_profile},              
  function(err) {
    if (err){
       next(err)
    } 
  else{
      next()
  }
});   

 // console.log(context.result) 
Career.app.models.Email.send({ 
        to: 'john@gmail.com', 
        from: 'noreply@gmail.com', 
        subject: 'Career Form', 
        html: '<em>Hi,</em>'

        },
       function(err, mail) { 
            // console.log(context.result.email)
        console.log('email sent!'); 
        console.log(err); 
    }); 
});

hope this help



来源:https://stackoverflow.com/questions/55568366/loopback-get-data-from-one-module-to-anothee

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