Skip to content

Commit

Permalink
feat: linked user devices
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Jan 6, 2025
1 parent da00867 commit 803719e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.24.3",
"version": "0.25.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
24 changes: 22 additions & 2 deletions src/modules/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
BLOCK_USER_MUTATION,
UNBLOCK_USER_MUTATION,
UPDATE_EMAIL_MUTATION,
LINK_DEVICE_MUTATION,
UNLINK_DEVICE_MUTATION,
} from '../../mutations';
import {
UserInterface,
Expand All @@ -44,6 +46,7 @@ import {
SocialLoginParams,
OrderBy,
AllBlockedUsersInterface,
DeviceParams,
} from '../../types';

export class Users {
Expand Down Expand Up @@ -329,11 +332,28 @@ export class Users {
return response.data.unBlockUser;
}

public async updateEmail(email: string): Promise<boolean > {
public async updateEmail(email: string): Promise<boolean> {
const response = await this.client.mutate({
mutation: UPDATE_EMAIL_MUTATION,
variables: { email },
});
return response.data;
}
}


public async linkDevice(input: DeviceParams): Promise<boolean> {
const response = await this.client.mutate({
mutation: LINK_DEVICE_MUTATION,
variables: { data: input },
});
return response.data.linkDevice;
}

public async unLinkDevice(input: DeviceParams): Promise<boolean> {
const response = await this.client.mutate({
mutation: UNLINK_DEVICE_MUTATION,
variables: { data: input },
});
return response.data.unLinkDevice;
}
}
12 changes: 12 additions & 0 deletions src/mutations/users.mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,16 @@ export const UPDATE_EMAIL_MUTATION = gql`
mutation updateEmail($email: String!) {
updateEmail(email: $email)
}
`;

export const LINK_DEVICE_MUTATION = gql`
mutation linkDevice($data: DeviceInput!) {
linkDevice(data: $data)
}
`;

export const UNLINK_DEVICE_MUTATION = gql`
mutation unLinkDevice($data: DeviceInput!) {
unLinkDevice(data: $data)
}
`;
11 changes: 11 additions & 0 deletions src/types/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,15 @@ export interface AllBlockedUsersInterface {
data: UserInterface[];
paginatorInfo?: PaginatorInfo;
};
}

export enum SourceSite {
AndroidApp = "androidapp",
IOSApp = "iosapp",
}

export interface DeviceParams {
device_id: string;
source_site: SourceSite; // Use the enum here
source_username?: string;
}
25 changes: 23 additions & 2 deletions test/user.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UpdateUserParams } from '../src';
import { SourceSite, UpdateUserParams } from '../src';
import { initializeClient, getClient } from './setupClient';
import dotenv from 'dotenv';

Expand Down Expand Up @@ -97,7 +97,6 @@ describe('Test the KanvasCore client', () => {
userInfo.id,
updatedUserInfo
);
console.log(updateUser.custom_fields);
expect(updateUser).toBeDefined();
expect(updateUser.firstname).toBe('Max');
});
Expand Down Expand Up @@ -149,4 +148,26 @@ describe('Test the KanvasCore client', () => {

expect(blockedUsers.blockedUsers.data).toBeDefined();
});

it('test link device', async () => {
const client = getClient();
const deviceParams = {
device_id: '123456',
source_site: SourceSite.IOSApp,
};
const linkedDevice = await client.users.linkDevice(deviceParams);

expect(linkedDevice).toBeTruthy();
});

it('test unlink device', async () => {
const client = getClient();
const deviceParams = {
device_id: '123456',
source_site: SourceSite.IOSApp,
};
const unlinkedDevice = await client.users.unLinkDevice(deviceParams);

expect(unlinkedDevice).toBeTruthy();
});
});

0 comments on commit 803719e

Please sign in to comment.