@go-avro/avro-js 0.0.4-beta.9 → 0.0.5

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.
Files changed (40) hide show
  1. package/dist/auth/AuthManager.d.ts +2 -2
  2. package/dist/client/QueryClient.d.ts +67 -3
  3. package/dist/client/QueryClient.js +28 -1
  4. package/dist/client/core/fetch.js +5 -0
  5. package/dist/client/core/xhr.js +12 -0
  6. package/dist/client/hooks/bills.js +8 -0
  7. package/dist/client/hooks/catalog_items.js +8 -1
  8. package/dist/client/hooks/events.js +14 -17
  9. package/dist/client/hooks/jobs.js +7 -3
  10. package/dist/client/hooks/prepayments.js +60 -1
  11. package/dist/client/hooks/proposal.js +8 -1
  12. package/dist/client/hooks/routes.js +13 -8
  13. package/dist/client/hooks/users.js +11 -0
  14. package/dist/client/hooks/waivers.d.ts +1 -0
  15. package/dist/client/hooks/waivers.js +123 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/types/api/Job.d.ts +31 -24
  19. package/dist/types/api/Job.js +23 -1
  20. package/dist/types/api/LineItem.d.ts +1 -0
  21. package/dist/types/api/LineItem.js +2 -1
  22. package/dist/types/api/Prepayment.d.ts +13 -8
  23. package/dist/types/api/Prepayment.js +7 -1
  24. package/dist/types/api/Route.d.ts +35 -17
  25. package/dist/types/api/Route.js +82 -1
  26. package/dist/types/api/RouteJob.d.ts +14 -9
  27. package/dist/types/api/RouteJob.js +5 -1
  28. package/dist/types/api/ServiceMonth.d.ts +1 -0
  29. package/dist/types/api/Task.d.ts +7 -0
  30. package/dist/types/api/Task.js +37 -1
  31. package/dist/types/api/User.d.ts +1 -0
  32. package/dist/types/api/UserCompanyAssociation.d.ts +1 -0
  33. package/dist/types/api/Waiver.d.ts +9 -0
  34. package/dist/types/api/Waiver.js +1 -0
  35. package/dist/types/api/_Event.d.ts +22 -15
  36. package/dist/types/api/_Event.js +18 -1
  37. package/dist/types/api.d.ts +3 -0
  38. package/dist/types/api.js +1 -0
  39. package/dist/types/cache.d.ts +2 -2
  40. package/package.json +1 -1
@@ -0,0 +1,123 @@
1
+ import { useMutation, useQuery } from '@tanstack/react-query';
2
+ import { AvroQueryClient } from '../../client/QueryClient';
3
+ AvroQueryClient.prototype.useCreateWaiver = function () {
4
+ const queryClient = this.getQueryClient();
5
+ return useMutation({
6
+ mutationFn: async ({ waiverData }) => {
7
+ return this.post(`/company/${this.companyId}/waiver`, JSON.stringify(waiverData), undefined, {
8
+ "Content-Type": "application/json",
9
+ });
10
+ },
11
+ onSettled: () => {
12
+ queryClient.invalidateQueries({ queryKey: ['company'] });
13
+ queryClient.invalidateQueries({ queryKey: ['waivers'] });
14
+ },
15
+ });
16
+ };
17
+ AvroQueryClient.prototype.useGetWaivers = function (body, total, onProgress) {
18
+ return useQuery({
19
+ queryKey: ['waivers', this.companyId, body.amt ?? 50, body.known_ids ?? [], body.unknown_ids ?? [], body.offset ?? 0, body.query ?? "", total ?? "all"],
20
+ queryFn: async () => {
21
+ if (typeof total !== "number") {
22
+ return this.fetchWaivers({ ...body, offset: 0 });
23
+ }
24
+ onProgress?.(0);
25
+ const pageCount = body.amt ? Math.ceil(total / body.amt) + 1 : 1;
26
+ let completed = 0;
27
+ const promises = Array.from({ length: pageCount }, (_, i) => this.fetchWaivers({
28
+ ...body,
29
+ offset: i * (body.amt ?? 1),
30
+ }));
31
+ const trackedPromises = promises.map((promise) => promise.then((result) => {
32
+ completed++;
33
+ const fraction = completed / pageCount;
34
+ onProgress?.(fraction);
35
+ return result;
36
+ }));
37
+ const pages = await Promise.all(trackedPromises);
38
+ const waivers = pages.flat();
39
+ return waivers;
40
+ },
41
+ });
42
+ };
43
+ AvroQueryClient.prototype.useUpdateWaiver = function () {
44
+ const queryClient = this.getQueryClient();
45
+ return useMutation({
46
+ mutationFn: async ({ waiverId, updates }) => {
47
+ return this.put(`/waiver/${waiverId}`, JSON.stringify(updates), undefined, {
48
+ "Content-Type": "application/json",
49
+ });
50
+ },
51
+ onMutate: async ({ waiverId, updates }) => {
52
+ await queryClient.cancelQueries({ queryKey: ['waivers'] });
53
+ await queryClient.cancelQueries({ queryKey: ['waiver', waiverId] });
54
+ const previousWaivers = queryClient.getQueryData(['waivers']);
55
+ const previousWaiver = queryClient.getQueryData(['waiver', waiverId]);
56
+ queryClient.setQueryData(['waiver', waiverId], (oldData) => {
57
+ if (!oldData)
58
+ return oldData;
59
+ return { ...oldData, ...updates };
60
+ });
61
+ queryClient.setQueriesData({ queryKey: ['waivers'] }, (oldData) => {
62
+ if (!oldData)
63
+ return oldData;
64
+ if (oldData.pages) {
65
+ const updatedPages = oldData.pages.map((page) => page.map((waiver) => waiver.id === waiverId ? { ...waiver, ...updates } : waiver));
66
+ return { ...oldData, pages: updatedPages };
67
+ }
68
+ if (Array.isArray(oldData)) {
69
+ return oldData.map((waiver) => waiver.id === waiverId ? { ...waiver, ...updates } : waiver);
70
+ }
71
+ return oldData;
72
+ });
73
+ return { previousWaivers, previousWaiver };
74
+ },
75
+ onError: (_err, variables, context) => {
76
+ const { waiverId } = variables;
77
+ if (context?.previousWaivers) {
78
+ queryClient.setQueryData(['waivers'], context.previousWaivers);
79
+ }
80
+ if (context?.previousWaiver) {
81
+ queryClient.setQueryData(['waiver', waiverId], context.previousWaiver);
82
+ }
83
+ },
84
+ onSettled: (_data, _error, variables) => {
85
+ const { waiverId } = variables;
86
+ queryClient.invalidateQueries({ queryKey: ['waivers'] });
87
+ queryClient.invalidateQueries({ queryKey: ['waiver', waiverId] });
88
+ },
89
+ });
90
+ };
91
+ AvroQueryClient.prototype.useDeleteWaiver = function () {
92
+ const queryClient = this.getQueryClient();
93
+ return useMutation({
94
+ mutationFn: async ({ waiverId }) => {
95
+ return this.delete(`/waiver/${waiverId}`);
96
+ },
97
+ onMutate: async ({ waiverId }) => {
98
+ await queryClient.cancelQueries({ queryKey: ['waivers'] });
99
+ const previousWaivers = queryClient.getQueryData(['waivers']);
100
+ queryClient.setQueriesData({ queryKey: ['waivers'] }, (oldData) => {
101
+ if (!oldData)
102
+ return oldData;
103
+ if (oldData.pages) {
104
+ const updatedPages = oldData.pages.map((page) => page.filter((waiver) => waiver.id !== waiverId));
105
+ return { ...oldData, pages: updatedPages };
106
+ }
107
+ if (Array.isArray(oldData)) {
108
+ return oldData.filter((waiver) => waiver.id !== waiverId);
109
+ }
110
+ return oldData;
111
+ });
112
+ return { previousWaivers };
113
+ },
114
+ onError: (_err, variables, context) => {
115
+ if (context?.previousWaivers) {
116
+ queryClient.setQueryData(['waivers'], context.previousWaivers);
117
+ }
118
+ },
119
+ onSettled: () => {
120
+ queryClient.invalidateQueries({ queryKey: ['waivers'] });
121
+ },
122
+ });
123
+ };
package/dist/index.d.ts CHANGED
@@ -26,6 +26,7 @@ import './client/hooks/labels';
26
26
  import './client/hooks/groups';
27
27
  import './client/hooks/skills';
28
28
  import './client/hooks/proposal';
29
+ import './client/hooks/waivers';
29
30
  export * from './types/api';
30
31
  export * from './types/auth';
31
32
  export * from './types/cache';
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ import './client/hooks/labels';
26
26
  import './client/hooks/groups';
27
27
  import './client/hooks/skills';
28
28
  import './client/hooks/proposal';
29
+ import './client/hooks/waivers';
29
30
  export * from './types/api';
30
31
  export * from './types/auth';
31
32
  export * from './types/cache';
@@ -2,28 +2,35 @@ 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
- export interface Job {
6
- address: string;
7
- company: string;
8
- description: string;
9
- id: string;
10
- is_one_time: boolean;
11
- autostart_radius: number;
12
- latitude: number;
13
- longitude: number;
14
- name: string;
15
- internal_notes: string;
16
- external_notes: string;
17
- priority: number;
18
- tasks: Partial<Task>[];
19
- time_created: number;
20
- time_updated: number | null;
21
- routes: RouteJob[];
22
- subscribers: Subscription[];
23
- manual_emails: string[][];
24
- overdue_time: number;
25
- last_completed_event: _Event | null;
26
- current_event: _Event | null;
27
- labels: string[];
28
- owner: string;
5
+ declare module '../../types/api/Job' {
6
+ interface Job {
7
+ address: string;
8
+ company: string;
9
+ description: string;
10
+ id: string;
11
+ is_one_time: boolean;
12
+ autostart_radius: number;
13
+ latitude: number;
14
+ longitude: number;
15
+ name: string;
16
+ internal_notes: string;
17
+ external_notes: string;
18
+ priority: number;
19
+ tasks: Partial<Task>[];
20
+ time_created: number;
21
+ time_updated: number | null;
22
+ routes: RouteJob[];
23
+ subscribers: Subscription[];
24
+ manual_emails: string[][];
25
+ overdue_time: number;
26
+ last_completed_event: _Event | null;
27
+ current_event: _Event | null;
28
+ labels: string[];
29
+ owner: string;
30
+ }
31
+ }
32
+ export declare class Job {
33
+ constructor(init?: Partial<Job>);
34
+ portionDone: (fallback?: Date | null, routeJob?: RouteJob) => number;
35
+ isDone: (fallback?: Date | null, routeJob?: RouteJob) => boolean;
29
36
  }
@@ -1 +1,23 @@
1
- export {};
1
+ import { Task } from "../../types/api/Task";
2
+ import { RouteJob } from "../../types/api/RouteJob";
3
+ export class Job {
4
+ constructor(init) {
5
+ this.portionDone = (fallback, routeJob) => {
6
+ if (!this.tasks || this.tasks.length === 0) {
7
+ return 0;
8
+ }
9
+ const contextTasks = routeJob ? this.tasks.filter(t => !t.id || routeJob.tasks.includes(t.id)) : this.tasks;
10
+ return contextTasks.filter(t => t.isDone?.(fallback)).length / contextTasks.length;
11
+ };
12
+ this.isDone = (fallback, routeJob) => {
13
+ return this.portionDone(fallback, routeJob) === 1;
14
+ };
15
+ Object.assign(this, init);
16
+ if (init?.tasks) {
17
+ this.tasks = init.tasks.map(t => new Task(t));
18
+ }
19
+ if (init?.routes) {
20
+ this.routes = init.routes.map(r => new RouteJob(r));
21
+ }
22
+ }
23
+ }
@@ -34,6 +34,7 @@ declare module '../../types/api/LineItem' {
34
34
  }
35
35
  }
36
36
  export declare class LineItem {
37
+ constructor(init?: Partial<LineItem>);
37
38
  isPaid: () => boolean;
38
39
  isBilled: () => boolean;
39
40
  isUnbilled: () => boolean;
@@ -15,7 +15,7 @@ export const LineItemType = {
15
15
  PREPAYMENT: "PREPAYMENT",
16
16
  };
17
17
  export class LineItem {
18
- constructor() {
18
+ constructor(init) {
19
19
  this.isPaid = () => {
20
20
  return this.status === LineItemStatus.PAID || this.status === LineItemStatus.PREPAID || this.status === LineItemStatus.EXTERNALLY_PAID;
21
21
  };
@@ -25,5 +25,6 @@ export class LineItem {
25
25
  this.isUnbilled = () => {
26
26
  return !this.isBilled() && !this.isPaid();
27
27
  };
28
+ Object.assign(this, init);
28
29
  }
29
30
  }
@@ -1,10 +1,15 @@
1
1
  import { LineItem } from "../../types/api/LineItem";
2
- export interface Prepayment extends LineItem {
3
- id: string;
4
- task_id: string | null;
5
- line_item_type: "PREPAYMENT";
6
- type: "SERVICE" | "MONTH";
7
- time_updated: number | null;
8
- num_events: number;
9
- num_service_months: number;
2
+ declare module '../../types/api/Prepayment' {
3
+ interface Prepayment extends LineItem {
4
+ id: string;
5
+ task_id: string | null;
6
+ line_item_type: "PREPAYMENT";
7
+ type: "SERVICE" | "MONTH";
8
+ time_updated: number | null;
9
+ num_events: number;
10
+ num_service_months: number;
11
+ }
12
+ }
13
+ export declare class Prepayment extends LineItem {
14
+ constructor(init?: Partial<Prepayment>);
10
15
  }
@@ -1 +1,7 @@
1
- export {};
1
+ import { LineItem } from "../../types/api/LineItem";
2
+ export class Prepayment extends LineItem {
3
+ constructor(init) {
4
+ super(init);
5
+ Object.assign(this, init);
6
+ }
7
+ }
@@ -1,19 +1,37 @@
1
1
  import { RouteJob } from "../../types/api/RouteJob";
2
- export interface Route {
3
- company: string;
4
- id: string;
5
- is_internal: boolean;
6
- jobs: RouteJob[];
7
- name: string;
8
- time_created: number;
9
- time_updated: number | null;
10
- teams: string[];
11
- polyline: string;
12
- is_optimized: boolean;
13
- start_time: number;
14
- end_time: number;
15
- start_latitude: number;
16
- start_longitude: number;
17
- end_latitude: number;
18
- end_longitude: number;
2
+ export declare const FrequencyType: {
3
+ readonly ONCE: "ONCE";
4
+ readonly DAILY: "DAILY";
5
+ readonly WEEKLY: "WEEKLY";
6
+ readonly BIWEEKLY: "BIWEEKLY";
7
+ readonly MONTHLY: "MONTHLY";
8
+ readonly YEARLY: "YEARLY";
9
+ };
10
+ export type FrequencyType = typeof FrequencyType[keyof typeof FrequencyType];
11
+ declare module '../../types/api/Route' {
12
+ interface Route {
13
+ company: string;
14
+ id: string;
15
+ is_internal: boolean;
16
+ jobs: RouteJob[];
17
+ name: string;
18
+ time_created: number;
19
+ time_updated: number | null;
20
+ teams: string[];
21
+ polyline: string;
22
+ is_optimized: boolean;
23
+ start_time: number;
24
+ end_time: number;
25
+ start_latitude: number;
26
+ start_longitude: number;
27
+ end_latitude: number;
28
+ end_longitude: number;
29
+ frequency: typeof FrequencyType[keyof typeof FrequencyType];
30
+ }
31
+ }
32
+ export declare class Route {
33
+ constructor(init?: Partial<Route>);
34
+ getNextOccurrences: (count?: number) => (Date | null)[];
35
+ getNextOccurrence: (after?: Date) => Date | null;
36
+ getIndicatorExpiration: () => Date;
19
37
  }
@@ -1 +1,82 @@
1
- export {};
1
+ import { RouteJob } from "../../types/api/RouteJob";
2
+ export const FrequencyType = {
3
+ ONCE: "ONCE",
4
+ DAILY: "DAILY",
5
+ WEEKLY: "WEEKLY",
6
+ BIWEEKLY: "BIWEEKLY",
7
+ MONTHLY: "MONTHLY",
8
+ YEARLY: "YEARLY",
9
+ };
10
+ export class Route {
11
+ constructor(init) {
12
+ this.getNextOccurrences = (count = 1) => {
13
+ let next_occurrences = [];
14
+ for (let i = 0; i < count; i++) {
15
+ next_occurrences.push(this.getNextOccurrence(next_occurrences.length > 0 ? next_occurrences[next_occurrences.length - 1] ?? new Date() : new Date()));
16
+ }
17
+ return next_occurrences;
18
+ };
19
+ this.getNextOccurrence = (after = new Date()) => {
20
+ let next_occurrence = new Date(this.start_time * 1000);
21
+ while (next_occurrence <= after) {
22
+ switch (this.frequency) {
23
+ case FrequencyType.ONCE:
24
+ return null;
25
+ case FrequencyType.DAILY:
26
+ next_occurrence.setDate(next_occurrence.getDate() + 1);
27
+ break;
28
+ case FrequencyType.WEEKLY:
29
+ next_occurrence.setDate(next_occurrence.getDate() + 7);
30
+ break;
31
+ case FrequencyType.BIWEEKLY:
32
+ next_occurrence.setDate(next_occurrence.getDate() + 14);
33
+ break;
34
+ case FrequencyType.MONTHLY:
35
+ next_occurrence.setMonth(next_occurrence.getMonth() + 1);
36
+ break;
37
+ case FrequencyType.YEARLY:
38
+ next_occurrence.setFullYear(next_occurrence.getFullYear() + 1);
39
+ break;
40
+ }
41
+ }
42
+ return next_occurrence;
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
+ Object.assign(this, init);
78
+ if (init?.jobs) {
79
+ this.jobs = init.jobs.map(j => new RouteJob(j));
80
+ }
81
+ }
82
+ }
@@ -1,10 +1,15 @@
1
- export interface RouteJob {
2
- time_created: number;
3
- route_id: string;
4
- job_id: string;
5
- id: string;
6
- order: number;
7
- estimated_arrival_time: number;
8
- scheduled_arrival_time: number;
9
- tasks: string[];
1
+ declare module '../../types/api/RouteJob' {
2
+ interface RouteJob {
3
+ time_created: number;
4
+ route_id: string;
5
+ job_id: string;
6
+ id: string;
7
+ order: number;
8
+ estimated_arrival_time: number;
9
+ scheduled_arrival_time: number;
10
+ tasks: string[];
11
+ }
12
+ }
13
+ export declare class RouteJob {
14
+ constructor(init?: Partial<RouteJob>);
10
15
  }
@@ -1 +1,5 @@
1
- export {};
1
+ export class RouteJob {
2
+ constructor(init) {
3
+ Object.assign(this, init);
4
+ }
5
+ }
@@ -3,5 +3,6 @@ export interface ServiceMonth extends LineItem {
3
3
  line_item_type: "SERVICE_MONTH";
4
4
  bill_id: string | null;
5
5
  tasks: string[];
6
+ task_names: string[];
6
7
  time_updated: number | null;
7
8
  }
@@ -1,5 +1,6 @@
1
1
  import { UserCompanyAssociation } from "../../types/api/UserCompanyAssociation";
2
2
  import { Prepayment } from "../../types/api/Prepayment";
3
+ import { PaymentOption } from "../../types/api/PaymentOption";
3
4
  import { _Event } from "../../types/api/_Event";
4
5
  export declare const TaskStatus: {
5
6
  readonly PENDING_CUSTOMER: "PENDING_CUSTOMER";
@@ -15,6 +16,7 @@ declare module '../../types/api/Task' {
15
16
  interface Task {
16
17
  enforce_proof_amount: boolean;
17
18
  events: _Event[];
19
+ payment_options: PaymentOption[];
18
20
  frequency: number;
19
21
  id: string;
20
22
  job_id: string;
@@ -35,6 +37,7 @@ declare module '../../types/api/Task' {
35
37
  skills: string[];
36
38
  service: number;
37
39
  bill_mode: "MONTH" | "SERVICE" | "NONE";
40
+ autobill: boolean;
38
41
  price: number;
39
42
  services_remaining: number;
40
43
  activate_on: number | null;
@@ -47,5 +50,9 @@ declare module '../../types/api/Task' {
47
50
  }
48
51
  }
49
52
  export declare class Task {
53
+ constructor(init?: Partial<Task>);
50
54
  computeNextTaskState: (isCustomer: boolean, action: "accept" | "modify" | "reject") => TaskStatus;
55
+ getPrepaidEventsRemaining: () => number;
56
+ getPrepaidMonthsRemaining: () => number;
57
+ isDone: (fallback?: Date | null) => boolean | 1;
51
58
  }
@@ -1,3 +1,4 @@
1
+ import { Prepayment } from "../../types/api/Prepayment";
1
2
  export const TaskStatus = {
2
3
  PENDING_CUSTOMER: "PENDING_CUSTOMER",
3
4
  PENDING_COMPANY: "PENDING_COMPANY",
@@ -8,7 +9,7 @@ export const TaskStatus = {
8
9
  PENDING_ACTIVATION: "PENDING_ACTIVATION"
9
10
  };
10
11
  export class Task {
11
- constructor() {
12
+ constructor(init) {
12
13
  this.computeNextTaskState = (isCustomer, action) => {
13
14
  if (action === "accept") {
14
15
  if (this.status === TaskStatus.PENDING_CUSTOMER || this.status === TaskStatus.PENDING_COMPANY) {
@@ -34,5 +35,40 @@ export class Task {
34
35
  }
35
36
  return this.status;
36
37
  };
38
+ this.getPrepaidEventsRemaining = () => {
39
+ return this.prepayments.reduce((acc, prepayment) => {
40
+ if (prepayment.isPaid()) {
41
+ return acc + prepayment.amount - prepayment.num_events;
42
+ }
43
+ return acc;
44
+ }, 0);
45
+ };
46
+ this.getPrepaidMonthsRemaining = () => {
47
+ return this.prepayments.reduce((acc, prepayment) => {
48
+ if (prepayment.isPaid()) {
49
+ return acc + prepayment.amount - prepayment.num_service_months;
50
+ }
51
+ return acc;
52
+ }, 0);
53
+ };
54
+ this.isDone = (fallback) => {
55
+ if (!this.status || this.status !== TaskStatus.ACTIVE) {
56
+ return 1;
57
+ }
58
+ if (this.frequency > 0) {
59
+ return this.overdue_time <= 0;
60
+ }
61
+ else if (fallback) {
62
+ // If frequency is 0, use fallback
63
+ return new Date((this.last_completed_event?.time_ended ?? 0) * 1000) > (fallback);
64
+ }
65
+ else {
66
+ return this.last_completed_event?.time_ended ? true : false;
67
+ }
68
+ };
69
+ Object.assign(this, init);
70
+ if (init?.prepayments) {
71
+ this.prepayments = init.prepayments.map(p => new Prepayment(p));
72
+ }
37
73
  }
38
74
  }
@@ -7,6 +7,7 @@ export interface User {
7
7
  username: string;
8
8
  first_name: string;
9
9
  last_name: string;
10
+ email_verified: boolean;
10
11
  verified: boolean;
11
12
  email: string | null;
12
13
  phone_number: string | null;
@@ -1,4 +1,5 @@
1
1
  import { User } from "../../types/api/User";
2
+ import { Location } from "../../types/api";
2
3
  export declare const Permission: {
3
4
  readonly CAN_WRITE_COMPANY: "can_write_company";
4
5
  readonly CAN_READ_GROUPS: "can_read_groups";
@@ -0,0 +1,9 @@
1
+ export interface Waiver {
2
+ id: string;
3
+ name: string;
4
+ contents: string;
5
+ signed_users: string[];
6
+ company_id: string;
7
+ time_created: number | null;
8
+ time_updated: number | null;
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,19 +1,26 @@
1
1
  import { LineItem } from "../../types/api/LineItem";
2
2
  import { AdditionalCharge } from "../../types/api/AdditionalCharge";
3
3
  import { UserEvent } from "../../types/api/UserEvent";
4
- export interface _Event extends LineItem {
5
- breaks: string[];
6
- line_item_type: "EVENT";
7
- internal_notes: string;
8
- external_notes: string;
9
- proofs: string[];
10
- tasks: string[];
11
- time_ended: number | null;
12
- time_started: number;
13
- time_updated: number | null;
14
- bill_id: string;
15
- billed_amount: number;
16
- additional_charges: AdditionalCharge[];
17
- users: UserEvent[];
18
- autostart: boolean;
4
+ declare module '../../types/api/_Event' {
5
+ interface _Event extends LineItem {
6
+ breaks: string[];
7
+ line_item_type: "EVENT";
8
+ internal_notes: string;
9
+ external_notes: string;
10
+ proofs: string[];
11
+ tasks: string[];
12
+ task_names: string[];
13
+ time_ended: number | null;
14
+ time_started: number;
15
+ time_updated: number | null;
16
+ bill_id: string;
17
+ billed_amount: number;
18
+ additional_charges: AdditionalCharge[];
19
+ users: UserEvent[];
20
+ autostart: boolean;
21
+ }
22
+ }
23
+ export declare class _Event extends LineItem {
24
+ constructor(init?: Partial<_Event>);
25
+ getCost: () => number;
19
26
  }
@@ -1 +1,18 @@
1
- export {};
1
+ import { LineItem } from "../../types/api/LineItem";
2
+ export class _Event extends LineItem {
3
+ constructor(init) {
4
+ super(init);
5
+ this.getCost = () => {
6
+ const additionalChargesCost = this.additional_charges.reduce((acc, charge) => acc + (charge.cost ?? 0) * (charge.amount ?? 0), 0);
7
+ return (this.cost * this.amount) + additionalChargesCost;
8
+ };
9
+ Object.assign(this, init);
10
+ this.breaks = init?.breaks ?? [];
11
+ this.proofs = init?.proofs ?? [];
12
+ this.tasks = init?.tasks ?? [];
13
+ this.task_names = init?.task_names ?? [];
14
+ this.additional_charges = init?.additional_charges ?? [];
15
+ this.users = init?.users ?? [];
16
+ this.autostart = init?.autostart ?? false;
17
+ }
18
+ }