-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Учебный проект: долгая прогулка #19
Changes from 13 commits
9585263
02cc07c
11c9fa8
f2d91a9
580dca0
1dd8d2a
b0d4cf9
218c941
b7c5bcf
ab5290a
30b1a5b
fdd3fe5
bdb53ac
d37ab31
f03f507
7cfadff
4b457ee
d8291ec
afd7aca
32e60e0
71ae001
f024279
8949777
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ myRouter.get(`/`, async (req, res) => { | |
}); | ||
|
||
myRouter.get(`/comments`, async (req, res) => { | ||
const _offers = await api.getOffers(); | ||
const _offers = await api.getOffers({comments: true}); | ||
|
||
res.render(`${ROOT}/comments`, {_offers: _offers.slice(0, 3)}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нужен поясняющий комментарий, почему мы так делаем. Отрезаем только первые три части массива. |
||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,12 @@ const storage = multer.diskStorage({ | |
|
||
const upload = multer({storage}); | ||
|
||
offersRouter.get(`/add`, (req, res) => res.render(`${ROOT}/add`)); | ||
offersRouter.get(`/add`, async (req, res) => { | ||
const categories = await api.getCategories(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вопрос, что будет если сервис вернет ошибку? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Связался с автором курса — будем обрабатывать ошибки и делать валидацию в следующем модуле. Остальное исправил. |
||
|
||
res.render(`${ROOT}/add`, {categories}); | ||
}); | ||
|
||
offersRouter.post(`/add`, upload.single(`avatar`), async (req, res) => { | ||
const {file: { | ||
filename: picture, | ||
|
@@ -64,7 +69,15 @@ offersRouter.get(`/edit/:id`, async (req, res) => { | |
res.render(`${ROOT}/edit`, {offer, categories}); | ||
}); | ||
|
||
offersRouter.get(`/category/:id`, (req, res) => res.render(`${ROOT}/category`)); | ||
offersRouter.get(`/:id`, (req, res) => res.render(`${ROOT}/offer`)); | ||
offersRouter.get(`/:id`, async (req, res) => { | ||
const {id} = req.params; | ||
|
||
const _offer = await api.getOffer(id, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Опять все вместе подчеркивание и await |
||
|
||
res.render(`${ROOT}/offer`, {_offer}); | ||
}); | ||
|
||
offersRouter.get(`/category/:id`, (req, res) => | ||
res.render(`${ROOT}/category`)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Мы в шаблон ничего не передаем? Вроде же конкретную категорию просим :id |
||
|
||
module.exports = offersRouter; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,53 @@ | ||
extends ../layout.pug | ||
|
||
block content | ||
- | ||
const formatDate = (dateString) => { | ||
const date = new Date(dateString); | ||
|
||
return date.toLocaleString(); | ||
} | ||
|
||
section.ticket | ||
.ticket__wrapper | ||
h1.visually-hidden Карточка объявления | ||
.ticket__content | ||
.ticket__img | ||
img(src='img/ticket.jpg' srcset='img/[email protected] 2x' alt='Изображение товара') | ||
img(src=`/img/${_offer.picture}.jpg` | ||
srcset=`/img/${_offer.picture}@2x.jpg 2x` | ||
alt=_offer.title) | ||
.ticket__info | ||
h2.ticket__title Мое старое кресло | ||
h2.ticket__title #{_offer.title} | ||
.ticket__header | ||
p.ticket__price | ||
span.js-sum 4000 | ||
span.js-sum #{_offer.sum} | ||
| ₽ | ||
p.ticket__action ПРОДАМ | ||
p.ticket__action #{_offer.type === `OFFER` ? `КУПЛЮ` : `ПРОДАМ`} | ||
.ticket__desc | ||
p Продам свое старое кресло, чтобы сидеть и читать книги зимними вечерами. Ножки мягкие, мой пол не царапают. Кресло почти новое – продаю, т.к. надоел серый цвет. Можно, конечно, накинуть плед и спасти ситуацию, но я все-таки хочу просто другое кресло. В общем оно на самом деле удобное и с ним все хорошо, просто нам пора расстаться. | ||
p #{_offer.description} | ||
.ticket__data | ||
p | ||
b Дата добавления: | ||
span 20 ноября 2019 | ||
span #{formatDate(_offer.createdAt)} | ||
p | ||
b Автор: | ||
a(href='#') Денис Шкатулкин | ||
p | ||
b Контакты: | ||
a(href='mailto:[email protected]') [email protected] | ||
ul.ticket__tags | ||
li | ||
a.category-tile.category-tile--small(href='#') | ||
span.category-tile__image | ||
img(src='img/cat.jpg' srcset='img/[email protected] 2x' alt='Иконка категории') | ||
span.category-tile__label Дом | ||
each category in _offer.categories | ||
li | ||
a.category-tile.category-tile--small(href='#') | ||
span.category-tile__image | ||
+categoryImage(category) | ||
span.category-tile__label #{category.name} | ||
li | ||
a.category-tile.category-tile--small(href='#') | ||
span.category-tile__image | ||
img(src='img/cat04.jpg' srcset='img/[email protected] 2x' alt='Иконка категории') | ||
span.category-tile__label Спорт и отдых | ||
|
||
.ticket__comments | ||
h2.ticket__subtitle Коментарии | ||
.ticket__comment-form | ||
|
@@ -51,24 +62,16 @@ block content | |
label(for='comment-field') Текст комментария | ||
span Обязательное поле | ||
button.comment-form__button.btn.btn--white.js-button(type='submit' disabled) Отправить | ||
|
||
.ticket__comments-list | ||
ul.comments-list | ||
li | ||
.comment-card | ||
.comment-card__header | ||
a.comment-card__avatar.avatar(href='#') | ||
img(src='img/avatar02.jpg' srcset='img/[email protected] 2x' alt='Аватар пользователя') | ||
p.comment-card__author Георгий Шпиц | ||
.comment-card__content | ||
p Что это за рухлядь? Стыдно такое даже фотографировать, не то, что продавать. | ||
li | ||
.comment-card | ||
.comment-card__header | ||
a.comment-card__avatar.avatar(href='#') | ||
img(src='img/avatar03.jpg' srcset='img/[email protected] 2x' alt='Аватар пользователя') | ||
p.comment-card__author Александр Бурый | ||
.comment-card__content | ||
p | ||
| А можете доставить мне домой? Готов доплатить 300 сверху. | ||
br | ||
| Живу в центре прямо рядом с Моховой улицей. Готов купить прямо сейчас. Мой телефон 9032594748 | ||
if _offer.comments && _offer.comments.length | ||
each comment in _offer.comments | ||
li | ||
.comment-card | ||
.comment-card__header | ||
a.comment-card__avatar.avatar(href='#') | ||
img(src='img/avatar03.jpg' srcset='img/[email protected] 2x' alt='Аватар пользователя') | ||
p.comment-card__author Александр Бурый | ||
.comment-card__content | ||
p #{comment.text} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,10 @@ | ||
section.categories-list | ||
h1.visually-hidden Сервис объявлений "Куплю - продам" | ||
h1.visually-hidden Сервис объявлений «Куплю — продам» | ||
ul.categories-list__wrapper | ||
li.categories-list__item | ||
a.category-tile.category-tile--default(href='#') | ||
span.category-tile__image | ||
img(src='img/cat.jpg' srcset='img/[email protected] 2x' alt='Иконка категории') | ||
span.category-tile__label | ||
| Дом | ||
span.category-tile__qty.js-qty 81 | ||
li.categories-list__item | ||
a.category-tile.category-tile--default(href='#') | ||
span.category-tile__image | ||
img(src='img/cat02.jpg' srcset='img/[email protected] 2x' alt='Иконка категории') | ||
span.category-tile__label | ||
| Электроника | ||
span.category-tile__qty.js-qty 62 | ||
li.categories-list__item | ||
a.category-tile.category-tile--default(href='#') | ||
span.category-tile__image | ||
img(src='img/cat03.jpg' srcset='img/[email protected] 2x' alt='Иконка категории') | ||
span.category-tile__label | ||
| Одежда | ||
span.category-tile__qty.js-qty 106 | ||
li.categories-list__item | ||
a.category-tile.category-tile--default(href='#') | ||
span.category-tile__image | ||
img(src='img/cat04.jpg' srcset='img/[email protected] 2x' alt='Иконка категории') | ||
span.category-tile__label | ||
| Спорт/отдых | ||
span.category-tile__qty.js-qty 86 | ||
li.categories-list__item | ||
a.category-tile.category-tile--default(href='#') | ||
span.category-tile__image | ||
img(src='img/cat05.jpg' srcset='img/[email protected] 2x' alt='Иконка категории') | ||
span.category-tile__label | ||
| Авто | ||
span.category-tile__qty.js-qty 34 | ||
li.categories-list__item | ||
a.category-tile.category-tile--default(href='#') | ||
span.category-tile__image | ||
img(src='img/cat06.jpg' srcset='img/[email protected] 2x' alt='Иконка категории') | ||
span.category-tile__label | ||
| Книги | ||
span.category-tile__qty.js-qty 92 | ||
each category in categories | ||
li.categories-list__item | ||
a.category-tile.category-tile--default(href='#') | ||
span.category-tile__image | ||
+categoryImage(category) | ||
span.category-tile__label #{category.name} | ||
span.category-tile__qty.js-qty #{category.count} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У нас это не класс, почему подчеркивание? Это же не приватный метод
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Потому что шаблонизатор «Паг 3» выдаёт ошибку, если переменная начинается с ключевого слова: в моём случае с
of
.Баг в Паге 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
так тогда передавай {_offers: offers} в сам шаблон. а лучше (offersForPug: offers) чтобы понять было, что не просто так это сделали.