Skip to content
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

Ben Created Update Profile #16

Merged
merged 2 commits into from
Oct 14, 2024
Merged

Ben Created Update Profile #16

merged 2 commits into from
Oct 14, 2024

Conversation

prooflesben
Copy link
Contributor

Created a new post request in the controller along with a method in the service for user auth service.

import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator';

// Custom validator to ensure that at least one field is present
export function AtLeastOneProperty(validationOptions?: ValidationOptions) {
return function (object: Object, propertyName: string) {
registerDecorator({
name: 'atLeastOneProperty',
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
validator: {
validate(value: any, args: ValidationArguments) {
const object = args.object as any;
return !!(object.displayName || object.email || object.biography); // Checks if at least one is present
},
defaultMessage(args: ValidationArguments) {
return 'At least one of displayName, email, or biography is required';
},
},
});
};
}
possible validation pipe for the post request to allow all the updates to be done in one post request allowing for one update to a field or updates to multiple fields.

@jarenadams21
Copy link
Collaborator

Yea I think property testing would be interesting to try at some point

@jarenadams21 jarenadams21 merged commit 5e73bbe into main Oct 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants