Skip to content

Commit

Permalink
feat: change line_state to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
kingofday committed Jan 18, 2025
1 parent 84443b6 commit b1909a2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 49 deletions.
99 changes: 58 additions & 41 deletions src/domain/Profile.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import Line, { LineResponse } from './Line';
import ForwardOption, { FORWARD_KEYS } from './ForwardOption';
import newFrom from '../utils/new-from';
import SipLine from './SipLine';
import Incall, { GenericIncall } from './Incall';
import Line, { LineResponse } from "./Line";

Check failure on line 1 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 1 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
import ForwardOption, { FORWARD_KEYS } from "./ForwardOption";

Check failure on line 2 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 2 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
import newFrom from "../utils/new-from";

Check failure on line 3 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 3 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
import SipLine from "./SipLine";

Check failure on line 4 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 4 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
import Incall, { GenericIncall } from "./Incall";

Check failure on line 5 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 5 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote

export const STATE = {
AVAILABLE: 'available',
UNAVAILABLE: 'unavailable',
INVISIBLE: 'invisible',
DISCONNECTED: 'disconnected',
AWAY: 'away',
};
export const LINE_STATE = {
AVAILABLE: 'available',
HOLDING: 'holding',
RINGING: 'ringing',
TALKING: 'talking',
UNAVAILABLE: 'unavailable',
PROGRESSING: 'progressing',
AVAILABLE: "available",

Check failure on line 8 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 8 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
UNAVAILABLE: "unavailable",

Check failure on line 9 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 9 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
INVISIBLE: "invisible",

Check failure on line 10 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 10 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
DISCONNECTED: "disconnected",

Check failure on line 11 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 11 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
AWAY: "away",

Check failure on line 12 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Strings must use singlequote

Check failure on line 12 in src/domain/Profile.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Strings must use singlequote
};
export enum LINE_STATE {
AVAILABLE = "available",
HOLDING = "holding",
RINGING = "ringing",
TALKING = "talking",
UNAVAILABLE = "unavailable",
PROGRESSING = "progressing",
}

type ProfileResponse = {
groups: Array<{
Expand Down Expand Up @@ -141,48 +141,64 @@ export default class Profile {

ringSeconds: number | null | undefined;

voicemail: {
id: number;
name: string;
} | null | undefined;
voicemail:
| {
id: number;
name: string;
}
| null
| undefined;

status: string;

subscriptionType: number | null | undefined;

agent: {
firstname: string;
id: number;
lastname: string;
number: string;
} | null | undefined;
agent:
| {
firstname: string;
id: number;
lastname: string;
number: string;
}
| null
| undefined;

switchboards: Array<any>;

callPickupTargetUsers: Array<{
firstname: string;
lastname: string;
uuid: string;
}> | null | undefined;
callPickupTargetUsers:
| Array<{
firstname: string;
lastname: string;
uuid: string;
}>
| null
| undefined;

static parse(plain: ProfileResponse): Profile {
return new Profile({
id: plain.uuid,
firstName: plain.firstName || plain.firstname || '',
lastName: plain.lastName || plain.lastname || '',
firstName: plain.firstName || plain.firstname || "",
lastName: plain.lastName || plain.lastname || "",
email: plain.email,
lines: plain.lines.map(line => Line.parse(line)),
lines: plain.lines.map((line) => Line.parse(line)),
incalls: plain.incalls,
username: plain.username,
mobileNumber: plain.mobile_phone_number || '',
mobileNumber: plain.mobile_phone_number || "",
ringSeconds: plain.ring_seconds,
forwards: [ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL), ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER), ForwardOption.parse(plain.forwards.busy, FORWARD_KEYS.BUSY)],
forwards: [
ForwardOption.parse(
plain.forwards.unconditional,
FORWARD_KEYS.UNCONDITIONAL
),
ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
ForwardOption.parse(plain.forwards.busy, FORWARD_KEYS.BUSY),
],
doNotDisturb: plain.services.dnd.enabled,
subscriptionType: plain.subscription_type,
voicemail: plain.voicemail,
switchboards: plain.switchboards || [],
agent: plain.agent,
status: '',
status: "",
callPickupTargetUsers: plain.call_pickup_target_users || [],
onlineCallRecordEnabled: plain.online_call_record_enabled,
});
Expand Down Expand Up @@ -270,7 +286,9 @@ export default class Profile {

setForwardOption(forwardOption: ForwardOption) {
const updatedForwardOptions = this.forwards.slice();
const index = updatedForwardOptions.findIndex(forward => forward.is(forwardOption));
const index = updatedForwardOptions.findIndex((forward) =>
forward.is(forwardOption)
);
updatedForwardOptions.splice(index, 1, forwardOption);
this.forwards = updatedForwardOptions;
return this;
Expand All @@ -285,5 +303,4 @@ export default class Profile {
this.state = state;
return this;
}

}
9 changes: 1 addition & 8 deletions src/domain/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@ import { Transport } from "sip.js/lib/api";
import WazoSessionDescriptionHandler from "../lib/WazoSessionDescriptionHandler";
import { Websocket } from "../simple/Websocket";
import * as WebSocketClient from "../websocket-client";
import { LINE_STATE } from "../domain/Profile";

const { SOCKET_EVENTS, ...OTHER_EVENTS } = WebSocketClient;

type GenericObject = Record<string, any>;
export enum LINE_STATE {
AVAILABLE = "available",
HOLDING = "holding",
RINGING = "ringing",
TALKING = "talking",
UNAVAILABLE = "unavailable",
PROGRESSING = "progressing",
}
export type Token = string;
export type UUID = string;
export type DateString = string;
Expand Down

0 comments on commit b1909a2

Please sign in to comment.