summaryrefslogtreecommitdiff
path: root/lib/models
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models')
-rw-r--r--lib/models/index.js6
-rw-r--r--lib/models/note.js9
-rw-r--r--lib/models/revision.js12
3 files changed, 27 insertions, 0 deletions
diff --git a/lib/models/index.js b/lib/models/index.js
index 6d0fd3c3..e83956e5 100644
--- a/lib/models/index.js
+++ b/lib/models/index.js
@@ -27,6 +27,12 @@ function stripNullByte(value) {
}
sequelize.stripNullByte = stripNullByte;
+function processData(data, _default, process) {
+ if (data === undefined) return data;
+ else return data === null ? _default : (process ? process(data) : data);
+}
+sequelize.processData = processData;
+
var db = {};
fs
diff --git a/lib/models/note.js b/lib/models/note.js
index 37d26ec0..5c63dc1a 100644
--- a/lib/models/note.js
+++ b/lib/models/note.js
@@ -53,18 +53,27 @@ module.exports = function (sequelize, DataTypes) {
},
title: {
type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('title'), "");
+ },
set: function (value) {
this.setDataValue('title', sequelize.stripNullByte(value));
}
},
content: {
type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('content'), "");
+ },
set: function (value) {
this.setDataValue('content', sequelize.stripNullByte(value));
}
},
authorship: {
type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('authorship'), [], JSON.parse);
+ },
set: function (value) {
this.setDataValue('authorship', JSON.stringify(value));
}
diff --git a/lib/models/revision.js b/lib/models/revision.js
index adc651f1..c7360fed 100644
--- a/lib/models/revision.js
+++ b/lib/models/revision.js
@@ -60,18 +60,27 @@ module.exports = function (sequelize, DataTypes) {
},
patch: {
type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('patch'), "");
+ },
set: function (value) {
this.setDataValue('patch', sequelize.stripNullByte(value));
}
},
lastContent: {
type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('lastContent'), "");
+ },
set: function (value) {
this.setDataValue('lastContent', sequelize.stripNullByte(value));
}
},
content: {
type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('content'), "");
+ },
set: function (value) {
this.setDataValue('content', sequelize.stripNullByte(value));
}
@@ -81,6 +90,9 @@ module.exports = function (sequelize, DataTypes) {
},
authorship: {
type: DataTypes.TEXT,
+ get: function () {
+ return sequelize.processData(this.getDataValue('authorship'), [], JSON.parse);
+ },
set: function (value) {
this.setDataValue('authorship', value ? JSON.stringify(value) : value);
}