-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-clean.js
More file actions
55 lines (45 loc) · 1.69 KB
/
test-clean.js
File metadata and controls
55 lines (45 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* jshint
browser: true, jquery: true, node: true,
bitwise: true, camelcase: false, curly: true, eqeqeq: true, es3: true, expr: true, evil: true, forin: true, immed: true, indent: 4, latedef: true, newcap: true, noarg: true, noempty: true, nonew: true, quotmark: single, regexdash: true, strict: true, sub: true, trailing: true, undef: true, unused: vars, white: true
*/
'use strict';
var _ = require('lodash');
var config = require('./test-config');
var api = require('./index').configure(
config.PSA_SERVER_HOST,
config.INTEGRATION_COMPANY_NAME,
config.INTEGRATION_LOGIN_ID,
config.INTEGRATION_PASSWORD
);
function findTestCompanyTickets(returnTickets) {
var options = {
Conditions: 'RecordType="s" and ClosedFlag=false and CompanyName="' + config.TEST_PSA_COMPANY_NAME + '"'
};
api.action('FindPartnerTicketsAction', options, function (error, result) {
if (error) { console.error(error); }
if (result) {
var tickets = api.normalizeCollection(result.FindPartnerTicketsAction.Tickets);
tickets = api.normalizeTicketsFromFindPartnerTicketsAction(tickets);
returnTickets(tickets);
}
});
}
function deleteTickets(tickets) {
console.log('deleting tickets');
console.log(_.map(tickets, function (t) {return [t.Id, t.Summary]; }));
_.forEach(tickets, function (ticket) {
var options = {
SrServiceRecid: ticket.Id
};
api.action('DeleteTicketAction', options, function (error, result) {
if (error) {
console.error(error);
} else {
console.log('deleted', ticket.Id, ticket.Summary);
}
});
});
}
// ----------------------------------------------------------------------------
// Main
findTestCompanyTickets(deleteTickets);