@go-avro/avro-js 0.0.11 → 0.0.13-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import { Task } from "../../types/api/Task";
2
2
  import { _Event } from "../../types/api/_Event";
3
3
  import { RouteJob } from "../../types/api/RouteJob";
4
4
  import { Subscription } from "../../types/api/Subscription";
5
+ import { Route } from "../../types/api/Route";
5
6
  declare module '../../types/api/Job' {
6
7
  interface Job {
7
8
  address: string;
@@ -34,6 +35,6 @@ export declare class Job {
34
35
  getOverdueLabel: () => string;
35
36
  getStatus(): "PENDING_CUSTOMER" | "PENDING_COMPANY" | "ACTIVE" | "ARCHIVED" | "DRAFT" | "PENDING_PAYMENT" | "PENDING_ACTIVATION";
36
37
  getStatusLabel(): "Active" | "Draft" | "Archived" | "Pending Activation" | "Customer Approval" | "Company Approval" | "Awaiting Payment";
37
- portionDone: (fallback?: Date | null, routeJob?: RouteJob) => number;
38
- isDone: (fallback?: Date | null, routeJob?: RouteJob) => boolean;
38
+ portionDone: (route: Route) => number;
39
+ isDone: (route: Route) => boolean;
39
40
  }
@@ -21,15 +21,22 @@ export class Job {
21
21
  return `${Math.floor(maxOverdueTime / 86400)}d overdue`;
22
22
  }
23
23
  };
24
- this.portionDone = (fallback, routeJob) => {
24
+ this.portionDone = (route) => {
25
25
  if (!this.tasks || this.tasks.length === 0) {
26
26
  return 0;
27
27
  }
28
- const contextTasks = routeJob ? this.tasks.filter(t => !t.id || routeJob.tasks.includes(t.id)) : this.tasks;
29
- return contextTasks.filter(t => t.isDone?.(fallback)).length / contextTasks.length;
28
+ const routeJob = this.routes.find(r => r.job_id === this.id);
29
+ if (!routeJob) {
30
+ return 0;
31
+ }
32
+ const contextTasks = this.tasks.filter(t => !t.id || routeJob.tasks.includes(t.id));
33
+ if (contextTasks.length === 0) {
34
+ return 0;
35
+ }
36
+ return contextTasks.filter(t => t.isDone?.(route)).length / contextTasks.length;
30
37
  };
31
- this.isDone = (fallback, routeJob) => {
32
- return this.portionDone(fallback, routeJob) === 1;
38
+ this.isDone = (route) => {
39
+ return this.portionDone(route) === 1;
33
40
  };
34
41
  Object.assign(this, init);
35
42
  if (init?.tasks) {
@@ -33,5 +33,4 @@ export declare class Route {
33
33
  constructor(init?: Partial<Route>);
34
34
  getNextOccurrences: (count?: number) => (Date | null)[];
35
35
  getNextOccurrence: (after?: Date) => Date | null;
36
- getIndicatorExpiration: () => Date;
37
36
  }
@@ -41,39 +41,6 @@ export class Route {
41
41
  }
42
42
  return next_occurrence;
43
43
  };
44
- this.getIndicatorExpiration = () => {
45
- const start_time = new Date(this.start_time * 1000);
46
- if (this.frequency === FrequencyType.ONCE) {
47
- return start_time;
48
- }
49
- // if the route is currently active, return the start time as the indicator expiration
50
- if (Date.now() > start_time.getTime()) {
51
- return start_time;
52
- }
53
- // else compute the previous occurrence and return that as the indicator expiration
54
- const prev = new Date(start_time);
55
- switch (this.frequency) {
56
- case FrequencyType.DAILY:
57
- prev.setHours(prev.getHours() - 4);
58
- prev.setDate(prev.getDate() - 1);
59
- break;
60
- case FrequencyType.WEEKLY:
61
- prev.setDate(prev.getDate() - 8);
62
- break;
63
- case FrequencyType.BIWEEKLY:
64
- prev.setDate(prev.getDate() - 15);
65
- break;
66
- case FrequencyType.MONTHLY:
67
- prev.setDate(prev.getDate() - 1);
68
- prev.setMonth(prev.getMonth() - 1);
69
- break;
70
- case FrequencyType.YEARLY:
71
- prev.setDate(prev.getDate() - 1);
72
- prev.setFullYear(prev.getFullYear() - 1);
73
- break;
74
- }
75
- return prev;
76
- };
77
44
  Object.assign(this, init);
78
45
  if (init?.jobs) {
79
46
  this.jobs = init.jobs.map(j => new RouteJob(j));
@@ -2,6 +2,7 @@ import { UserCompanyAssociation } from "../../types/api/UserCompanyAssociation";
2
2
  import { Prepayment } from "../../types/api/Prepayment";
3
3
  import { PaymentOption } from "../../types/api/PaymentOption";
4
4
  import { _Event } from "../../types/api/_Event";
5
+ import { Route } from "../../types/api/Route";
5
6
  export declare const TaskStatus: {
6
7
  readonly PENDING_CUSTOMER: "PENDING_CUSTOMER";
7
8
  readonly PENDING_COMPANY: "PENDING_COMPANY";
@@ -58,5 +59,5 @@ export declare class Task {
58
59
  computeNextTaskState: (isCustomer: boolean, action: "accept" | "modify" | "reject") => TaskStatus;
59
60
  getPrepaidEventsRemaining: () => number;
60
61
  getPrepaidMonthsRemaining: () => number;
61
- isDone: (fallback?: Date | null) => boolean | 1;
62
+ isDone: (route: Route) => boolean;
62
63
  }
@@ -95,16 +95,12 @@ export class Task {
95
95
  return acc;
96
96
  }, 0);
97
97
  };
98
- this.isDone = (fallback) => {
98
+ this.isDone = (route) => {
99
99
  if (!this.status || this.status !== TaskStatus.ACTIVE) {
100
- return 1;
100
+ return true;
101
101
  }
102
102
  if (this.frequency > 0) {
103
- return this.overdue_time <= 0;
104
- }
105
- else if (fallback) {
106
- // If frequency is 0, use fallback
107
- return new Date((this.last_completed_event?.time_ended ?? 0) * 1000) > (fallback);
103
+ return (this.last_completed_event?.time_ended ?? 0) > route.start_time;
108
104
  }
109
105
  else {
110
106
  return this.last_completed_event?.time_ended ? true : false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.11",
3
+ "version": "0.0.13-beta.0",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",