Skip to content

Instantly share code, notes, and snippets.

@sdevore
Forked from JamesRagonesi/Comment.js
Created November 27, 2019 21:23
Show Gist options
  • Save sdevore/7e5887a83fbd7f0253ef2cea1af9aae8 to your computer and use it in GitHub Desktop.
Save sdevore/7e5887a83fbd7f0253ef2cea1af9aae8 to your computer and use it in GitHub Desktop.
Reusable Forms - Model
import { Model } from "@vuex-orm/core";
import { required, maxLength, minLength } from "vuelidate/lib/validators";
export default class Comment extends Model {
static fields() {
return {
id: this.attr(null),
text: this.string(""),
};
}
// Keep validations within the model
static get validations() {
return {
form: {
text: { required, maxLength: maxLength(24), minLength: minLength(6) },
}
};
}
// Call to send new POST request
toCreatePayload() {
return {
text: this.text,
};
}
// Call to send new PUT request
toUpdatePayload() {
return {
...this.toCreatePayload(),
id: this.$id
};
}
}
Comment.entity = "comments";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment