| 12345678910111213141516171819202122232425262728293031323334353637 |
- import {Model} from "pinia-orm";
- /**
- * Base class for resources that can be fetched from the API
- */
- export class ApiResource extends Model {
- private _model: typeof ApiResource | undefined = undefined;
- public getModel() {
- return this._model
- }
- public setModel(model: typeof ApiResource) {
- this._model = model
- }
- /**
- * Fix the 'Cannot stringify arbitrary non-POJOs' warning, meaning server can not parse the store
- *
- * @see https://github.com/vuex-orm/vuex-orm/issues/255#issuecomment-876378684
- */
- toJSON () {
- return { ...this }
- }
- /**
- * Is it a newly created entity?
- *
- * If it is, it means this entity does not exist in the data source and that it has a temporary id
- */
- public isNew(): boolean {
- return !this.id || (typeof this.id === 'string' && this.id.slice(0, 3) === 'tmp')
- }
- }
- export default ApiResource
|