问题
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