Skip to content

Commit cf16594

Browse files
committed
👔 merge update and create function for entity call logs
1 parent e6ccb8d commit cf16594

File tree

4 files changed

+70
-127
lines changed

4 files changed

+70
-127
lines changed

src/index.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,15 @@ export function start(
6969
app.post("/events/calls", (req, res, next) =>
7070
controller.handleCallEvent(req, res, next)
7171
);
72-
app.post("/call-log", (req, res, next) =>
73-
controller.createCallLogForEntities(req, res, next)
74-
);
75-
app.put("/call-log", (req, res, next) =>
76-
controller.updateCallLogForEntities(req, res, next)
77-
);
7872
app.put("/events/calls/:id", (req, res, next) =>
7973
controller.updateCallEvent(req, res, next)
8074
);
8175
app.post("/events/connected", (req, res, next) =>
8276
controller.handleConnectedEvent(req, res, next)
8377
);
78+
app.put("/call-log", (req, res, next) =>
79+
controller.createOrUpdateCallLogForEntities(req, res, next)
80+
);
8481
app.get("/health", (req, res, next) => controller.getHealth(req, res, next));
8582
app.get("/oauth2/redirect", (req, res, next) =>
8683
controller.oAuth2Redirect(req, res, next)

src/models/adapter.model.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
ContactUpdate,
1212
LabeledIntegrationEntity,
1313
LoggedIntegrationEntity,
14-
UpdateCallLogBody,
1514
} from ".";
1615
import { IntegrationEntityType } from "./integration-entity.model";
1716

@@ -51,13 +50,9 @@ export interface Adapter {
5150
* Please do no longer implement handleCallEvent in new bridges.
5251
* */
5352
handleCallEvent?: (config: Config, event: CallEvent) => Promise<string>;
54-
createCallLogsForEntities?: (
53+
createOrUpdateCallLogForEntities?: (
5554
config: Config,
56-
event: CallEventWithIntegrationEntities
57-
) => Promise<LoggedIntegrationEntity[]>;
58-
updateCallLogsForEntities?: (
59-
config: Config,
60-
body: UpdateCallLogBody
55+
body: CallEventWithIntegrationEntities
6156
) => Promise<LoggedIntegrationEntity[]>;
6257
getEntity?: (
6358
providerConfig: Config,

src/models/call-event.model.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,5 @@ export interface CallEvent {
3434
}
3535

3636
export interface CallEventWithIntegrationEntities extends CallEvent {
37-
integrationEntities?: IntegrationEntity[];
38-
}
39-
40-
export interface UpdateCallLogBody {
41-
updatedProperties: { note: string };
42-
loggedIntegrationEntities: (IntegrationEntity | LoggedIntegrationEntity)[];
37+
integrationEntities: (IntegrationEntity | LoggedIntegrationEntity)[];
4338
}

src/models/controller.model.ts

Lines changed: 64 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
ContactTemplate,
1313
ContactUpdate,
1414
ServerError,
15-
UpdateCallLogBody,
1615
} from ".";
1716
import { calendarEventsSchema, contactsSchema } from "../schemas";
1817
import { shouldSkipCallEvent } from "../util/call-event.util";
@@ -652,113 +651,6 @@ export class Controller {
652651
}
653652
}
654653

655-
public async createCallLogForEntities(
656-
req: BridgeRequest<CallEventWithIntegrationEntities>,
657-
res: Response,
658-
next: NextFunction
659-
): Promise<void> {
660-
const { providerConfig } = req;
661-
662-
try {
663-
infoLogger("createCallLogForEntities", `START`, providerConfig?.apiKey);
664-
665-
if (!providerConfig) {
666-
throw new ServerError(400, "Missing config parameters");
667-
}
668-
669-
if (!this.adapter.createCallLogsForEntities) {
670-
throw new ServerError(501, "Creating call log is not implemented");
671-
}
672-
673-
if (shouldSkipCallEvent(req.body)) {
674-
infoLogger(
675-
"createCallLogForEntities",
676-
`Skipping call log for call id ${req.body.id}`,
677-
providerConfig.apiKey
678-
);
679-
res.status(200).send("Skipping call log");
680-
return;
681-
}
682-
683-
infoLogger(
684-
"createCallLogForEntities",
685-
`Creating call Logs…`,
686-
providerConfig.apiKey
687-
);
688-
689-
const entitiesWithCallLogReferences =
690-
await this.adapter.createCallLogsForEntities(providerConfig, req.body);
691-
692-
entitiesWithCallLogReferences.forEach(({ id, logId }) =>
693-
infoLogger(
694-
"createCallLogForEntities",
695-
`CallEvent with logId ${logId} created for id ${id}`,
696-
providerConfig?.apiKey
697-
)
698-
);
699-
700-
infoLogger("createCallLogForEntities", `END`, providerConfig?.apiKey);
701-
res.status(200).send(entitiesWithCallLogReferences);
702-
} catch (error) {
703-
errorLogger(
704-
"createCallLogForEntities",
705-
"Could not create call logs:",
706-
providerConfig?.apiKey,
707-
error || "Unknown"
708-
);
709-
errorLogger(
710-
"createCallLogForEntities",
711-
"Entity",
712-
providerConfig?.apiKey,
713-
req.body
714-
);
715-
next(error);
716-
}
717-
}
718-
719-
public async updateCallLogForEntities(
720-
req: BridgeRequest<UpdateCallLogBody>,
721-
res: Response,
722-
next: NextFunction
723-
): Promise<void> {
724-
const { providerConfig } = req;
725-
726-
try {
727-
infoLogger("updateCallLoGForEntities", `START`, providerConfig?.apiKey);
728-
729-
if (!providerConfig) {
730-
throw new ServerError(400, "Missing config parameters");
731-
}
732-
733-
if (!this.adapter.updateCallLogsForEntities) {
734-
throw new ServerError(
735-
501,
736-
"Updating call log with entities is not implemented"
737-
);
738-
}
739-
740-
infoLogger(
741-
"updateCallLogForEntities",
742-
`Creating call Logs…`,
743-
providerConfig?.apiKey
744-
);
745-
746-
const entitiesWithCallLogReferences =
747-
await this.adapter.updateCallLogsForEntities(providerConfig, req.body);
748-
749-
infoLogger("updateCallLoGForEntities", `END`, providerConfig?.apiKey);
750-
res.status(200).send(entitiesWithCallLogReferences);
751-
} catch (error) {
752-
errorLogger(
753-
"updateCallLogForEntities",
754-
"Could not update call logs with entities:",
755-
providerConfig?.apiKey,
756-
error || "Unknown"
757-
);
758-
next(error);
759-
}
760-
}
761-
762654
public async handleConnectedEvent(
763655
req: BridgeRequest<unknown>,
764656
res: Response,
@@ -829,6 +721,70 @@ export class Controller {
829721
}
830722
}
831723

724+
public async createOrUpdateCallLogForEntities(
725+
req: BridgeRequest<CallEventWithIntegrationEntities>,
726+
res: Response,
727+
next: NextFunction
728+
): Promise<void> {
729+
const { providerConfig } = req;
730+
731+
try {
732+
infoLogger(
733+
"createOrUpdateCallLogForEntities",
734+
`START`,
735+
providerConfig?.apiKey
736+
);
737+
738+
if (!providerConfig) {
739+
throw new ServerError(400, "Missing config parameters");
740+
}
741+
742+
if (!this.adapter.createOrUpdateCallLogForEntities) {
743+
throw new ServerError(
744+
501,
745+
"Updating call log with entities is not implemented"
746+
);
747+
}
748+
749+
if (shouldSkipCallEvent(req.body)) {
750+
infoLogger(
751+
"createOrUpdateCallLogForEntities",
752+
`Skipping call log for call id ${req.body.id}`,
753+
providerConfig.apiKey
754+
);
755+
res.status(200).send("Skipping call log");
756+
return;
757+
}
758+
759+
infoLogger(
760+
"createOrUpdateCallLogForEntities",
761+
`Creating and updating call Logs…`,
762+
providerConfig.apiKey
763+
);
764+
765+
const entitiesWithCallLogReferences =
766+
await this.adapter.createOrUpdateCallLogForEntities(
767+
providerConfig,
768+
req.body
769+
);
770+
771+
infoLogger(
772+
"createOrUpdateCallLogForEntities",
773+
`END`,
774+
providerConfig.apiKey
775+
);
776+
res.status(200).send(entitiesWithCallLogReferences);
777+
} catch (error) {
778+
errorLogger(
779+
"createOrUpdateCallLogForEntities",
780+
"Could not update call logs with entities:",
781+
providerConfig?.apiKey,
782+
error || "Unknown"
783+
);
784+
next(error);
785+
}
786+
}
787+
832788
public async getEntity(
833789
req: IntegrationEntityBridgeRequest,
834790
res: Response,

0 commit comments

Comments
 (0)