Built motion from commit ee17993.|1.0.6
[motion.git] / server / models / cm_contact.js
index ccf6b22..c5587a2 100644 (file)
@@ -12,18 +12,38 @@ module.exports = function(sequelize, DataTypes) {
       }
     },
     lastName: DataTypes.STRING,
-    tags: DataTypes.STRING,
+    tags: {
+      type: DataTypes.STRING,
+      get: function() {
+        var tags;
+        if (this.getDataValue('tags')) {
+          tags = this.getDataValue('tags').split(';');
+          if (tags.length > 1) {
+            tags.pop();
+          } else {
+            tags = []; //if the length is 1 the value is still in the format of the old tags, with comma separator. So I return an empty array since the old format is obsolete and invalid
+          }
+        } else {
+          tags = [];
+        }
+        return tags;
+      },
+      set: function(val) {
+        this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
+      }
+    },
     street: DataTypes.STRING,
     postalCode: DataTypes.STRING,
     city: DataTypes.STRING,
     country: DataTypes.STRING,
     dateOfBirth: DataTypes.STRING,
-    description: DataTypes.STRING,
+    description: DataTypes.TEXT,
     phone: DataTypes.STRING,
     mobile: DataTypes.STRING,
     fax: DataTypes.STRING,
     email: DataTypes.STRING,
-    url: DataTypes.STRING
+    url: DataTypes.STRING,
+    planningtime: DataTypes.DATE
   }, {
     tableName: 'cm_contacts',
     associate: function(models) {
@@ -45,11 +65,9 @@ module.exports = function(sequelize, DataTypes) {
         };
         if (query.CompanyId) {
           scope.where.CompanyId = query.CompanyId;
-          delete query.CompanyId;
         }
         if (query.ListId) {
           scope.where.ListId = query.ListId;
-          delete query.ListId;
         }
         return scope;
       });