const jwt = require('jsonwebtoken');

const getPurchasedBooks = require('../../lib/amazon/getPurchasedBooks');
const User = require('../../db/models/user');
const cert = process.env.SECRET_KEY_BASE;

const options = { name: 'books.purchased.get', durable: true };
const handler = ({ dataToken }, ack) => {
  (async () => {
    const { identifier, aid, apw } = jwt.verify(dataToken, cert);
    const user = await User.findOne({ identifier });
    const books = await getPurchasedBooks(aid, apw);
    await user.createBooksPurchased(books);
    ack();
  })();
};

module.exports = { options, handler };

@@ -29,16 +29,55 @@
 token');
+%0Aconst chunk = require('lodash.chunk');
 %0A%0Aconst 
@@ -232,16 +232,88 @@
 _BASE;%0A%0A
+const exchange = require('../amqp')();%0Aconst key = 'books.detail.get';%0A%0A
 const op
@@ -599,16 +599,16 @@
 , apw);%0A
-
     awai
@@ -643,16 +643,225 @@
 books);%0A
+    chunk(books, 10).map((items) =%3E %7B%0A      const asins = items.map(item =%3E item.asin);%0A      // console.log('processing to %5B%25s%5D... %25s', key, asins.join());%0A      exchange.publish(%7B asins %7D, %7B key %7D);%0A    %7D);%0A
     ack(

add pushing queue of getting book info