@@ -290,15 +290,82 @@ exports.update_status = function(req, res, next){
290290 console . log ( error )
291291 return response . error ( res , 'report' , 'Error reporting status: ' + error ) ;
292292 } )
293- . done ( function ( ) {
294-
295-
296- } ) ;
293+ . done ( ) ;
297294 }
298295} ;
299296
300- exports . add_scan = function ( req , res , next ) {
301- response . success ( res , [ ] ) ;
297+ exports . add_scan = function ( req , res , next ) {
298+
299+ Member . findOneQ ( { key : req . session . memberKey } )
300+ . then ( function ( reporter ) {
301+ var scan = Scan . prepare ( reporter . fleetKey , reporter , req . body . scanData ) ;
302+
303+ if ( ! scan . shipTypes . length ) return response . error ( res , 'report' , 'Invalid scan data.' ) ;
304+ if ( ! scan . shipClasses . length ) return response . error ( res , 'report' , 'Invalid scan data.' ) ;
305+
306+ var event = Event . prepare ( 'scanPosted' , reporter . fleetKey , scan ) ;
307+ scan . saveQ ( ) ;
308+ event . saveQ ( ) ;
309+
310+ return response . success ( res ) ;
311+ } )
312+ . catch ( function ( error ) {
313+ console . log ( error )
314+ return response . error ( res , 'report' , 'Error reporting scan: ' + error ) ;
315+ } )
316+ . done ( ) ;
317+
318+ // var checkScanDataIntegrity = function (scan) {
319+ // var shipQty = 0;
320+ //
321+ // for (var index in scan) {
322+ // if (!typeof(scan) === 'object'
323+ // || (!scan[index].shipType && !scan[index].shipClass)
324+ // || !scan[index].count
325+ // || !scan[index].details
326+ // || !typeof scan[index].details === 'object') {
327+ //
328+ // return false;
329+ // }
330+ //
331+ // for (var detailIndex in scan[index].details) {
332+ // if (!scan[index].details[detailIndex].distance
333+ // || !scan[index].details[detailIndex].shipName) {
334+ //
335+ // return false;
336+ // }
337+ // shipQty++;
338+ // }
339+ // }
340+ //
341+ // return !(shipQty > settings.scanMaxShips || shipQty < settings.scanMinShips);
342+ // };
343+ //
344+ // pub.run = function (req, res) {
345+ // logger.processing(req);
346+ //
347+ // var scanData = req.body.scanData;
348+ // if ( !scanData
349+ // || !checkScanDataIntegrity(scanData.types)
350+ // || !checkScanDataIntegrity(scanData.classes) ) {
351+ // return errorResponse.respond(req, res, 'scan', 'Invalid scan data.');
352+ // }
353+ //
354+ // scanService.addAndGet(headerParser.parse(req), scanData, req.session.fleetKey, function (error, scan) {
355+ // if (error) return errorResponse.respond(req, res, 'scan', 'Unable to add scan');
356+ //
357+ // memberService.getByKey(req.session.memberKey, function (error, member) {
358+ // if (error) return errorResponse.respond(req, res, 'member', 'Error fetching member');
359+ //
360+ // eventService.addAndGet('scanPosted', scan, req.session.fleetKey, function (error, event) {
361+ // successResponse.respond(res);
362+ // });
363+ // });
364+ // });
365+ // };
366+ //
367+ // return pub;
368+
302369} ;
303370
304371exports . add_report = function ( req , res , next ) {
0 commit comments