Skip to content

Commit

Permalink
Merge pull request #328 from bakaphp/feat-blocked-users
Browse files Browse the repository at this point in the history
featt: add blocked users
  • Loading branch information
AudryLopez authored Oct 18, 2024
2 parents a995556 + 85a3a5f commit 5a3f610
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 3 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.12.3",
"version": "0.13.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
51 changes: 51 additions & 0 deletions src/modules/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GET_USER_SOCIAL_DATA_QUERY,
GET_USER_BY_DISPLAYNAME,
GET_USER_BY_ID,
GET_BLOCKED_USERS,
} from '../../queries';
import {
REGISTER_MUTATTION,
Expand All @@ -22,6 +23,8 @@ import {
UPDATE_DISPLAY_NAME_MUTATION,
UPDATE_USER_SOCIAL_MUTATION,
SHARE_USER_MUTATION,
BLOCK_USER_MUTATION,
UNBLOCK_USER_MUTATION,
} from '../../mutations';
import {
UserInterface,
Expand All @@ -38,6 +41,8 @@ import {
InviteData,
SocialLoginData,
SocialLoginParams,
OrderBy,
AllBlockedUsersInterface,
} from '../../types';

export class Users {
Expand Down Expand Up @@ -215,6 +220,36 @@ export class Users {
return response.data.usersInvites.data;
}

public async getBlockedUsers(
options: {
first?: number;
page?: number;
whereCondition?: WhereCondition;
orderByCondition?: OrderBy[];
} = {}
): Promise<AllBlockedUsersInterface> {
const {
first,
page,
whereCondition,
orderByCondition,
} = options;

const response = await this.client.query({
query: GET_BLOCKED_USERS,
variables: {
first,
page,
whereCondition,
orderByCondition
},
fetchPolicy: 'network-only',
partialRefetch: true,
});

return response.data;
}

public async processInvite(
input: InviteProcessParams
): Promise<InviteProcessData> {
Expand Down Expand Up @@ -276,4 +311,20 @@ export class Users {
});
return response.data.shareUser;
}

public async blockUser(id: number | string): Promise<boolean> {
const response = await this.client.mutate({
mutation: BLOCK_USER_MUTATION,
variables: { id },
});
return response.data.blockUser;
}

public async unBlockUser(id: number | string): Promise<boolean> {
const response = await this.client.mutate({
mutation: UNBLOCK_USER_MUTATION,
variables: { id },
});
return response.data.unBlockUser;
}
}
13 changes: 13 additions & 0 deletions src/mutations/users.mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const UPDATE_USER_SOCIAL_MUTATION = gql`
total_message
total_followers
total_following
is_following
}
email
branches {
Expand Down Expand Up @@ -193,4 +194,16 @@ export const SHARE_USER_MUTATION = gql`
mutation shareUser($id: ID!) {
shareUser(id: $id)
}
`;

export const BLOCK_USER_MUTATION = gql`
mutation blockUser($id: ID!) {
blockUser(id: $id)
}
`;

export const UNBLOCK_USER_MUTATION = gql`
mutation unBlockUser($id: ID!) {
unBlockUser(id: $id)
}
`;
3 changes: 2 additions & 1 deletion src/queries/app.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const GET_APP_USERS = gql`
total_message
total_followers
total_following
is_following
}
created_at
updated_at
Expand Down Expand Up @@ -124,4 +125,4 @@ export const GET_APPS_WITH_ACCESS = gql`
}
}
}
`;
`;
2 changes: 2 additions & 0 deletions src/queries/follows.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const GET_FOLLOWERS_QUERY = gql`
total_message
total_followers
total_following
is_following
}
roles
abilities
Expand Down Expand Up @@ -85,6 +86,7 @@ export const GET_FOLLOWING_QUERY = gql`
total_message
total_followers
total_following
is_following
}
roles
abilities
Expand Down
58 changes: 58 additions & 0 deletions src/queries/users.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,61 @@ export const GET_USERS_INVITES_BY_ROLE_ID_QUERY = gql`
}
}
`;


export const GET_BLOCKED_USERS = gql`
query getBlockedUsers(
$first: Int
$page: Int
$whereCondition: QueryBlockedUsersWhereWhereConditions
$orderBy: [QueryBlockedUsersOrderByOrderByClause!]
) {
blockedUsers(
first: $first
page: $page
where: $whereCondition
orderBy: $orderBy
) {
data {
id
uuid
email
displayname
lastname
firstname
description
default_company
default_company_branch
sex
user_active
roles
is_active
contact {
phone_number
cell_phone_number
}
photo {
url
}
social {
total_message
total_followers
total_following
is_following
}
created_at
updated_at
}
paginatorInfo {
currentPage
perPage
firstItem
lastItem
total
count
lastPage
hasMorePages
}
}
}
`;
1 change: 1 addition & 0 deletions src/types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface AppUserInterface {
total_message: number;
total_followers: number;
total_following: number;
is_following: number;
};
created_at: string;
updated_at: string;
Expand Down
10 changes: 10 additions & 0 deletions src/types/users.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { CustomFieldData, CustomFieldInput } from './custom-fields';
import { PaginatorInfo } from './paginator';

export interface UserInterface {
id: number;
Expand Down Expand Up @@ -75,6 +76,7 @@ export interface UserInterface {
total_message: number;
total_followers: number;
total_following: number;
is_following: number;
};
// social_links: SocialLinkInterface[];
custom_fields?: CustomFieldInput[];
Expand Down Expand Up @@ -112,6 +114,7 @@ export interface UserData {
total_message: number;
total_followers: number;
total_following: number;
is_following: number;
};
branches: {
id: string;
Expand Down Expand Up @@ -210,3 +213,10 @@ export interface SocialLoginParams {
}

export interface SocialLoginData extends InviteProcessData { }

export interface AllBlockedUsersInterface {
blockedUsers: {
data: UserInterface[];
paginatorInfo?: PaginatorInfo;
};
}
33 changes: 33 additions & 0 deletions test/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { initializeClient, getClient } from './setupClient';
import dotenv from 'dotenv';

dotenv.config();

beforeAll(async () => {
await initializeClient(process.env.KANVAS_APP_SECRET!);
});

describe('Test the KanvasCore client', () => {
it('initializes correctly', async () => {
const client = getClient();
expect(client).toBeDefined();
});

it('gets user info by id', async () => {
const client = getClient();
const user = await client.users.getUserByDisplayName('test');

const userInfo = await client.app.users.getAppUsers({
first: 1,
whereCondition: {
column: "ID",
operator: "EQ",
value: user.id,
}
})

expect(userInfo.appUsers.data.length).toBe(1);
expect(userInfo.appUsers.data[0].id).toBe(user.id);
});

});
27 changes: 26 additions & 1 deletion test/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Test the KanvasCore client', () => {

it('gets user info', async () => {
const client = getClient();

//if you pass anything with been a app owner it will return your user
const userInfo = await client.users.getUserByDisplayName('test');
expect(userInfo).toBeDefined();
Expand Down Expand Up @@ -104,4 +104,29 @@ describe('Test the KanvasCore client', () => {
const sharedProfile = await client.users.shareUserById(userInfo.id);
expect(sharedProfile).toBeDefined();
});

it('test block user by id', async () => {
const client = getClient();
const userInfo = await client.users.getUserByDisplayName('test');

const blockedUser = await client.users.blockUser(userInfo.id);

expect(blockedUser).toBeDefined();
});

it('test unblock user by id', async () => {
const client = getClient();
const userInfo = await client.users.getUserByDisplayName('test');

const unblockedUser = await client.users.unBlockUser(userInfo.id);

expect(unblockedUser).toBeDefined();
});

it('test get blocked users', async () => {
const client = getClient();
const blockedUsers = await client.users.getBlockedUsers();

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

0 comments on commit 5a3f610

Please sign in to comment.