R
R
Roman Andreevich2021-07-23 07:17:26
PostgreSQL
Roman Andreevich, 2021-07-23 07:17:26

How to write a query in PostgreSql?

Colleagues, good day to all. I ask for help IMHO there is not enough or already confused))) The essence is this:

There is a products table, each product has an owner. There are also roles - admin, owner and guest. product model:

{
   userId, // owner продукта
   categoryId,
   title,
   slug,
   avatar,
   approved,
   published,
   publishedAt,
   createdAt,
}


It is necessary to make a request in PG, Sequelize is used.
The point is, you need to return a list of products, if the owner or admin requests, then add the attributes 'approved', 'published', 'publishedAt', 'createdAt', and if the request is made by guest, then set the condition where published=true.

I've already broken my head. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-07-23
@freeExec

A clumsy version on the forehead, make UNIONall three requests from different rights, where instead of inaccessible fields you insert at least NULL, at least в доступе отказано.
A more beautiful option, you have three views ala ViewProductByAdmin, which, if there are not enough rights, returns a cookie, and the choice of the view already lies with the client.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question