question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Updating a date property fails on the validation

See original GitHub issue

Hello First thanks for the project !

I have a basic book node model :

module.exports = {
  ISBN: {
    type: 'int',
    primary: true
  },
  title: {
    type: 'string'
  },
  author: {
    type: 'string'
  },
  publication: {
    type: 'date'
  },
  createdAt: {
    type: 'datetime',
    default: () => new Date()
  }
}

I would like to update the publication property a specific book via API like this :

  neo4j.first('Books', 'ISBN', parseInt(req.body.ISBN)).then( book => {
    if (!book) throw({ status: 'error', message: 'Missing or wrong required fields'});
		return book.update({
      title: req.body.title,
      author: req.body.author,
      publication: new Date(req.body.publication),
		})
	})
	.then( book => {
		return res.status(200).json({ status: 'success', message: 'Book updated', data: {book: book.properties()} });
	})
	.catch((err) => { console.log(err) ; next(err) })

I got in the catch the following error

ValidationError: ERROR_VALIDATION
    at /home/chris/bookApp/node_modules/neode/build/Services/Validator.js:297:23
    at internals.Object._validateWithOptions (/home/chris/bookApp/node_modules/@hapi/joi/lib/types/any/index.js:766:20)
    at module.exports.internals.Any.root.validate (/home/chris/bookApp/node_modules/@hapi/joi/lib/index.js:145:23)
    at /home/chris/bookApp/node_modules/neode/build/Services/Validator.js:295:21
    at new Promise (<anonymous>)
    at Validator (/home/chris/bookApp/node_modules/neode/build/Services/Validator.js:294:10)
    at UpdateNode (/home/chris/bookApp/node_modules/neode/build/Services/UpdateNode.js:14:36)
    at Node.update (/home/chris/bookApp/node_modules/neode/build/Node.js:280:41)
    at /home/chris/bookApp/api/books/books.controller.js:173:15
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  details: [
    {
      message: '"publication" must be an instance of "Date"',
      path: [Array],
      type: 'object.type',
      context: [Object]
    }
  ],
  input: {
    title: 'new title',
    author: 'new author',
    publication: 2020-01-01T00:00:00.000Z
  },
  _joiError: Error [ValidationError]: child "publication" fails because ["publication" must be an instance of "Date"]
....

As you can see the date seems to be correct but i can’t get what the error could be I tried the type datetime and then i have an error about publication not being an instance of Object

Any advice is welcome

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pihomeservercommented, Mar 13, 2020

My full apologizes i did not saw the upgrade requirement. Now it works ! Thank you

0reactions
adam-cowleycommented, Mar 13, 2020

Has the version definitely updated? Try npm i --save neode@^0.4.3

I’ve just run this code and get the output in the console:

https://gist.github.com/adam-cowley/a5995e72438095b06dec03eddfbd47c1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate property before updating, don't update if validation fails
Hey everyone, I was wondering if it's possible to validate a property before it's being updated, and if the validation fails the property...
Read more >
Date field keeps giving validation error even though submitted ...
I'm having a strange problem with a date field on a webform. I have it set, in the Element Settings, to a minimum...
Read more >
Property startDate must be a valid Date error in Grails
If EmpRef is argument of a method, it is automatically binded on request. This causes both startDate and endDate to have error.
Read more >
Property validation - MikroORM
Property validation. MikroORM will validate your properties before actual persisting happens. It will try to fix wrong data types for you automatically.
Read more >
Validation on SysEffectiveDate constantly fails with valid ...
Hello everyone, I am currently facing a problem when trying to update an effective dated View Object. Any help or advice would be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found