0
一个唯一的发票编号我需要帆为我的发票与当前格式的唯一ID:如何产生Sails.js
<auto-incremented-number>/<current-year>
,如:8/2016
,122/2099
,122/2100
的想法是按照文档
function getLatestId() {
//stuck here
return 42;
}
const current_year = new Date().getFullYear()
const calculated_id = getLatestId() +"/"+ current_year
Invoice.create({ data:'...', id: calculated_id }).exec(function (err, item){
if (err) { return res.serverError(err); }
sails.log('Invoice created:', item.id);
return res.ok();
});
的问题是,即使有工作getLatestId
函数的代码是丑陋而在例如它代码从一英里闻起来。
甚至尝试更新create函数的exec回调中的id看起来很奇怪,因为具有特定id的项目已经创建。
我不敢相信,风帆没有东西来解决类似的情况,但我无法找到文档中的任何东西。
从技术上说,身份证必须是连续的,但我得到你的方法 – Motocarota