ApiResource.ts 512 B

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