Skip to content

Homework 06#7

Open
aendrevv wants to merge 6 commits intomainfrom
homework-066
Open

Homework 06#7
aendrevv wants to merge 6 commits intomainfrom
homework-066

Conversation

@aendrevv
Copy link
Owner

Увесь необхідний функціонал додав. Але ніяк не можу приборкати помилку із аутентифікацією :(

image

Copy link
Collaborator

@VitaliiHurin VitaliiHurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Щось не побачив де кладеться в базу, коли обрацьовуємо CSV потоково.
Як я зрозумів, там тільки можна вже підготовлений файл в базу класти?
Можна було зробити реалізацію додавання в базу після оптимізації зразу, тобто без файлів взагалі.

const timestamp = new Date();

const res = await client.query(
`INSERT INTO ${table} (type, color, price, quantity, created_at, updated_at, deleted_at) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (type, color, price) DO UPDATE SET quantity = ${table}.quantity + $4 RETURNING *`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Погано напряму в запит вставляти назву таблиці...

const timestamp = new Date();

const res = await client.query(
`INSERT INTO ${table} (type, color, price, quantity, created_at, updated_at, deleted_at) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (type, color, price) DO UPDATE SET quantity = ${table}.quantity + $4 RETURNING *`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

При апдейті кількості треба апдейтити і updated_at поле теж.
Також при такій реалізації цей метод має називатись не createProduct, а скоріше вже upsertProduct...

const getProductById = async (req, res) => {
const { id } = req.params;
try {
const result = await getProduct(id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Доречно ще буде опрацювати якщо юзер ввів не правильний id, то щоб це не давало 500 помилку. Тобто ще валідувати id на число. Крім цього, ще треба опрацювати ситуацію, коли за вказаним id не знайдено товару, по хорошому треба віддавати 404. Те ж саме і для delete та update.

type: e.type || 'no type',
color: e.color || 'no color',
quantity: e.quantity || 0,
price: +e.price + 0.99,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Чому тут 0.99?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments