@@ -645,7 +645,7 @@ module.exports = (sequelize, DataTypes) => {
645645 return "The name field is required." ;
646646 } else if ( "string" !== typeof payload . name ) {
647647 return "The name field must be a string." ;
648- } else if ( 50 < payload . name . length ) {
648+ } else if ( 50 < payload . name . trim ( ) . length ) {
649649 return "The name field must be less than 51 characters." ;
650650 } else {
651651 const nameExists = await this . getProductBySlug (
@@ -666,18 +666,22 @@ module.exports = (sequelize, DataTypes) => {
666666 return "The weight field is required." ;
667667 } else if ( null === `${ payload . weight } ` . match ( numberWithOptionalDecimalPartRegex ) ) {
668668 return "The weight field must be a number"
669+ } else if ( 500 < Number ( payload . weight ) ) {
670+ return "The weight field number must not be greater than 500." ;
669671 }
670672
671673 if ( undefined === payload . price ) {
672674 return "The price field is required." ;
673675 } else if ( null === `${ payload . price } ` . match ( numberWithOptionalDecimalPartRegex ) ) {
674676 return "The price field must be a number"
677+ } else if ( 500 < Number ( payload . price ) ) {
678+ return "The price field number must not be greater than 500." ;
675679 }
676680
677681 if ( payload . description ) {
678682 if ( "string" !== typeof payload . description ) {
679683 return "The description field must be a string." ;
680- } else if ( 1000 < payload . description . length ) {
684+ } else if ( 1000 < payload . description . trim ( ) . length ) {
681685 return "The description field must be less than 1001 characters." ;
682686 }
683687 }
@@ -728,19 +732,19 @@ module.exports = (sequelize, DataTypes) => {
728732 if ( payload . stripeProductId ) {
729733 if ( "string" !== typeof payload . stripeProductId ) {
730734 return "The stripe product id field must be of type string."
731- } else if ( 15 > payload . stripeProductId . length ) {
735+ } else if ( 15 > payload . stripeProductId . trim ( ) . length ) {
732736 return "The stripe product id field length must be greater than 15 characters." ;
733- } else if ( 30 < payload . stripeProductId . length ) {
737+ } else if ( 30 < payload . stripeProductId . trim ( ) . length ) {
734738 return "The stripe product id field length must not exceed 30 characters." ;
735739 }
736740 }
737741
738742 if ( payload . stripePriceId ) {
739743 if ( "string" !== typeof payload . stripePriceId ) {
740744 return "The stripe price id field must be of type string."
741- } else if ( 15 > payload . stripePriceId . length ) {
745+ } else if ( 15 > payload . stripePriceId . trim ( ) . length ) {
742746 return "The stripe price id field length must be greater than 15 characters." ;
743- } else if ( 50 < payload . stripePriceId . length ) {
747+ } else if ( 50 < payload . stripePriceId . trim ( ) . length ) {
744748 return "The stripe price id field length must not exceed 50 characters." ;
745749 }
746750 }
@@ -766,7 +770,7 @@ module.exports = (sequelize, DataTypes) => {
766770 return "The name field is required." ;
767771 } else if ( "string" !== typeof payload . name ) {
768772 return "The name field must be a string." ;
769- } else if ( 50 < payload . name . length ) {
773+ } else if ( 50 < payload . name . trim ( ) . length ) {
770774 return "The name field must be less than 51 characters." ;
771775 } else {
772776 const newSlug = slugify ( payload . name ) ;
@@ -790,18 +794,22 @@ module.exports = (sequelize, DataTypes) => {
790794 return "The weight field is required." ;
791795 } else if ( null === `${ payload . weight } ` . match ( numberWithOptionalDecimalPartRegex ) ) {
792796 return "The weight field must be a number"
797+ } else if ( 500 < Number ( payload . weight ) ) {
798+ return "The weight field number must not be greater than 500." ;
793799 }
794800
795801 if ( undefined === payload . price ) {
796802 return "The price field is required." ;
797803 } else if ( null === `${ payload . price } ` . match ( numberWithOptionalDecimalPartRegex ) ) {
798804 return "The price field must be a number"
805+ } else if ( 500 < Number ( payload . price ) ) {
806+ return "The price field number must not be greater than 500." ;
799807 }
800808
801809 if ( payload . description ) {
802810 if ( "string" !== typeof payload . description ) {
803811 return "The description field must be a string." ;
804- } else if ( 1000 < payload . description . length ) {
812+ } else if ( 1000 < payload . description . trim ( ) . length ) {
805813 return "The description field must be less than 1001 characters." ;
806814 }
807815 }
@@ -883,14 +891,14 @@ module.exports = (sequelize, DataTypes) => {
883891
884892 static getNewProductData ( payload ) {
885893 const result = {
886- name : payload . name ,
894+ name : payload . name . trim ( ) ,
887895 units : payload . units ,
888896 weight : payload . weight ,
889897 price : payload . price ,
890898 isLive : false ,
891899 } ;
892900 if ( payload . description ) {
893- result . description = payload . description ;
901+ result . description = payload . description . trim ( ) ;
894902 }
895903 if ( payload . category ) {
896904 result . category = payload . category ;
@@ -904,24 +912,24 @@ module.exports = (sequelize, DataTypes) => {
904912 }
905913 }
906914 if ( payload . stripeProductId ) {
907- result . stripeProductId = payload . stripeProductId ;
915+ result . stripeProductId = payload . stripeProductId . trim ( ) ;
908916 }
909917 if ( payload . stripePriceId ) {
910- result . stripePriceId = payload . stripePriceId ;
918+ result . stripePriceId = payload . stripePriceId . trim ( ) ;
911919 }
912920 return result ;
913921 }
914922
915923 static getEditProductData ( payload ) {
916924 const result = {
917- name : payload . name ,
925+ name : payload . name . trim ( ) ,
918926 units : payload . units ,
919927 weight : payload . weight ,
920928 price : payload . price ,
921929 isLive : false ,
922930 } ;
923931 if ( payload . description ) {
924- result . description = payload . description ;
932+ result . description = payload . description . trim ( ) ;
925933 }
926934 if ( payload . category ) {
927935 result . category = payload . category ;
@@ -935,10 +943,10 @@ module.exports = (sequelize, DataTypes) => {
935943 }
936944 }
937945 if ( payload . stripeProductId ) {
938- result . stripeProductId = payload . stripeProductId ;
946+ result . stripeProductId = payload . stripeProductId . trim ( ) ;
939947 }
940948 if ( payload . stripePriceId ) {
941- result . stripePriceId = payload . stripePriceId ;
949+ result . stripePriceId = payload . stripePriceId . trim ( ) ;
942950 }
943951 return result ;
944952 }
0 commit comments