Bin
2025-12-17 1d710f844b65d9bfdf986a71a3b924cd70598a41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { getParent, types } from "mobx-state-tree";
import Utilities from "../utils";
 
/**
 * Model for HTTP Basic Authorization
 */
const AuthStore = types.model({
  enable: types.optional(types.boolean, false),
  username: types.string,
  password: types.string,
  to: types.string,
});
 
/**
 * Task Store
 */
const TaskStore = types
  .model("Task", {
    id: types.maybeNull(types.number),
    load: types.optional(types.boolean, false),
    auth: types.maybeNull(AuthStore),
    agreement: types.maybeNull(types.number),
    /**
     * Data of task, may contain an object but in App Store will be transformed into string
     * MST doesn't support processing of dynamic objects with unkown keys value
     */
    data: types.maybeNull(types.string),
    queue: types.optional(types.maybeNull(types.string), null),
    /**
     * Whether this task can be skipped. Defaults to true if undefined.
     */
    allow_skip: types.optional(types.maybeNull(types.boolean), true),
  })
  .views((self) => ({
    get app() {
      return getParent(self);
    },
 
    /**
     * Return JSON with task data
     * @returns {object}
     */
    get dataObj() {
      if (Utilities.Checkers.isStringJSON(self.data)) {
        return JSON.parse(self.data);
      }
      if (typeof self.data === "object") {
        return self.data;
      }
      return null;
    },
  }));
 
export default TaskStore;