Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Feature/minimum validation #20

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/artworks/artwork.constraints.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
export const ARTWORK_CONSTRAINTS = {
title: {
presence: true
},
imageUrl: {
presence: true,
url: true
},
artistId: {
presence: true,
personExists: true
},
eventbriteId: {
presence: false
}
title: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to indentation using 4 spaces? I know this is linting issue again 🤣

presence: { allowEmpty: false }
},
imageUrl: {
presence: { allowEmpty: false },
url: true
},
artistId: {
presence: { allowEmpty: false }
},
eventbriteId: {
presence: false
}
};
1 change: 1 addition & 0 deletions src/hackoss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './firebase/firebase.config';
export * from './firebase/firebase.repository';

export * from './utils';
export * from './validators';
46 changes: 23 additions & 23 deletions src/locations/location.constraints.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
export const LOCATION_CONSTRAINTS = {
name: {
presence: true
},
seatingCapacity: {
presence: true,
numericality: {
onlyInteger: true,
greaterThan: 0
}
},
addressLine1: {
presence: true
},
addressLine2: {
presence: false
},
imageUrl: {
presence: false,
url: true
},
eventbriteId: {
presence: false
},
name: {
presence: { allowEmpty: false }
},
seatingCapacity: {
presence: { allowEmpty: false },
numericality: {
onlyInteger: true,
greaterThan: 0
}
},
addressLine1: {
presence: { allowEmpty: false }
},
addressLine2: {
presence: false
},
imageUrl: {
presence: false,
urlAllowEmpty: true
},
eventbriteId: {
presence: false
}
};
36 changes: 18 additions & 18 deletions src/organisations/organisation.constraints.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export const ORGANISATION_CONSTRAINTS = {
name: {
presence: true
},
about: {
presence: true
},
websiteUrl: {
presence: false,
url: true
},
avatarUrl: {
presence: false,
url: true
},
githubUrl: {
presence: false,
url: true
}
name: {
presence: { allowEmpty: false }
},
about: {
presence: { allowEmpty: false }
},
websiteUrl: {
presence: false,
urlAllowEmpty: true
},
avatarUrl: {
presence: false,
urlAllowEmpty: true
},
githubUrl: {
presence: false,
urlAllowEmpty: true
}
};
36 changes: 18 additions & 18 deletions src/people/person.constraints.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
export const PERSON_CONSTRAINTS = {
name: {
presence: true
},
about: {
presence: true
},
websiteUrl: {
presence: false,
url: true
},
avatarUrl: {
presence: false,
url: true
},
githubUrl: {
presence: false,
url: true
}
name: {
presence: { allowEmpty: false }
},
about: {
presence: { allowEmpty: false }
},
websiteUrl: {
presence: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need presence: false here now that we have the urlAllowEmpty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies to other validation files.

urlAllowEmpty: true
},
avatarUrl: {
presence: false,
urlAllowEmpty: true
},
githubUrl: {
presence: false,
urlAllowEmpty: true
}
};
7 changes: 7 additions & 0 deletions src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ validators.array = (value: any[], options: ArrayValidatorOptions, key: string, a
validators.object = (value: any, options: MapValidatorOptions, key: string, attributes: any) => {
return validate(value, options.constraints);
};

validators.urlAllowEmpty = (values: any, ...others: any[]) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice. A bit disappointing the library does not support it by default.

if (!values) return;
return validators.url(values, ...others);
};

export default validate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot about this one. Wouldn't have worked without this aye?

Copy link
Member

@clarencecastillo clarencecastillo Feb 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, XXXexists in the repositories also add custom validators. In that case, they should also be exported there and imported here. Not sure with this one.