workflow.js 675 B

12345678910111213141516171819202122232425262728293031
  1. import { Model } from '@vuex-orm/core';
  2. import { nanoid } from 'nanoid';
  3. import Task from './task';
  4. class Workflow extends Model {
  5. static entity = 'workflows';
  6. static primaryKey = 'id';
  7. static fields() {
  8. return {
  9. id: this.uid(() => nanoid()),
  10. name: this.string(''),
  11. icon: this.string('riGlobalLine'),
  12. data: this.attr(null),
  13. lastRunAt: this.number(),
  14. createdAt: this.number(),
  15. tasks: this.hasMany(Task, 'workflowId'),
  16. };
  17. }
  18. static async insert(payload) {
  19. const res = await super.insert(payload);
  20. await this.store().dispatch('saveToStorage', 'workflows');
  21. return res;
  22. }
  23. }
  24. export default Workflow;