Built motion from commit a486b36.|1.0.4
[motion.git] / server / models / cm_contact.js
index eaf3cd9..c5587a2 100644 (file)
@@ -12,17 +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,
+    planningtime: DataTypes.DATE
   }, {
     tableName: 'cm_contacts',
     associate: function(models) {
@@ -32,9 +53,24 @@ module.exports = function(sequelize, DataTypes) {
       Contact.addScope('list', {
         include: [models.List]
       });
+      Contact.addScope('company', {
+        include: [models.Company]
+      });
       Contact.addScope('user', {
         include: [models.User]
       });
+      Contact.addScope('company_list_filter', function(query) {
+        var scope = {
+          where: {}
+        };
+        if (query.CompanyId) {
+          scope.where.CompanyId = query.CompanyId;
+        }
+        if (query.ListId) {
+          scope.where.ListId = query.ListId;
+        }
+        return scope;
+      });
     }
   });