Skip to content

Commit

Permalink
feat: add new GET endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkparti committed Aug 20, 2023
1 parent 84ff548 commit 2d62c4c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
20 changes: 19 additions & 1 deletion server/handlers/trustHandler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ const trustPost = async (req, res) => {
res.status(200).json(trustRelationship);
};

const trustRelationshipGetById = async (req, res) => {
await trustRelationshipIdSchema.validateAsync(req.params, {
abortEarly: false,
});

const { trustRelationshipId } = req.params
const trustService = new TrustService()

const trustRelationship = await trustService.trustRelationshipGetById({
walletLoginId: req.wallet_id,
trustRelationshipId
})

res.status(200).json(trustRelationship)
}


const trustRelationshipAccept = async (req, res) => {
await trustRelationshipIdSchema.validateAsync(req.params, {
abortEarly: false,
Expand All @@ -56,7 +73,7 @@ const trustRelationshipAccept = async (req, res) => {
trustRelationshipId,
walletLoginId: req.wallet_id,
});
res.json(json);
res.status(200).json(json);
};

const trustRelationshipDecline = async (req, res) => {
Expand Down Expand Up @@ -93,4 +110,5 @@ module.exports = {
trustRelationshipAccept,
trustRelationshipDecline,
trustRelationshipDelete,
trustRelationshipGetById
};
25 changes: 25 additions & 0 deletions server/models/Trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,31 @@ class Trust {
return false;
}

async getTrustRelationshipById({ walletId, trustRelationshipId}) {
const filter = {
and: [
{
or: [
{ actor_wallet_id: walletId },
{ target_wallet_id: walletId },
{ originator_wallet_id: walletId },
],
},
{
'wallet_trust.id': trustRelationshipId,
},
],
};

const [trustRelationship] = await this._trustRepository.getByFilter(filter)

if(!trustRelationship){
throw new HttpError(404, 'No such trust relationship exists or it is not associated with the current wallet.')
}

return trustRelationship
}

// NOT YET IN USE
// /*
// * Get all the trust relationships I have requested
Expand Down
2 changes: 2 additions & 0 deletions server/routes/trustRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
trustRelationshipDelete,
trustRelationshipDecline,
trustRelationshipAccept,
trustRelationshipGetById,
trustPost,
} = require('../handlers/trustHandler');

Expand All @@ -27,6 +28,7 @@ router.post(
handlerWrapper(trustRelationshipDecline),
);
router.delete('/:trustRelationshipId', handlerWrapper(trustRelationshipDelete));
router.get('/:trustRelationshipId', handlerWrapper(trustRelationshipGetById))

routerWrapper.use(
'/trust_relationships',
Expand Down
9 changes: 9 additions & 0 deletions server/services/TrustService.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ class TrustService {
trustRelationshipId,
});
}

async trustRelationshipGetById({ walletLoginId, trustRelationshipId}){
return this._trust.getTrustRelationshipById({
walletId: walletLoginId,
trustRelationshipId
})
}

}


module.exports = TrustService;

0 comments on commit 2d62c4c

Please sign in to comment.