objection.js: type must be JSONType or JSONType[]: date-time
After update to the 3.0.0 I got this validation error.
static get jsonSchema() {
return {
type: "object",
required: [
"first_name",
"last_name",
"email",
"phone_number",
],
properties: {
first_name: { type: "string" },
last_name: { type: "string" },
last_change: { type: "date-time" },
email: { type: "email" },
phone_number: { type: "string" },
last_try: { type: "date-time" },
last_logged: { type: "date-time" },
},
};
}
const now = new Date(Date.now());
const lastLogged = response.isValid ? { last_logged: now } : {};
const toPatch = {
last_try: now,
...lastLogged,
};
await user.$query().patch(toPatch);
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15
Commits related to this issue
- Adding ajv-formats package #2142, #2146, #2147, #2170 — committed to TigerC10/objection.js by TigerC10 2 years ago
- Include ajv-formats by default Closes #2218, #2142, #2146, #2147, #2170 — committed to Vincit/objection.js by lehni a year ago
- Include ajv-formats by default Closes #2218, #2142, #2146, #2147, #2170 — committed to Vincit/objection.js by lehni a year ago
- Include ajv-formats by default (#2453) Closes #2218, #2142, #2146, #2147, #2170 — committed to Vincit/objection.js by lehni a year ago
date-timeis not a valid JSON schema type. It’s been working before by accident. I thinkAjvhas added more validation in recent versions.emailis also not a valid type.Valid types are JSON types
string,number,boolean,object,arrayandnull(and alsointeger). You can use theformatfield to implement additional format checks like date-time or email. See what formatsAjvsupports by default. You may need to add a library likeajv-formatsto make those work.