Skip to content

Commit

Permalink
static method Book.list() #14
Browse files Browse the repository at this point in the history
  • Loading branch information
tima101 committed Jan 31, 2018
1 parent 4f15f9a commit f53dc07
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions server/models/Book.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ class BookClass {
let books = [];
const otherBooks = [];

if (process.env.DEMO) {
allBooks.forEach((b) => {
if (b.userId && b.userId.equals(userId)) {
books.push(b);
} else {
otherBooks.push(b);
}
});
} else {
books = allBooks;
}

return { books, otherBooks };
}

Expand Down Expand Up @@ -125,7 +137,6 @@ class BookClass {
isInPreorder = null,
preorderPrice = null,
}) {

const slug = await generateSlug(this, name);

return this.create({
Expand Down Expand Up @@ -274,13 +285,13 @@ class BookClass {
logger.error('Email sending error:', error);
});

subscribe({
email: user.email,
listName: isPreorder ? 'preordered' : 'ordered',
book: book.slug,
}).catch((error) => {
logger.error('Mailchimp subscribing error:', error);
});
subscribe({
email: user.email,
listName: isPreorder ? 'preordered' : 'ordered',
book: book.slug,
}).catch((error) => {
logger.error('Mailchimp subscribing error:', error);
});

return Purchase.create({
userId: user._id,
Expand Down

0 comments on commit f53dc07

Please sign in to comment.