diff --git a/package.json b/package.json index 9356a759..5ac209df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "version": "0.0.56", + "version": "0.0.57", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index fd80ab5d..fe630dea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,7 +19,8 @@ import { Order, UsersLists, UsersInteractions, - Messages + Messages, + Roles, } from './modules'; import { setContext } from '@apollo/client/link/context'; @@ -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(), @@ -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() { diff --git a/src/modules/index.ts b/src/modules/index.ts index 8c33c715..fe82d571 100644 --- a/src/modules/index.ts +++ b/src/modules/index.ts @@ -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' \ No newline at end of file +export * from './messages'; +export * from './roles'; diff --git a/src/modules/roles/index.ts b/src/modules/roles/index.ts new file mode 100644 index 00000000..ee0a2a2a --- /dev/null +++ b/src/modules/roles/index.ts @@ -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 { + 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 { + const response = await this.client.mutate({ + mutation: ASSIGN_ROLE_USER, + variables: { ...params }, + }); + return response.data; + } + + public async removeRoleUser(params: UserRoleParams): Promise { + const response = await this.client.mutate({ + mutation: REMOVE_ROLE_USER, + variables: { ...params }, + }); + return response.data; + } +} diff --git a/src/modules/users/index.ts b/src/modules/users/index.ts index d9c456e8..d33e12f0 100644 --- a/src/modules/users/index.ts +++ b/src/modules/users/index.ts @@ -19,7 +19,7 @@ import { WhereCondition, RoleData, MultiUpload, - Roles, + RolesEnum, } from '../../types'; export class Users { @@ -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; } diff --git a/src/mutations/app.mutation.ts b/src/mutations/app.mutation.ts index b5aa5bec..b0e3712c 100644 --- a/src/mutations/app.mutation.ts +++ b/src/mutations/app.mutation.ts @@ -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 diff --git a/src/mutations/index.ts b/src/mutations/index.ts index 1fbddcbd..70fb2f5b 100644 --- a/src/mutations/index.ts +++ b/src/mutations/index.ts @@ -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"; \ No newline at end of file +export * from './userList.mutation'; +export * from './channels.mutation'; +export * from './roles.mutation'; diff --git a/src/mutations/roles.mutation.ts b/src/mutations/roles.mutation.ts new file mode 100644 index 00000000..3cfb42de --- /dev/null +++ b/src/mutations/roles.mutation.ts @@ -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) + } +`; diff --git a/src/queries/index.ts b/src/queries/index.ts index de5b21b6..abdd9218 100644 --- a/src/queries/index.ts +++ b/src/queries/index.ts @@ -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'; \ No newline at end of file +export * from './messages.query'; +export * from './roles.query'; \ No newline at end of file diff --git a/src/queries/roles.query.ts b/src/queries/roles.query.ts new file mode 100644 index 00000000..275f0157 --- /dev/null +++ b/src/queries/roles.query.ts @@ -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 + } + } + } +`; diff --git a/src/types/app.ts b/src/types/app.ts index e8425ac3..20340a0d 100644 --- a/src/types/app.ts +++ b/src/types/app.ts @@ -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; } diff --git a/src/types/inventory.ts b/src/types/inventory.ts index 55cc83e7..10dbadbe 100644 --- a/src/types/inventory.ts +++ b/src/types/inventory.ts @@ -254,6 +254,7 @@ export interface CreateProductParams { variants?: ProductVariant[]; price?: number; attributes?: ProductAttributes[]; + company_id?: number | string; } export interface AllCreatedProducts { diff --git a/src/types/roles.ts b/src/types/roles.ts index f48515a1..7a4d539f 100644 --- a/src/types/roles.ts +++ b/src/types/roles.ts @@ -1,4 +1,4 @@ -export enum Roles { +export enum RolesEnum { OWNER = 'Owner', ADMIN = 'Admin', USER = 'Users', @@ -6,3 +6,29 @@ export enum Roles { 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; +}