Skip to content

Commit

Permalink
Merge pull request #13 from Lend-it/132_ver_perfil
Browse files Browse the repository at this point in the history
Solve 132 Ver Perfil
  • Loading branch information
youssef-md authored Apr 26, 2021
2 parents a7fec99 + f08de2a commit b8df7a4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/microservices/User.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import {
baseGet,
baseMultiFormPatch,
basePatch,
basePost,
basePut,
queryGet,
} from '../utils/baseRequest.js';
import endpoint from '../utils/endpoint.js';
import FormData from 'form-data';
import fs from 'fs';
import { mergeUserDataFromRequest } from '../utils/mergeUser.js';

const { user } = endpoint[process.env.NODE_ENV] || endpoint.fallback;
const { user, rating, request } =
endpoint[process.env.NODE_ENV] || endpoint.fallback;

async function createUser(req, res) {
res.json(await basePost(`${user}/users`, req.body));
Expand Down Expand Up @@ -37,10 +41,50 @@ async function createSession(req, res) {
res.json(await basePost(`${user}/session`, req.body));
}

async function getUserRequests(req, res) {
const { useremail } = req.params;
const { data: userRequester } = await queryGet(`${request}/requests`, {
requester: useremail,
});
const { data: userLender } = await queryGet(`${request}/requests`, {
lender: useremail,
});

const { data: rates } = await baseGet(`${rating}/rating`);

const userRequesterRates = userRequester.requests.map(request => {
const rate = rates.rates.find(rate => rate.requestid === request.requestid);
return {
...request,
rate,
};
});

const userLenderRates = userLender.requests.map(request => {
const rate = rates.rates.find(rate => rate.requestid === request.requestid);
return {
...request,
rate,
};
});

const mergedUserWithRequester = await mergeUserDataFromRequest(
userLenderRates
);
const mergedUserWithLender = await mergeUserDataFromRequest(
userRequesterRates
);

return res
.status(200)
.json({ mergedUserWithRequester, mergedUserWithLender });
}

export default {
createUser,
createSession,
updateAvatar,
updateUser,
updateLocation,
getUserRequests,
};
1 change: 1 addition & 0 deletions src/routes/user.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ userRouter.post('/session', User.createSession);
userRouter.put('/user', User.updateUser);
userRouter.patch('/user/avatar', upload.single('avatar'), User.updateAvatar);
userRouter.patch('/user/location', User.updateLocation);
userRouter.get('/user/requests/:useremail', User.getUserRequests);

export default userRouter;

0 comments on commit b8df7a4

Please # to comment.