mirror of
https://github.com/vernu/textbee.git
synced 2026-05-19 05:46:23 -04:00
feat(api): track received sms count stat
This commit is contained in:
@@ -170,6 +170,16 @@ export class GatewayService {
|
||||
receivedAt: dto.receivedAt,
|
||||
})
|
||||
|
||||
this.deviceModel
|
||||
.findByIdAndUpdate(deviceId, {
|
||||
$inc: { receivedSMSCount: 1 },
|
||||
})
|
||||
.exec()
|
||||
.catch((e) => {
|
||||
console.log('Failed to update receivedSMSCount')
|
||||
console.log(e)
|
||||
})
|
||||
|
||||
// TODO: Implement webhook to forward received SMS to user's callback URL
|
||||
|
||||
return sms
|
||||
@@ -207,15 +217,20 @@ export class GatewayService {
|
||||
const devices = await this.deviceModel.find({ user: user._id })
|
||||
const apiKeys = await this.authService.getUserApiKeys(user)
|
||||
|
||||
const totalSMSCount = devices.reduce((acc, device) => {
|
||||
const totalSentSMSCount = devices.reduce((acc, device) => {
|
||||
return acc + (device.sentSMSCount || 0)
|
||||
}, 0)
|
||||
|
||||
const totalReceivedSMSCount = devices.reduce((acc, device) => {
|
||||
return acc + (device.receivedSMSCount || 0)
|
||||
}, 0)
|
||||
|
||||
const totalDeviceCount = devices.length
|
||||
const totalApiKeyCount = apiKeys.length
|
||||
|
||||
return {
|
||||
totalSMSCount,
|
||||
totalSentSMSCount,
|
||||
totalReceivedSMSCount,
|
||||
totalDeviceCount,
|
||||
totalApiKeyCount,
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ export class Device {
|
||||
|
||||
@Prop({ type: Number, default: 0 })
|
||||
sentSMSCount: number
|
||||
|
||||
@Prop({ type: Number, default: 0 })
|
||||
receivedSMSCount: number
|
||||
}
|
||||
|
||||
export const DeviceSchema = SchemaFactory.createForClass(Device)
|
||||
|
||||
Reference in New Issue
Block a user