Built motion from commit 3e059bc2.|2.5.32
[motion2.git] / server / config / seedDB / contacts.js
1 'use strict';
2
3 var db = require('../../mysqldb').db;
4 var logger = require('../logger')('app');
5
6 var tags = require('./tags');
7
8 // See tags file
9 var tags = tags.getNames();
10 var getRandomTag = function() {
11   var length = tags.length - 1;
12   return [tags[Math.floor(Math.random() * length) + 1]];
13 };
14
15 var contacts = [{
16   id: 1,
17   firstName: 'Mario',
18   lastName: 'Rossi',
19   phone: '123',
20   email: 'mario.rossi@xcally.com',
21   ListId: 1,
22   CompanyId: 1,
23   tags: getRandomTag(),
24   description: 'contact auto generated'
25 }, {
26   id: 2,
27   firstName: 'Giuseppe',
28   lastName: 'Verdi',
29   phone: '456',
30   email: 'giuseppe.verdi@xcally.com',
31   ListId: 1,
32   CompanyId: 1,
33   tags: getRandomTag(),
34   description: 'contact auto generated'
35 }, {
36   id: 3,
37   firstName: 'Andrea',
38   lastName: 'Bianco',
39   phone: '789',
40   email: 'andrea.bianco@xcally.com',
41   ListId: 2,
42   CompanyId: 1,
43   tags: getRandomTag(),
44   description: 'contact auto generated'
45 }];
46
47 exports.create = function() {
48   return db.CmContact
49     .bulkCreate(contacts, {
50       ignoreDuplicates: true,
51       individualHooks: true
52     })
53     .then(function() {
54       logger.info('Contacts have been created');
55     })
56     .catch(function(err) {
57       logger.error('Can\'t create Contacts');
58     });
59 };