aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models/__helpers.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-26 13:43:22 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-26 13:43:22 -0400
commitb7f254cd426138880318d2ba6a06e8e86ae407bf (patch)
treead624b5dacba2dc1ee9e445e00ffc1a7926fcd85 /src/lib/models/__helpers.ts
parent85d24271a00d9363fe022ebb8e132bd506c712ba (diff)
downloadtanzanite-b7f254cd426138880318d2ba6a06e8e86ae407bf.tar.gz
tanzanite-b7f254cd426138880318d2ba6a06e8e86ae407bf.tar.bz2
tanzanite-b7f254cd426138880318d2ba6a06e8e86ae407bf.zip
finished feature command and did some refactoring
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: '[]'
+ };
+}