风帆制造问题

Sails create probleme

我只想通过 sailsjs 在我的数据库中创建一个新输入,但没有错误,也没有主菜出来。

这是我的模型

module.exports = {

  attributes: {

    id: { type: 'integer'},
    entreprise_id: { type: 'integer'},
    employees_id: { type: 'string'},
    name : { type: 'string'},
    description_short: { type: 'string'},
    description_long: { type: 'string'},
    price: { type: 'string'},
    duration: { type: 'string'},
    at_home: {type: 'integer'},
    break_time: {type: 'integer'},
    many_customer: {type: 'integer'},
    last_minute_max: {type: 'integer'},
    precision_label: {type: 'string'},
    createdAt : { type: 'date' }, 
    updatedAt : { type: 'date' }

  }

}

和创建主菜的脚本

Service.create({

  entreprise_id: entrepriseId,
  employees_id:infos['employees_id'],
  name :infos['name'],
  description_short:infos['description_short'],
  description_long:infos['description_long'],
  price:infos['price'],
  duration:infos['duration'],
  at_home:infos['at_home'],
  break_time:infos['break_time'],
  many_customer:infos['many_customer'],
  last_minute_max:infos['last_minute_max'],
  precision_label:infos['precision_label']  

}).exec( function(err, newService){

  if(err){ com.push({error:err})}
  else{
    com.push(newService)
  }

});

我已经验证 info 数组中的所有信息都是空的或包含值但没有错误。 最重要的是我的 com 数组没有错误,也没有 newservice 作为 wall.

我终于通过在我的回调函数中添加 "if(err){ return res.serverError(err); }" 得到了错误。

我必须防止需要数字等的空值

for(n in infos){

  if(n=='entreprise_id'){ infos[n] = entrepriseId; }
  if(n=="price"||n=="duration"||n=="at_home"||n=="break_time"||n=="many_customer"||n=="last_minute_max"){
    if(!infos[n]){
      infos[n]=0;
    }
  }

}

Service.create({
  entreprise_id: infos['entreprise_id'],
  employees_id:infos['employees_id'],
  name :infos['name'],
  description_short:infos['description_short'],
  description_long:infos['description_long'],
  price:infos['price'],
  duration:infos['duration'],
  at_home:infos['at_home'],
  break_time:infos['break_time'],
  many_customer:parseInt(infos['many_customer']),
  last_minute_max:parseInt(infos['last_minute_max']),
  precision_label:infos['precision_label']         
}).exec( function(err, newService){

  if(err){  return res.serverError(err); }
  com.push({news:newService})

});