|
1 | | -module.exports = function (hostileService, eventService, memberService, standingsService, neow, headerParser, errorResponse, successResponse, _) { |
| 1 | +module.exports = function (hostileService, eventService, memberService, standingsService, neow, headerParser, errorResponse, successResponse, async, _) { |
2 | 2 |
|
3 | 3 | var pub = {}; |
4 | 4 |
|
@@ -66,13 +66,36 @@ module.exports = function (hostileService, eventService, memberService, standing |
66 | 66 | }); |
67 | 67 |
|
68 | 68 | } else if (scanData.text === 'hostile') { |
69 | | - hostileService.addAndGet(headerParser.parse(req), scanData, req.session.armadaKey, function (error, status) { |
70 | | - if (error) return errorResponse.respond(res, 'status', 'Unable to add status.'); |
| 69 | + var hostiles = []; |
| 70 | + |
| 71 | + async.each(scanData.pilots, function(pilot, callback) { |
| 72 | + async.waterfall([ |
| 73 | + function(callback){ |
| 74 | + hostileService.getById(pilot.id, function(error, result) { |
| 75 | + if (error) return errorResponse.respond(res, 'status', 'Unable to find hostile by id ' + pilot.id); |
| 76 | + if (result !== null) { |
| 77 | + pilot.key = result.key; |
| 78 | + if (result.shipType !== null) pilot.shipType = result.shipType; |
| 79 | + if (result.shipTypeId !== null) pilot.shipTypeId = result.shipTypeId; |
| 80 | + } |
| 81 | + callback(null, pilot); |
| 82 | + }); |
| 83 | + }, |
| 84 | + function(pilot, callback){ |
| 85 | + hostileService.updateAndGet(headerParser.parse(req), pilot, req.session.armadaKey, function(hostile) { |
| 86 | + callback(null, hostile); |
| 87 | + }); |
| 88 | + } |
| 89 | + ], function (error, hostile) { |
| 90 | + if (error) return errorResponse.respond(res, 'status', 'Unable to parse status.'); |
| 91 | + hostiles.push(hostile); |
| 92 | + callback(); |
| 93 | + }); |
71 | 94 |
|
| 95 | + }, function(error) { |
72 | 96 | memberService.getByKey(req.session.memberKey, function (error, member) { |
73 | 97 | if (error) return errorResponse.respond(res, 'member', 'Error fetching member'); |
74 | | - |
75 | | - eventService.addAndGet('reportHostile', status, req.session.armadaKey, function (error, event) { |
| 98 | + eventService.addAndGet('reportHostile', hostiles, req.session.armadaKey, function(error, event) { |
76 | 99 | successResponse.respond(res); |
77 | 100 | }); |
78 | 101 | }); |
|
0 commit comments