Skip to content

Commit

Permalink
fix: Add missing params in node sdk get changes method (novuhq#4932)
Browse files Browse the repository at this point in the history
  • Loading branch information
peoray authored Jan 3, 2024
1 parent 99a6222 commit fbec940
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
8 changes: 7 additions & 1 deletion packages/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,14 @@ import { Novu } from '@novu/node';

const novu = new Novu('<NOVU_API_KEY>');

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()
Expand Down
8 changes: 7 additions & 1 deletion packages/node/src/lib/changes/changes.interface.ts
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 5 additions & 1 deletion packages/node/src/lib/changes/changes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
14 changes: 11 additions & 3 deletions packages/node/src/lib/changes/changes.ts
Original file line number Diff line number Diff line change
@@ -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<object>} - 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,
},
});
}

/**
Expand Down

0 comments on commit fbec940

Please sign in to comment.