aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models/__helpers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/models/__helpers.ts')
-rw-r--r--src/lib/models/__helpers.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/models/__helpers.ts b/src/lib/models/__helpers.ts
new file mode 100644
index 0000000..f558ecb
--- /dev/null
+++ b/src/lib/models/__helpers.ts
@@ -0,0 +1,23 @@
+import { DataTypes, Model } from 'sequelize';
+
+export const NEVER_USED = 'This should never be executed';
+function jsonParseGet(key: string, that: Model): any {
+ return JSON.parse(that.getDataValue(key));
+}
+function jsonParseSet(key: string, that: Model, value: any): any {
+ return that.setDataValue(key, JSON.stringify(value));
+}
+
+export function jsonArrayInit(key: string): any {
+ return {
+ type: DataTypes.TEXT,
+ get: function () {
+ return jsonParseGet(key, this);
+ },
+ set: function (val: string[]) {
+ return jsonParseSet(key, this, val);
+ },
+ allowNull: false,
+ defaultValue: '[]'
+ };
+}