-function createRequest (type, endpoint, data, to) {
- const req = new Request({
+// Wrapper that populate "toIds" argument with all our friends if it is not specified
+function createRequest (type, endpoint, data, toIds) {
+ if (toIds) return _createRequest(type, endpoint, data, toIds)
+
+ // If the "toIds" pods is not specified, we send the request to all our friends
+ db.Pod.listAllIds(function (err, podIds) {
+ if (err) {
+ logger.error('Cannot get pod ids', { error: err })
+ return
+ }
+
+ return _createRequest(type, endpoint, data, podIds)
+ })
+}
+
+function _createRequest (type, endpoint, data, toIds) {
+ const pods = []
+
+ // If there are no destination pods abort
+ if (toIds.length === 0) return
+
+ toIds.forEach(function (toPod) {
+ pods.push(db.Pod.build({ id: toPod }))
+ })
+
+ const createQuery = {