From 7eb78b72f202916714ac7e057b1b8b1914440e80 Mon Sep 17 00:00:00 2001 From: isra el Date: Sat, 2 Mar 2024 20:59:04 +0300 Subject: [PATCH] feat(api): track sent sms count per device --- api/src/gateway/gateway.service.ts | 6 ++++++ api/src/gateway/schemas/device.schema.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/api/src/gateway/gateway.service.ts b/api/src/gateway/gateway.service.ts index 9f33cd2..c1cdfd7 100644 --- a/api/src/gateway/gateway.service.ts +++ b/api/src/gateway/gateway.service.ts @@ -95,6 +95,12 @@ export class GatewayService { const response = await firebaseAdmin .messaging() .sendToDevice(device.fcmToken, payload, { priority: 'high' }) + + this.deviceModel.findByIdAndUpdate( + deviceId, + { $inc: { sentSMSCount: 1 } }, + { new: true }, + ) return response } catch (e) { throw new HttpException( diff --git a/api/src/gateway/schemas/device.schema.ts b/api/src/gateway/schemas/device.schema.ts index ca5626f..4bc67f9 100644 --- a/api/src/gateway/schemas/device.schema.ts +++ b/api/src/gateway/schemas/device.schema.ts @@ -43,6 +43,9 @@ export class Device { @Prop({ type: Number }) appVersionCode: number + + @Prop({ type: Number, default: 0 }) + sentSMSCount: number } export const DeviceSchema = SchemaFactory.createForClass(Device)