shortcuts imported; note import completed
This commit is contained in:
+29
-23
@@ -28,7 +28,7 @@ var Shortcut = sequelize.define('Shortcut', {
|
|||||||
params: Sequelize.STRING
|
params: Sequelize.STRING
|
||||||
});
|
});
|
||||||
|
|
||||||
//Note.hasMany(Shortcut);
|
Note.hasMany(Shortcut);
|
||||||
Shortcut.belongsTo(Note);
|
Shortcut.belongsTo(Note);
|
||||||
|
|
||||||
sequelize.sync().then(function () {
|
sequelize.sync().then(function () {
|
||||||
@@ -56,30 +56,36 @@ sequelize.sync().then(function () {
|
|||||||
edited: !isNaN(edited[id]) && edited[id] && new Date(edited[id] * 1000) || null,
|
edited: !isNaN(edited[id]) && edited[id] && new Date(edited[id] * 1000) || null,
|
||||||
views: views[id],
|
views: views[id],
|
||||||
}).then(note => {
|
}).then(note => {
|
||||||
|
|
||||||
links.forEach(shortcutId => {
|
links.forEach(shortcutId => {
|
||||||
client.hget("short-url", shortcutId, function (err, result){
|
client.hget("short-url", shortcutId, function (err, result) {
|
||||||
|
|
||||||
Shortcut.create({
|
result = result.replace(/:([\w_-]+)\s/g, '"$1":');
|
||||||
id: shortcutId,
|
|
||||||
params: result
|
var obj = {};
|
||||||
}).then(shortcut => {
|
try {
|
||||||
|
obj = JSON.parse(result);
|
||||||
debugger
|
delete obj.title;
|
||||||
shortcut.setNote(note);
|
delete obj.day;
|
||||||
|
delete obj.year;
|
||||||
})
|
delete obj.month;
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
return console.log("PARSE ERROR FOR", result)
|
||||||
|
}
|
||||||
|
|
||||||
|
Shortcut.create({
|
||||||
|
id: shortcutId,
|
||||||
|
params: Object.keys(obj).length == 0 ? null : JSON.stringify(obj)
|
||||||
|
}).then(shortcut => {
|
||||||
|
|
||||||
|
shortcut.setNote(note);
|
||||||
|
note.addShortcut(shortcut);
|
||||||
|
|
||||||
|
})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user