< I put down there users table and car_detail table, I use users table as parent login,and
when they done login they can post their data in car_detail things but I use role in my users
table the role is working as only login parent can do login for their child and post data in car_detail for their child I know the restful that will put data for parents in car_detail but I do not how to make restful api that enter data in car_detail for child so the role 1 is for parents and 2 for child I can see those role when I login for parent and child the only thing confusing me now after switching to child account how data will added through child account in car_detail >
< Here my parent table I put it as users over here where I put the role that allow login for
parent and child but child cannot login only their parents login for them
CREATE TABLE users (
user_id PRIMARY KEY,
user_name varchar(255) NOT NULL,
user_email varchar(255) NOT NULL,
user_password varchar(255) NOT NULL,
user_role INTEGER NOT NULL,
);
>
< car_detail that I need for parent account and child account so parent can see their
information in car_detair what car_name and car_model are added in that table and parent go
to thier child accont see their what car_name and car_model have for their child
CREATE TABLE car_detail (
car_id PRIMARY KEY,
car_name varchar(255) NOT NULL,
car_model varchar(255) NOT NULL,
FOREIGN KEY (user_id)
);
>
< Here is restful api for that working nicley and parent can add, upated their car_detial all I want same thing for child but I do not how car_detail will be added in this table for child router.post("/car_detail", authorization, async (req, res) => { try { const { car_name, car_mode} = req.body; const carInUse = await pool.query("SELECT car_name from car_detail WHERE car_name = $1 AND user_id =$2", [car_name, req.user.id]); if (carInUse.rows.length > 0) { return res.status(405).send("You already got this car "); }
const newcar = await pool.query(
"INSERT INTO car_detail (car_name, car_model,user_id) VALUES ($1,
$2, $3) RETURNING *", [car_name, car_model, req.user.id]
);
res.json(newcar.rows[0]);
} catch (err) {
console.log(err.message);
}
});
>