Skip to content

Commit

Permalink
Fix issue where Graph events were returning 400 on update (#524)
Browse files Browse the repository at this point in the history
This PR remedies the issue seen where Graph accounts were returning 400 on update due to visibility field being present in the PUT request. We now check to see if the visibility field was modified, and only then do we include it in the outgoing request.
  • Loading branch information
mrashed-dev committed Jan 5, 2024
1 parent 6586ab4 commit 1e9d1a2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### Unreleased
* Fix issue where Graph events were returning 400 on update

### 6.11.0 / 2023-11-28
* Add support for logging
* Nullify replyToMessageId is an empty string
Expand Down
30 changes: 27 additions & 3 deletions src/models/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ export default class Event extends RestfulModel {
organizerEmail?: string;
organizerName?: string;
hideParticipants?: boolean;
visibility?: string;
customerEventId?: string;
private _visibility?: string;
private visibilityIsDirty = false;
static collectionName = 'events';
static attributes: Record<string, Attribute> = {
...RestfulModel.attributes,
Expand Down Expand Up @@ -220,7 +221,8 @@ export default class Event extends RestfulModel {
jsonKey: 'hide_participants',
}),
visibility: Attributes.String({
modelKey: 'visibility',
modelKey: '_visibility',
jsonKey: 'visibility',
}),
customerEventId: Attributes.String({
modelKey: 'customerEventId',
Expand All @@ -231,6 +233,7 @@ export default class Event extends RestfulModel {
constructor(connection: NylasConnection, props?: EventProperties) {
super(connection, props);
this.initAttributes(props);
this.visibilityIsDirty = false;
}

get start(): string | number | undefined {
Expand Down Expand Up @@ -307,6 +310,18 @@ export default class Event extends RestfulModel {
}
}

get visibility(): string | undefined {
return this._visibility;
}

set visibility(val: string | undefined) {
if (val !== this._visibility) {
this.visibilityIsDirty = true;
}

this._visibility = val;
}

deleteRequestQueryString(
params: Record<string, unknown> = {}
): Record<string, unknown> {
Expand All @@ -333,7 +348,10 @@ export default class Event extends RestfulModel {
participant => delete participant.status
);
}
if (this.visibility !== undefined && this.visibility === '') {
if (
(this.visibility !== undefined && this.visibility === '') ||
!this.visibilityIsDirty
) {
delete json.visibility;
}

Expand Down Expand Up @@ -402,6 +420,12 @@ export default class Event extends RestfulModel {
});
}

fromJSON(json: Record<string, unknown>): this {
const model = super.fromJSON(json);
model.visibilityIsDirty = false;
return model;
}

private validate(): void {
if (
this.conferencing &&
Expand Down

0 comments on commit 1e9d1a2

Please sign in to comment.