-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vps 25/resource api definitions are implemented #216
Vps 25/resource api definitions are implemented #216
Conversation
…leting a resource and authentication
feat: added endpoint to retrieve all resources of a group feat: created resource DAO, added functions for api calls
button to test api for resources
without auth
…ps://github.com/UoaWDCC/VPS into VPS-25/Resource-API-Definitions-are-implemented
chore: fixed types and bugs in resource APIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job - looking sweet.
Few nits, after should be good to merge.
backend/src/routes/api/resources.js
Outdated
} catch (error) { | ||
return res.status(HTTP_FORBIDDEN).send("Forbidden"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is not actually true?
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403
indicates that the server understood the request but refused to process it
(4xx
suggests that there was something that went wrong because of the request made)
We should have a list of 5xx
codes as well - which is the correct response when something goes wrong on "our" side.
I'd say that this is a 5xx
error if we catch
internal server error
const getResourceById = async (resourceId) => { | ||
const resource = await Resource.findById(resourceId); | ||
return resource; | ||
}; | ||
|
||
const deleteResourceById = async (resourceId) => { | ||
const resource = await Resource.findById(resourceId); | ||
await Resource.findByIdAndRemove(resourceId); | ||
return resource; | ||
}; | ||
|
||
const getAllVisibleResources = async (groupId) => { | ||
const group = await Group.findById(groupId); | ||
const allResources = await Resource.find({}); | ||
const flags = group.currentFlags; | ||
|
||
// Filter resources based on the comparison | ||
const visibleResources = allResources.filter((resource) => | ||
resource.requiredFlags.every((flag) => flags.includes(flag)) | ||
); | ||
|
||
return visibleResources; | ||
}; | ||
|
||
const addFlag = async (groupId, flag) => { | ||
const group = await Group.findById(groupId); | ||
if (!group.currentFlags.includes(flag)) { | ||
group.currentFlags.push(flag); | ||
await group.save(); | ||
} | ||
return group.currentFlags; | ||
}; | ||
|
||
const removeFlag = async (groupId, flag) => { | ||
const group = await Group.findById(groupId); | ||
|
||
if (group.currentFlags.includes(flag)) { | ||
const index = group.currentFlags.indexOf(flag); | ||
group.currentFlags.splice(index, 1); | ||
await group.save(); | ||
} | ||
|
||
return group.currentFlags; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its just me, but do we agree using no typescript without at least documenting functions with JSDoc leads to many problems down the line? After talking to @wjin-lee code quality is now whatever in VPS but I'd imagine doing so would assist in meeting the required milestone.
At least a @param
and @returns
would help immensely for whoever next consumes these functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something simple could be:
/**
* @param {string} groupId - The unique identifier of the group.
* @param {string} flag - The flag to be removed from the group's current flags.
* @returns {Promise<string[]>} A promise that resolves to the updated list of current flags for the group.
*
* @example
* const updatedFlags = await removeFlag('12345', 'active');
* console.log(updatedFlags); // Output: ['inactive', 'pending']
*/
this way someone can hover over the function to see what its doing rather needing to go to the definition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obviously a nit tho 💀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm - I might start enforcing this from now - we can discuss more in the next sprint meeting!
@@ -24,7 +24,15 @@ const HTTP_INTERNAL_SERVER_ERROR = 500; | |||
// Apply auth middleware to all routes below this point | |||
router.use(auth); | |||
|
|||
// Create a New Resource | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch on the 5xx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
const getResourceById = async (resourceId) => { | ||
const resource = await Resource.findById(resourceId); | ||
return resource; | ||
}; | ||
|
||
const deleteResourceById = async (resourceId) => { | ||
const resource = await Resource.findById(resourceId); | ||
await Resource.findByIdAndRemove(resourceId); | ||
return resource; | ||
}; | ||
|
||
const getAllVisibleResources = async (groupId) => { | ||
const group = await Group.findById(groupId); | ||
const allResources = await Resource.find({}); | ||
const flags = group.currentFlags; | ||
|
||
// Filter resources based on the comparison | ||
const visibleResources = allResources.filter((resource) => | ||
resource.requiredFlags.every((flag) => flags.includes(flag)) | ||
); | ||
|
||
return visibleResources; | ||
}; | ||
|
||
const addFlag = async (groupId, flag) => { | ||
const group = await Group.findById(groupId); | ||
if (!group.currentFlags.includes(flag)) { | ||
group.currentFlags.push(flag); | ||
await group.save(); | ||
} | ||
return group.currentFlags; | ||
}; | ||
|
||
const removeFlag = async (groupId, flag) => { | ||
const group = await Group.findById(groupId); | ||
|
||
if (group.currentFlags.includes(flag)) { | ||
const index = group.currentFlags.indexOf(flag); | ||
group.currentFlags.splice(index, 1); | ||
await group.save(); | ||
} | ||
|
||
return group.currentFlags; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm - I might start enforcing this from now - we can discuss more in the next sprint meeting!
@@ -24,7 +24,15 @@ const HTTP_INTERNAL_SERVER_ERROR = 500; | |||
// Apply auth middleware to all routes below this point | |||
router.use(auth); | |||
|
|||
// Create a New Resource | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch on the 5xx
Describe the issue
Resources is a new feature that allows users to access various medical resources. Without API endpoints, users are unable to create, retrieve, update, or delete resources, limiting the functionality of the feature. Once the API endpoints are implemented, users can start using them when designing the resources feature.
Describe the solution
This feature enables users to interact with various medical resources by adding the following API endpoints
Risk
A potential risk is the new feature may introduce new bugs.
Definition of Done
Reviewed By
Who reviewed your PR - for commit history once merged