log.js 974 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Model } from '@vuex-orm/core';
  2. import { nanoid } from 'nanoid';
  3. class Log extends Model {
  4. static entity = 'logs';
  5. static fields() {
  6. return {
  7. id: this.uid(() => nanoid()),
  8. data: this.attr({}),
  9. name: this.string(''),
  10. history: this.attr([]),
  11. endedAt: this.number(0),
  12. message: this.string(''),
  13. startedAt: this.number(0),
  14. workflowId: this.attr(null),
  15. collectionId: this.attr(null),
  16. status: this.string('success'),
  17. isChildLog: this.boolean(false),
  18. collectionLogId: this.attr(null),
  19. icon: this.string('riGlobalLine'),
  20. isInCollection: this.boolean(false),
  21. };
  22. }
  23. static afterDelete(item) {
  24. const logs = this.query().where('collectionLogId', item.id).get();
  25. if (logs.length !== 0) {
  26. Promise.allSettled(logs.map(({ id }) => this.delete(id))).then(() => {
  27. this.store().dispatch('saveToStorage', 'workflows');
  28. });
  29. }
  30. }
  31. }
  32. export default Log;