From fbec940dfb03e12ae3237549f880b78796060a1c Mon Sep 17 00:00:00 2001 From: Emmanuel Raymond Date: Wed, 3 Jan 2024 14:38:29 +0100 Subject: [PATCH] fix: Add missing params in node sdk get changes method (#4932) --- packages/node/README.md | 8 +++++++- packages/node/src/lib/changes/changes.interface.ts | 8 +++++++- packages/node/src/lib/changes/changes.spec.ts | 6 +++++- packages/node/src/lib/changes/changes.ts | 14 +++++++++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/node/README.md b/packages/node/README.md index 53c67c8db96..84b349d49c5 100644 --- a/packages/node/README.md +++ b/packages/node/README.md @@ -965,8 +965,14 @@ import { Novu } from '@novu/node'; const novu = new Novu(''); +const changesParams = { + page: 1, //optional + limit: 20, // optional + promoted: false // required +} + // get all changes -await novu.changes.get() +await novu.changes.get(changesParams) // get changes count await novu.changes.getCount() diff --git a/packages/node/src/lib/changes/changes.interface.ts b/packages/node/src/lib/changes/changes.interface.ts index 3c485a795d6..62a80602874 100644 --- a/packages/node/src/lib/changes/changes.interface.ts +++ b/packages/node/src/lib/changes/changes.interface.ts @@ -1,6 +1,12 @@ export interface IChanges { - get(); + get(data: IChangesPayload); getCount(); applyOne(changeId: string); applyMany(changeIds: string[]); } + +export interface IChangesPayload { + page?: number; + limit?: number; + promoted: boolean; +} diff --git a/packages/node/src/lib/changes/changes.spec.ts b/packages/node/src/lib/changes/changes.spec.ts index 02c643acaea..b55975d317a 100644 --- a/packages/node/src/lib/changes/changes.spec.ts +++ b/packages/node/src/lib/changes/changes.spec.ts @@ -17,9 +17,13 @@ describe('test use of novus node package - Changes class', () => { }); test('should get changes correctly', async () => { + const page = 1; + const limit = 20; + const promoted = false; + mockedAxios.post.mockResolvedValue({}); - await novu.changes.get(); + await novu.changes.get({ page, limit, promoted }); expect(mockedAxios.get).toHaveBeenCalled(); expect(mockedAxios.get).toHaveBeenCalledWith('/changes'); diff --git a/packages/node/src/lib/changes/changes.ts b/packages/node/src/lib/changes/changes.ts index c5ebf31e10a..a171cb24aec 100644 --- a/packages/node/src/lib/changes/changes.ts +++ b/packages/node/src/lib/changes/changes.ts @@ -1,12 +1,20 @@ -import { IChanges } from './changes.interface'; +import { IChanges, IChangesPayload } from './changes.interface'; import { WithHttp } from '../novu.interface'; export class Changes extends WithHttp implements IChanges { /** * @returns {promise} - Returns an object containing all changes */ - async get() { - return await this.http.get(`/changes`); + async get(data: IChangesPayload) { + const { page, limit, promoted } = data; + + return await this.http.get(`/changes`, { + params: { + page, + limit, + promoted, + }, + }); } /**