diff --git a/src/db/couchDevices.ts b/src/db/couchDevices.ts index 45ce590..53f45c0 100644 --- a/src/db/couchDevices.ts +++ b/src/db/couchDevices.ts @@ -1,5 +1,6 @@ import { asArray, + asBoolean, asDate, asObject, asOptional, @@ -43,6 +44,7 @@ export const asCouchDevice = asCouchDoc( // Status: apiKey: asOptional(asString), deviceToken: asOptional(asString), + ignorePriceChanges: asOptional(asBoolean, false), loginIds: asArray(asBase64), visited: asDate }) @@ -84,6 +86,7 @@ export async function getDeviceById( created: date, apiKey: undefined, deviceToken: undefined, + ignorePriceChanges: false, loginIds: [], visited: date } @@ -160,6 +163,9 @@ function makeDeviceRow( if (device.deviceToken === base.deviceToken) { device.deviceToken = remote.doc.deviceToken } + if (device.ignorePriceChanges === base.ignorePriceChanges) { + device.ignorePriceChanges = remote.doc.ignorePriceChanges + } if (device.loginIds === base.loginIds) { device.loginIds = remote.doc.loginIds } diff --git a/src/server/routes/deviceRoutes.ts b/src/server/routes/deviceRoutes.ts index 902d4e7..aeb1185 100644 --- a/src/server/routes/deviceRoutes.ts +++ b/src/server/routes/deviceRoutes.ts @@ -24,8 +24,9 @@ export const deviceFetchRoute = withDevice(async request => { return jsonResponse( wasDevicePayload({ - loginIds: device.loginIds, - events: eventRows.map(row => row.event) + events: eventRows.map(row => row.event), + ignorePriceChanges: device.ignorePriceChanges, + loginIds: device.loginIds }) ) }) @@ -43,9 +44,15 @@ export const deviceUpdateRoute = withDevice(async request => { const checked = checkPayload(asDeviceUpdatePayload, payload) if (checked.error != null) return checked.error - const { loginIds, createEvents, removeEvents } = checked.clean + const { loginIds, createEvents, ignorePriceChanges, removeEvents } = + checked.clean - device.loginIds = loginIds + if (ignorePriceChanges != null) { + device.ignorePriceChanges = ignorePriceChanges + } + if (loginIds != null) { + device.loginIds = loginIds + } const events = await adjustEvents(connection, { date, deviceId: device.deviceId, @@ -53,5 +60,11 @@ export const deviceUpdateRoute = withDevice(async request => { removeEvents }) - return jsonResponse(wasDevicePayload({ loginIds: device.loginIds, events })) + return jsonResponse( + wasDevicePayload({ + events, + ignorePriceChanges: device.ignorePriceChanges, + loginIds: device.loginIds + }) + ) }) diff --git a/src/types/pushApiTypes.ts b/src/types/pushApiTypes.ts index 3e35b90..7e1cd64 100644 --- a/src/types/pushApiTypes.ts +++ b/src/types/pushApiTypes.ts @@ -1,5 +1,6 @@ import { asArray, + asBoolean, asDate, asEither, asNull, @@ -54,9 +55,11 @@ export interface NewPushEvent { * PUSH /v2/device/update payload. */ export interface DeviceUpdatePayload { - loginIds: Uint8Array[] createEvents?: NewPushEvent[] removeEvents?: string[] + + ignorePriceChanges?: boolean + loginIds?: Uint8Array[] } /** @@ -92,9 +95,11 @@ export const asNewPushEvent: Cleaner = asObject({ }) export const asDeviceUpdatePayload: Cleaner = asObject({ - loginIds: asArray(asBase64), createEvents: asOptional(asArray(asNewPushEvent), []), - removeEvents: asOptional(asArray(asString), []) + removeEvents: asOptional(asArray(asString), []), + + ignorePriceChanges: asOptional(asBoolean), + loginIds: asOptional(asArray(asBase64)) }) export const asLoginUpdatePayload: Cleaner = asObject({ @@ -131,8 +136,9 @@ export const asPushEventStatus: Cleaner< * POST /v2/device response payload. */ export const asDevicePayload = asObject({ - loginIds: asArray(asBase64), - events: asArray(asPushEventStatus) + events: asArray(asPushEventStatus), + ignorePriceChanges: asBoolean, + loginIds: asArray(asBase64) }) /** diff --git a/src/types/pushTypes.ts b/src/types/pushTypes.ts index a06cbef..3acc270 100644 --- a/src/types/pushTypes.ts +++ b/src/types/pushTypes.ts @@ -41,6 +41,7 @@ export interface Device { // Settings: apiKey: string | undefined // Which app to send to? deviceToken: string | undefined + ignorePriceChanges: boolean loginIds: Uint8Array[] visited: Date }