UNPKG

copy-cat

Version:

A standalone server to mock various communications services for push messaging, email, and sms.

41 lines (33 loc) 1.04 kB
'use strict'; var routeValidator = require('express-route-validator'), validator = require('validator'); function _isValidNotification (notification) { if (!notification.send_date || !notification.content) { return false; } if (notification.android_root_params && typeof notification.android_root_params !== 'object' || notification.ios_root_params && typeof notification.ios_root_params !== 'object') { return false; } if (notification.platforms) { for (var i = 0, length = notification.platforms.length; i < length; i++) { if (!validator.isInt(notification.platforms[i], { min: 1, max: 11 })) { return false; } } } return true; } routeValidator.addValidators({ arePushwooshNotifications: function (notifications) { if (!(notifications instanceof Array)) { return false; } for (var i = 0, length = notifications.length; i < length; i++) { if (!_isValidNotification(notifications[i])) { return false; } } return true; } });