File tree Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Expand file tree Collapse file tree 3 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -896,8 +896,10 @@ let key = {
896896// Use the 'delete' method of MyEntity to delete the item from DynamoDB
897897let result = await MyEntity .delete (
898898 key,
899- condition: { attr: ' date_modified' lt: ' 2020-01-01' },
900- returnValues: ' all_old'
899+ {
900+ condition: { attr: ' date_modified' lt: ' 2020-01-01' },
901+ returnValues: ' all_old'
902+ }
901903)
902904` ` `
903905
Original file line number Diff line number Diff line change @@ -88,6 +88,17 @@ const TestEntity4 = new Entity({
8888 table : TestTable3
8989} ) ;
9090
91+ const TestEntity5 = new Entity ( {
92+ name : 'TestEntity5' ,
93+ autoExecute : false ,
94+ attributes : {
95+ pk : { partitionKey : true } ,
96+ test_required_boolean : { type : 'boolean' , required : true } ,
97+ test_required_number : { type : 'number' , required : true } ,
98+ } ,
99+ table : TestTable2
100+ } )
101+
91102describe ( 'put' , ( ) => {
92103
93104 it ( 'creates basic item' , ( ) => {
@@ -291,6 +302,17 @@ describe('put',()=>{
291302 } ) ) . toThrow ( `'test' is a required field` )
292303 } )
293304
305+ it ( 'puts 0 and false to required fields' , ( ) => {
306+ let { Item } = TestEntity5 . putParams ( {
307+ pk : 'test-pk' ,
308+ test_required_boolean : false ,
309+ test_required_number : 0
310+ } )
311+
312+ expect ( Item . test_required_boolean ) . toBe ( false )
313+ expect ( Item . test_required_number ) . toBe ( 0 )
314+ } )
315+
294316 it ( 'formats a batch put response' , async ( ) => {
295317 let result = TestEntity . putBatch ( { pk : 'x' , sk : 'y' } )
296318
Original file line number Diff line number Diff line change @@ -801,7 +801,7 @@ class Entity<
801801 && ( ! mapping . link || ( mapping . link && mapping . save === true ) )
802802 ) {
803803 // If a number or a set and adding
804- if ( [ 'number' , 'set' ] . includes ( mapping . type ) && data [ field ] ?. $add ) {
804+ if ( [ 'number' , 'set' ] . includes ( mapping . type ) && ( data [ field ] ?. $add !== undefined && data [ field ] ?. $add !== null ) ) {
805805 ADD . push ( `#${ field } :${ field } ` )
806806 values [ `:${ field } ` ] = validateType ( mapping , field , data [ field ] . $add )
807807 // Add field to names
@@ -1109,8 +1109,7 @@ class Entity<
11091109
11101110
11111111 // Check for required fields
1112- Object . keys ( required ) . forEach ( field =>
1113- required [ field ] !== undefined && ! data [ field ]
1112+ Object . keys ( required ) . forEach ( field => required [ field ] !== undefined && ( data [ field ] === undefined || data [ field ] === null )
11141113 && error ( `'${ field } ${ this . schema . attributes [ field ] . alias ? `/${ this . schema . attributes [ field ] . alias } ` : '' } ' is a required field` )
11151114 ) // end required field check
11161115
You can’t perform that action at this time.
0 commit comments