Skip to content

Commit

Permalink
Merge branch 'main' into feat/create-lead-upload-files
Browse files Browse the repository at this point in the history
  • Loading branch information
lizandro-mc committed Nov 8, 2023
2 parents 2da070a + 4ae7dc5 commit 873255c
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{

"version": "0.0.56",
"version": "0.0.57",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
Order,
UsersLists,
UsersInteractions,
Messages
Messages,
Roles,
} from './modules';

import { setContext } from '@apollo/client/link/context';
Expand Down Expand Up @@ -86,6 +87,8 @@ export default class KanvasCore {
public order: Order;
public usersLists: UsersLists;
public messages: Messages;
public roles: Roles;

constructor(protected options: Options) {
this.client = new ApolloClient({
link: this.generateLink(),
Expand All @@ -107,6 +110,7 @@ export default class KanvasCore {
this.order = new Order(this.client);
this.usersLists = new UsersLists(this.client);
this.messages = new Messages(this.client);
this.roles = new Roles(this.client);
}

protected generateURL() {
Expand Down
5 changes: 3 additions & 2 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './leads';
export * from './inventory';
export * from './user-interaction';
export * from './agents';
export * from "./commerce"
export * from './commerce';
export * from './usersLists';
export * from './messages'
export * from './messages';
export * from './roles';
49 changes: 49 additions & 0 deletions src/modules/roles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ClientType } from '../../index';
import { GET_ROLES } from '../../queries';
import {
AssignRoleUser,
CreatedRoles,
OrderBy,
RemoveRoleUser,
UserRoleParams,
WhereCondition,
} from '../../types';
import { ASSIGN_ROLE_USER, REMOVE_ROLE_USER } from '../../mutations';

export class Roles {
constructor(protected client: ClientType) {}

public async getRoles(
options: {
whereCondition?: WhereCondition;
orderByCondition?: OrderBy[];
} = {}
): Promise<CreatedRoles> {
const { whereCondition, orderByCondition } = options;

const response = await this.client.query({
query: GET_ROLES,
variables: {
whereCondition,
orderByCondition,
},
});
return response.data;
}

public async assignRoleUser(params: UserRoleParams): Promise<AssignRoleUser> {
const response = await this.client.mutate({
mutation: ASSIGN_ROLE_USER,
variables: { ...params },
});
return response.data;
}

public async removeRoleUser(params: UserRoleParams): Promise<RemoveRoleUser> {
const response = await this.client.mutate({
mutation: REMOVE_ROLE_USER,
variables: { ...params },
});
return response.data;
}
}
4 changes: 2 additions & 2 deletions src/modules/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
WhereCondition,
RoleData,
MultiUpload,
Roles,
RolesEnum,
} from '../../types';

export class Users {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class Users {
if (Array.isArray(roles)) {
return roles
.map(role => role.toLowerCase())
.includes(Roles.ADMIN.toLowerCase());
.includes(RolesEnum.ADMIN.toLowerCase());
}
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions src/mutations/app.mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const APP_CREATE_USER = gql`
default_company
default_company_branch
email
contact {
phone_number
cell_phone_number
}
branches {
id
name
Expand Down
5 changes: 3 additions & 2 deletions src/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export * from './inventory.mutation';
export * from './user-interaction.mutation';
export * from './commerce.mutation';
export * from './messages.mutation';
export * from "./userList.mutation"
export * from "./channels.mutation";
export * from './userList.mutation';
export * from './channels.mutation';
export * from './roles.mutation';
13 changes: 13 additions & 0 deletions src/mutations/roles.mutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { gql } from '@apollo/client';

export const ASSIGN_ROLE_USER = gql`
mutation($userId: ID!, $role: Mixed!) {
assignRoleToUser(userId: $userId, role: $role)
}
`;

export const REMOVE_ROLE_USER = gql`
mutation($userId: ID!, $role: Mixed!) {
removeRole(userId: $userId, role: $role)
}
`;
5 changes: 3 additions & 2 deletions src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './users.query';
export * from './leads.query';
export * from './inventory.query';
export * from './agents.query';
export * from './usersLists.query'
export * from './usersLists.query';
export * from './users-interactions.query';
export * from './messages.query';
export * from './messages.query';
export * from './roles.query';
17 changes: 17 additions & 0 deletions src/queries/roles.query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { gql } from '@apollo/client';

export const GET_ROLES = gql`
query getRoles(
$whereCondition: QueryRolesWhereWhereConditions
$orderByCondition: [QueryRolesOrderByOrderByClause!]
) {
roles(where: $whereCondition, orderBy: $orderByCondition) {
data {
id
name
title
scope
}
}
}
`;
2 changes: 2 additions & 0 deletions src/types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export interface AppCreateUserParams {
lastname?: string;
displayname?: string;
company_name?: string;
phone_number?: string;
cell_phone_number?: string;
roles_id?: string | number;
}

Expand Down
1 change: 1 addition & 0 deletions src/types/inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export interface CreateProductParams {
variants?: ProductVariant[];
price?: number;
attributes?: ProductAttributes[];
company_id?: number | string;
}

export interface AllCreatedProducts {
Expand Down
28 changes: 27 additions & 1 deletion src/types/roles.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
export enum Roles {
export enum RolesEnum {
OWNER = 'Owner',
ADMIN = 'Admin',
USER = 'Users',
AGENT = 'Agents',
DEVELOPER = 'Developer',
MANAGER = 'Managers',
}

export interface RolesInterface {
id: string | number;
name: string;
title: string;
scope: string;
}

export interface CreatedRoles {
roles: {
data: RolesInterface[];
};
}

export interface AssignRoleUser {
assignRoleToUser: boolean;
}

export interface RemoveRoleUser {
removeRole: boolean;
}

export interface UserRoleParams {
userId: string | number;
role: string | number;
}

0 comments on commit 873255c

Please sign in to comment.