1 |
|
2 | var CrmModule, Leads, Request, _;
|
3 |
|
4 | _ = require('underscore');
|
5 |
|
6 | CrmModule = require('./crm-module');
|
7 |
|
8 | Request = require('../../request');
|
9 |
|
10 | Leads = (function() {
|
11 | class Leads extends CrmModule {
|
12 | getMyRecords() {
|
13 | throw new Error('Not Implemented');
|
14 | }
|
15 |
|
16 | getSearchRecordsByPDC() {
|
17 | throw new Error('Not Implemented');
|
18 | }
|
19 |
|
20 | deleteRecords() {
|
21 | throw new Error('Not Implemented');
|
22 | }
|
23 |
|
24 | convertLead(lead_id, options, cb) {
|
25 | var defaults, query, records, request, url;
|
26 | if (!lead_id) {
|
27 | throw new Error('Requires a Lead Id');
|
28 | }
|
29 | if (!options) {
|
30 | throw new Error('Requires an options');
|
31 | }
|
32 | defaults = {
|
33 | createPotential: false,
|
34 | assignTo: '',
|
35 | notifyLeadOwner: true,
|
36 | notifyNewEntityOwner: true
|
37 | };
|
38 | _.defaults(options, defaults);
|
39 | records = [_.pick(options, ['createPotential', 'assignTo', 'notifyLeadOwner', 'notifyNewEntityOwner'])];
|
40 | if (options.createPotential === true && !_.isObject(options.potential)) {
|
41 | throw new Error('Requires a potential');
|
42 | } else if (options.createPotential === true) {
|
43 | records.push(options.potential);
|
44 | }
|
45 | query = {
|
46 | leadId: lead_id,
|
47 | newFormat: 1,
|
48 | xmlData: this.build(records)
|
49 | };
|
50 | options = {
|
51 | method: 'POST'
|
52 | };
|
53 | url = this.buildUrl(query, ['convertLead'], options);
|
54 | request = new Request(this, url);
|
55 | return request.request((err, response) => {
|
56 | var processed;
|
57 | if (err) {
|
58 | if (_.isFunction(cb)) {
|
59 | return cb(err, null);
|
60 | }
|
61 | } else {
|
62 | processed = this.processRecord(response.data);
|
63 | response.data = processed;
|
64 | if (_.isFunction(cb)) {
|
65 | return cb(null, response);
|
66 | }
|
67 | }
|
68 | });
|
69 | }
|
70 |
|
71 | getRelatedRecords() {
|
72 | throw new Error('Not Implemented');
|
73 | }
|
74 |
|
75 | updateRelatedRecords() {
|
76 | throw new Error('Not Implemented');
|
77 | }
|
78 |
|
79 | getUsers() {
|
80 | throw new Error('Not Implemented');
|
81 | }
|
82 |
|
83 | downloadPhoto() {
|
84 | throw new Error('Not Implemented');
|
85 | }
|
86 |
|
87 | deletePhoto() {
|
88 | throw new Error('Not Implemented');
|
89 | }
|
90 |
|
91 | };
|
92 |
|
93 | Leads.prototype.name = 'Leads';
|
94 |
|
95 | return Leads;
|
96 |
|
97 | }).call(this);
|
98 |
|
99 | module.exports = Leads;
|