-
Notifications
You must be signed in to change notification settings - Fork 0
Add profile completion check in tools #72
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
bb1063c
94c2600
4723fc2
23864a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -564,6 +564,52 @@ export default class Tools { | |
| return Array.from(conflicts); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a profile meets the minimum requirements defined by a venue. | ||
| * | ||
| * @param {object} profile - The profile object. | ||
| * @param {object} profileReqs - An object defining the required profile fields and conditions. | ||
| * @returns {boolean} - Returns true if the profile satisfies all requirements, false otherwise. | ||
| */ | ||
| isProfileComplete(profile, profileReqs) { | ||
| // If no profile or no requirements, skip check | ||
| if (!profile.id.startsWith('~') || !profileReqs) { | ||
|
enrubio marked this conversation as resolved.
Outdated
|
||
| return true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't you throw an error if a profile object is not passed?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decided to not check |
||
| } | ||
|
|
||
| for (const [profilePath, expectedValue] of Object.entries(profileReqs)) { | ||
| const pathItems = profilePath.split('.'); | ||
| let actualValue = profile; | ||
|
|
||
| // Resolve actual value from the profile | ||
| for (const item of pathItems) { | ||
| if (actualValue && typeof actualValue === 'object') { | ||
| actualValue = actualValue?.[item]; | ||
| } else { | ||
| actualValue = null; | ||
| } | ||
|
|
||
| if (actualValue === null || actualValue === undefined) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Check number of entries | ||
| if (typeof expectedValue === 'number') { | ||
| if (actualValue?.length < expectedValue) { | ||
| return false; | ||
| } | ||
| // Check if field exists in profile (e.g. links) | ||
| } else if (expectedValue === true && !actualValue) { | ||
| return false; | ||
| } else { | ||
| console.log(`Invalid path: ${profilePath}`); | ||
|
enrubio marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we throw an error here instead of logging it?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic was simplified so that PCs aren't allowed to require random parts of the profile. Now I ignore incorrect input from PCs by returning true (e.g. if they set "dblp": true) so that a person isn't wrongly marked as incomplete. |
||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Get the profile information for a given profile that includes the domains, emails, relations and publications. | ||
| * | ||
|
|
||
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.
Could you add a test to see what
profileReqslooks like?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.
It's located here right?:
packages/client/test/test.jsThere 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.
Yes, that's the right spot.