mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 01:47:13 +00:00 
			
		
		
		
	Apply same date parsing logic to all sql databases on save
This commit is contained in:
		
							parent
							
								
									60d04d26eb
								
							
						
					
					
						commit
						d1ee6a662e
					
				| @ -418,12 +418,10 @@ module.exports = ({ models, target, plugin = false }, ctx) => { | |||||||
|     try { |     try { | ||||||
|       // External function to map key that has been updated with `columnName`
 |       // External function to map key that has been updated with `columnName`
 | ||||||
|       const mapper = (params = {}) => { |       const mapper = (params = {}) => { | ||||||
|         if (definition.client === 'mysql' || definition.client === 'sqlite3') { |  | ||||||
|         Object.keys(params).map(key => { |         Object.keys(params).map(key => { | ||||||
|           const attr = definition.attributes[key] || {}; |           const attr = definition.attributes[key] || {}; | ||||||
|             params[key] = castValueFromType(attr.type, params[key]); |           params[key] = castValueFromType(attr.type, params[key], definition); | ||||||
|         }); |         }); | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         return _.mapKeys(params, (value, key) => { |         return _.mapKeys(params, (value, key) => { | ||||||
|           const attr = definition.attributes[key] || {}; |           const attr = definition.attributes[key] || {}; | ||||||
| @ -869,11 +867,14 @@ module.exports = ({ models, target, plugin = false }, ctx) => { | |||||||
|   return Promise.all(updates); |   return Promise.all(updates); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const castValueFromType = (type, value) => { | const castValueFromType = (type, value, definition) => { | ||||||
|   switch (type) { |   switch (type) { | ||||||
|     case 'json': { |     case 'json': { | ||||||
|  |       if (definition.client === 'mysql' || definition.client === 'sqlite3') { | ||||||
|         return JSON.stringify(value); |         return JSON.stringify(value); | ||||||
|       } |       } | ||||||
|  |       return value; | ||||||
|  |     } | ||||||
|     // TODO: handle real date format 1970-01-01
 |     // TODO: handle real date format 1970-01-01
 | ||||||
|     case 'date': |     case 'date': | ||||||
|     case 'datetime': { |     case 'datetime': { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Alexandre Bodin
						Alexandre Bodin