ApiResource.ts 464 B

123456789101112131415161718
  1. import {Model} from "pinia-orm";
  2. /**
  3. * Base class for resources that can be fetched from the API
  4. */
  5. export class ApiResource extends Model {
  6. /**
  7. * Is it a newly created entity?
  8. *
  9. * If it is, it means this entity does not exist in the data source and that it has a temporary id
  10. */
  11. public isNew(): boolean {
  12. return !this.id || (typeof this.id === 'string' && this.id.slice(0, 3) === 'tmp')
  13. }
  14. }
  15. export default ApiResource