Skip to content

Commit

Permalink
feat: follow
Browse files Browse the repository at this point in the history
  • Loading branch information
FredPeal committed Dec 19, 2023
1 parent 7d6ff99 commit a928f1c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
17 changes: 9 additions & 8 deletions src/modules/follows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { USER_FOLLOW_MUTATION, USER_UNFOLLOW_MUTATION } from '../../mutations/';

import {
IS_FOLLOWING_QUERY,
USER_FOLLOWERS_QUERY,
GET_FOLLOWERS_QUERY,
GET_FOLLOWING_QUERY,
GET_TOTAL_FOLLOWERS_QUERY,
} from '../../queries/follows.query';
Expand All @@ -16,38 +16,39 @@ export class Follow {
public async followUser(user_id: number): Promise<boolean> {
const response = await this.client.mutate({
mutation: USER_FOLLOW_MUTATION,
variables: { user_id },
variables: { user_id: user_id },
});
return response.data.userFollow as boolean;
}

public async unFollowUser(user_id: number): Promise<boolean> {
const response = await this.client.mutate({
mutation: USER_UNFOLLOW_MUTATION,
variables: { user_id },
variables: { user_id: user_id },
});
return response.data.userUnFollow as boolean;
}

public async isFollowing(user_id: number): Promise<boolean> {
const response = await this.client.query({
query: IS_FOLLOWING_QUERY,
variables: { user_id },
variables: { user_id: user_id },
});
return response.data.isFollowing as boolean;
}

public async userFollowers(user_id: number): Promise<UserInterface[]> {
public async getFollowers(user_id: number): Promise<UserInterface[]> {
const response = await this.client.query({
query: USER_FOLLOWERS_QUERY,
query: GET_FOLLOWERS_QUERY,
variables: { user_id },
});
return response.data.userFollowers.data as UserInterface[];
return response.data.getFollowers.data as UserInterface[];
}

public async getFollowing(): Promise<FollowingInterface[]> {
public async getFollowing(user_id: number): Promise<FollowingInterface[]> {
const response = await this.client.query({
query: GET_FOLLOWING_QUERY,
variables: { user_id: user_id },
});
return response.data.getFollowing.data as FollowingInterface[];
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/people/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientType } from '../../index';
import { ClientType } from './../../index';

import {
PeopleInputInterface,
Expand All @@ -14,7 +14,7 @@ import {
RESTORE_PEOPLE_MUTATION,
} from '../../mutations';

import { PEOPLE_QUERY } from '../../index';
import { PEOPLE_QUERY } from './../../queries/';
export class People {
constructor(protected client: ClientType) {}

Expand Down
12 changes: 6 additions & 6 deletions src/queries/follows.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export const IS_FOLLOWING_QUERY = gql`
}
`;

export const USER_FOLLOWERS_QUERY = gql`
query userFollowers($user_id: Int!) {
userFollowers(user_id: $user_id) {
export const GET_FOLLOWERS_QUERY = gql`
query getFollowers($user_id: Int!) {
getFollowers(user_id: $user_id) {
data {
id
uuid
Expand Down Expand Up @@ -49,11 +49,11 @@ export const USER_FOLLOWERS_QUERY = gql`
`;

export const GET_FOLLOWING_QUERY = gql`
query getFollowing {
getFollowing {
query getFollowing($user_id: Int!) {
getFollowing(user_id: $user_id) {
data {
id
user_id
users_id
entity_namespace
entity_id
entity {
Expand Down
2 changes: 1 addition & 1 deletion src/types/follows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UserInterface } from './users';

export interface FollowingInterface {
id: number;
user_id: number;
users_id: number;
entity_namespace: string;
entity_id: number;
entity: UserInterface;
Expand Down

0 comments on commit a928f1c

Please sign in to comment.