Skip to content

Commit

Permalink
Merge pull request #81 from GSG-G10/80-edit-query
Browse files Browse the repository at this point in the history
80 edit query
  • Loading branch information
Mu7ammadAbed authored Nov 7, 2021
2 parents 1d3c26a + 70bc9a8 commit 358bcbe
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
8 changes: 5 additions & 3 deletions server/controllers/users/userEstates.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const { userEstatesQuery } = require('../../database/quieres/index');
const { userEstatesQuery, agentQuery } = require('../../database/quieres/index');

const userEstateshandler = async (req, res) => {
const { userId } = req.params;

try {
if (userId > 0) {
const { rows } = await userEstatesQuery(userId);
const { rows: agentData } = await agentQuery(userId);
const { rows: estateData } = await userEstatesQuery(userId);
return res.json({
data: rows,
agentData,
estateData,
});
}
return res.status(404).json({
Expand Down
3 changes: 3 additions & 0 deletions server/database/quieres/agentQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const connection = require('../config/connection');

module.exports = (userId) => connection.query('SELECT agents.id, agents.name,agents.email,agents.phone,agents.avater FROM agents WHERE agents.id = ($1) ', [userId]);
2 changes: 2 additions & 0 deletions server/database/quieres/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const checkEmailQuery = require('./checkEmailQuery');
const editEstateQuery = require('./editEstatesQuery');
const deleteEstateQuery = require('./deleteEstateQuery');
const signUpAdminQuery = require('./signUpAdminQuery');
const agentQuery = require('./agentQuery');

module.exports = {
getAllUsersQuery,
Expand All @@ -18,4 +19,5 @@ module.exports = {
editEstateQuery,
deleteEstateQuery,
signUpAdminQuery,
agentQuery,
};
2 changes: 1 addition & 1 deletion server/database/quieres/userEstatesQuiery.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const connection = require('../config/connection');

module.exports = (userId) => connection.query('SELECT * FROM estates WHERE agent_id = $1', [userId]);
module.exports = (userId) => connection.query('SELECT estates.id, estates.title ,estates.description , estates.type,estates.category FROM estates WHERE estates.id = ($1) ', [userId]);

0 comments on commit 358bcbe

Please sign in to comment.