UNPKG

1.74 kBJavaScriptView Raw
1/* jshint
2browser: true, jquery: true, node: true,
3bitwise: 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
4*/
5
6'use strict';
7
8var _ = require('lodash');
9var config = require('./test-config');
10
11var api = require('./index').configure(
12 config.PSA_SERVER_HOST,
13 config.INTEGRATION_COMPANY_NAME,
14 config.INTEGRATION_LOGIN_ID,
15 config.INTEGRATION_PASSWORD
16);
17
18function findTestCompanyTickets(returnTickets) {
19 var options = {
20 Conditions: 'RecordType="s" and ClosedFlag=false and CompanyName="' + config.TEST_PSA_COMPANY_NAME + '"'
21 };
22
23 api.action('FindPartnerTicketsAction', options, function (error, result) {
24 if (error) { console.error(error); }
25 if (result) {
26 var tickets = api.normalizeCollection(result.FindPartnerTicketsAction.Tickets);
27 tickets = api.normalizeTicketsFromFindPartnerTicketsAction(tickets);
28 returnTickets(tickets);
29 }
30 });
31}
32
33function deleteTickets(tickets) {
34 console.log('deleting tickets');
35 console.log(_.map(tickets, function (t) {return [t.Id, t.Summary]; }));
36
37 _.forEach(tickets, function (ticket) {
38 var options = {
39 SrServiceRecid: ticket.Id
40 };
41
42 api.action('DeleteTicketAction', options, function (error, result) {
43 if (error) {
44 console.error(error);
45 } else {
46 console.log('deleted', ticket.Id, ticket.Summary);
47 }
48 });
49 });
50}
51
52// ----------------------------------------------------------------------------
53// Main
54
55findTestCompanyTickets(deleteTickets);
\No newline at end of file