Question
define a sequelize like below: var Program=sequelize.define('Program',{ programCode:{ type:Sequelize.STRING, primaryKey:true }, programName:Sequelize.STRING, }, module.exports.addProgram=function(programData){ return new Promise((resolve,reject)=>{ for ( var i in programData){ if(programData[i]==)
define a sequelize like below:
var Program=sequelize.define('Program',{
programCode:{
type:Sequelize.STRING,
primaryKey:true
},
programName:Sequelize.STRING,
},
module.exports.addProgram=function(programData){
return new Promise((resolve,reject)=>{
for ( var i in programData){
if(programData[i]=="")
programData[i]=null;
};
Program.create({
programCode:programData.programCode,
programName:programData.programName,
}) .then((data) => {
console.log("data:", data)
resolve(data);}
)
.catch((err) => {
reject ("Unable to Add the program");
return;
});
});
}
I know the programCode primaryKey should not be null, but if I input null in programCode, I will get some error. How could I handle this error?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started