Built motion from commit (unavailable).|2.4.3
[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         id: 4,
48         firstName: 'Mario',
49         lastName: 'Rossi',
50         phone: '789',
51         email: 'mario.rossio@xyz.com',
52         ListId: 2,
53         CompanyId: 2,
54         tags: getRandomTag(),
55         description: 'contact auto generated'
56     },
57     {
58         id: 5,
59         firstName: 'John',
60         lastName: 'Simon',
61         phone: '789',
62         email: 'john.simon@zzz.com',
63         ListId: 2,
64         CompanyId: 3,
65         tags: getRandomTag(),
66         description: 'contact auto generated'
67     }
68 ];
69
70 exports.create = function() {
71     return db.CmContact
72         .bulkCreate(contacts, {
73             ignoreDuplicates: true,
74             individualHooks: true
75         })
76         .then(function() {
77             logger.info('Contacts have been created');
78         })
79         .catch(function(err) {
80             logger.error('Can\'t create Contacts');
81         });
82 };