@amohamud23/notihub 1.0.165 → 1.0.167

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -414,13 +414,21 @@ var Notifications = class _Notifications {
414
414
  * @returns A promise that resolves to the notification object or null if not found.
415
415
  */
416
416
  static async getNotificationById(id) {
417
- const command = new import_lib_dynamodb4.GetCommand({
418
- TableName: _Notifications.TABLE_NAME,
419
- Key: { id }
420
- });
417
+ const params = {
418
+ TableName: "NotiHub-Notifications-v1-dev",
419
+ IndexName: "NotificationIdIndex",
420
+ KeyConditionExpression: "id = :id",
421
+ ExpressionAttributeValues: {
422
+ ":id": id
423
+ }
424
+ };
425
+ const command = new import_lib_dynamodb4.QueryCommand(params);
421
426
  try {
422
- const result = await ddbDocClient.send(command);
423
- return result.Item || null;
427
+ const response = await ddbDocClient.send(command);
428
+ if (!response.Items || response.Items.length === 0) {
429
+ return null;
430
+ }
431
+ return response.Items[0] ?? null;
424
432
  } catch (error) {
425
433
  console.error("Error fetching notification:", error);
426
434
  throw new Error("Could not fetch notification");
@@ -532,6 +540,37 @@ var NotiHubStats = class _NotiHubStats {
532
540
  throw new Error("Could not update NotiHub stats");
533
541
  }
534
542
  }
543
+ /**
544
+ * Get all stats with in a date range.
545
+ * @param startDate - The start date of the range.
546
+ * @param endDate - The end date of the range.
547
+ * @returns A promise that resolves to an array of statistics objects.
548
+ */
549
+ static async getStatsInDateRange(startDate, endDate) {
550
+ const command = new import_lib_dynamodb5.QueryCommand({
551
+ TableName: _NotiHubStats.TABLE_NAME,
552
+ IndexName: "DateIndex",
553
+ // Assuming you have a GSI for date
554
+ KeyConditionExpression: "#date BETWEEN :start_date AND :end_date",
555
+ ExpressionAttributeNames: {
556
+ "#date": "date"
557
+ },
558
+ ExpressionAttributeValues: {
559
+ ":start_date": startDate,
560
+ ":end_date": endDate
561
+ }
562
+ });
563
+ try {
564
+ const result = await ddbDocClient.send(command);
565
+ return result.Items || [];
566
+ } catch (error) {
567
+ console.error(
568
+ `Error fetching NotiHub stats between dates: ${startDate} and ${endDate}`,
569
+ error
570
+ );
571
+ throw new Error("Could not fetch NotiHub stats in date range");
572
+ }
573
+ }
535
574
  };
536
575
  var NotiHubStats_default = NotiHubStats;
537
576
 
package/dist/index.d.cts CHANGED
@@ -152,8 +152,7 @@ type INotiTypeStats = {
152
152
  };
153
153
  type IUserSubscription = {
154
154
  id: string;
155
- user: INotiHubUser;
156
- customer: INotiHubCustomer;
155
+ userId: string;
157
156
  customerId: string;
158
157
  subscriptionId: string;
159
158
  type: "SUBSCRIBED" | "UNSUBSCRIBED";
@@ -373,6 +372,13 @@ declare class NotiHubStats {
373
372
  * @returns A promise that resolves to the updated statistics object.
374
373
  */
375
374
  static updateViewsStats(notificationId: string): Promise<INotiHubStats>;
375
+ /**
376
+ * Get all stats with in a date range.
377
+ * @param startDate - The start date of the range.
378
+ * @param endDate - The end date of the range.
379
+ * @returns A promise that resolves to an array of statistics objects.
380
+ */
381
+ static getStatsInDateRange(startDate: string, endDate: string): Promise<INotiHubStats[]>;
376
382
  }
377
383
 
378
384
  declare class NotiType {
package/dist/index.d.ts CHANGED
@@ -152,8 +152,7 @@ type INotiTypeStats = {
152
152
  };
153
153
  type IUserSubscription = {
154
154
  id: string;
155
- user: INotiHubUser;
156
- customer: INotiHubCustomer;
155
+ userId: string;
157
156
  customerId: string;
158
157
  subscriptionId: string;
159
158
  type: "SUBSCRIBED" | "UNSUBSCRIBED";
@@ -373,6 +372,13 @@ declare class NotiHubStats {
373
372
  * @returns A promise that resolves to the updated statistics object.
374
373
  */
375
374
  static updateViewsStats(notificationId: string): Promise<INotiHubStats>;
375
+ /**
376
+ * Get all stats with in a date range.
377
+ * @param startDate - The start date of the range.
378
+ * @param endDate - The end date of the range.
379
+ * @returns A promise that resolves to an array of statistics objects.
380
+ */
381
+ static getStatsInDateRange(startDate: string, endDate: string): Promise<INotiHubStats[]>;
376
382
  }
377
383
 
378
384
  declare class NotiType {
package/dist/index.js CHANGED
@@ -377,7 +377,6 @@ var Customer_default = Customer;
377
377
 
378
378
  // src/DynamoModels/Notifications.ts
379
379
  import {
380
- GetCommand as GetCommand3,
381
380
  PutCommand as PutCommand3,
382
381
  QueryCommand as QueryCommand2
383
382
  } from "@aws-sdk/lib-dynamodb";
@@ -390,13 +389,21 @@ var Notifications = class _Notifications {
390
389
  * @returns A promise that resolves to the notification object or null if not found.
391
390
  */
392
391
  static async getNotificationById(id) {
393
- const command = new GetCommand3({
394
- TableName: _Notifications.TABLE_NAME,
395
- Key: { id }
396
- });
392
+ const params = {
393
+ TableName: "NotiHub-Notifications-v1-dev",
394
+ IndexName: "NotificationIdIndex",
395
+ KeyConditionExpression: "id = :id",
396
+ ExpressionAttributeValues: {
397
+ ":id": id
398
+ }
399
+ };
400
+ const command = new QueryCommand2(params);
397
401
  try {
398
- const result = await ddbDocClient.send(command);
399
- return result.Item || null;
402
+ const response = await ddbDocClient.send(command);
403
+ if (!response.Items || response.Items.length === 0) {
404
+ return null;
405
+ }
406
+ return response.Items[0] ?? null;
400
407
  } catch (error) {
401
408
  console.error("Error fetching notification:", error);
402
409
  throw new Error("Could not fetch notification");
@@ -449,6 +456,7 @@ var Notifications_default = Notifications;
449
456
  import {
450
457
  GetCommand as GetCommand4,
451
458
  PutCommand as PutCommand4,
459
+ QueryCommand as QueryCommand3,
452
460
  UpdateCommand as UpdateCommand4
453
461
  } from "@aws-sdk/lib-dynamodb";
454
462
  var NotiHubStats = class _NotiHubStats {
@@ -512,6 +520,37 @@ var NotiHubStats = class _NotiHubStats {
512
520
  throw new Error("Could not update NotiHub stats");
513
521
  }
514
522
  }
523
+ /**
524
+ * Get all stats with in a date range.
525
+ * @param startDate - The start date of the range.
526
+ * @param endDate - The end date of the range.
527
+ * @returns A promise that resolves to an array of statistics objects.
528
+ */
529
+ static async getStatsInDateRange(startDate, endDate) {
530
+ const command = new QueryCommand3({
531
+ TableName: _NotiHubStats.TABLE_NAME,
532
+ IndexName: "DateIndex",
533
+ // Assuming you have a GSI for date
534
+ KeyConditionExpression: "#date BETWEEN :start_date AND :end_date",
535
+ ExpressionAttributeNames: {
536
+ "#date": "date"
537
+ },
538
+ ExpressionAttributeValues: {
539
+ ":start_date": startDate,
540
+ ":end_date": endDate
541
+ }
542
+ });
543
+ try {
544
+ const result = await ddbDocClient.send(command);
545
+ return result.Items || [];
546
+ } catch (error) {
547
+ console.error(
548
+ `Error fetching NotiHub stats between dates: ${startDate} and ${endDate}`,
549
+ error
550
+ );
551
+ throw new Error("Could not fetch NotiHub stats in date range");
552
+ }
553
+ }
515
554
  };
516
555
  var NotiHubStats_default = NotiHubStats;
517
556
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.0.165",
3
+ "version": "1.0.167",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",