diff --git a/package.json b/package.json index 578847e8..5b16a079 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.0.74", + "version": "0.0.75", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/modules/settings/index.tsx b/src/modules/settings/index.tsx index fa9beadc..d70ac8c4 100644 --- a/src/modules/settings/index.tsx +++ b/src/modules/settings/index.tsx @@ -1,12 +1,26 @@ -import { AppSettingsQuery, CompanySettingsQuery } from "../../queries"; -import { AppSettingsResponse, ClientType, CompanySettingsResponse, SettingsResponse } from "../../index"; +import { + AppSettingsQuery, + CompanySettingsQuery, + ConfigInput, + USERS_SETTINGS_QUERY, +} from '../../queries'; +import { + AppSettingsResponse, + ClientType, + CompanySettingsResponse, + SettingsResponse, + userSettingsResponse, +} from '../../index'; +import { SET_USER_SETTINGS_MUTATION } from '../../mutations'; export default class Settings { constructor(protected client: ClientType, protected key: string) {} async getAppSettings(): Promise { try { - const { data: { getAppSettings } } = await this.client.query({ + const { + data: { getAppSettings }, + } = await this.client.query({ query: AppSettingsQuery, variables: { appKey: this.key }, fetchPolicy: 'no-cache', @@ -19,7 +33,9 @@ export default class Settings { async getCompanySettings(): Promise { try { - const { data: { companySettings } } = await this.client.query({ + const { + data: { companySettings }, + } = await this.client.query({ query: CompanySettingsQuery, fetchPolicy: 'no-cache', }); @@ -28,4 +44,37 @@ export default class Settings { return undefined; } } -} \ No newline at end of file + + async getUserSettings( + entity_uuid: string + ): Promise { + try { + const { data } = await this.client.query({ + query: USERS_SETTINGS_QUERY, + fetchPolicy: 'no-cache', + variables: { + entityUUID: entity_uuid, + }, + }); + return data; + } catch { + return undefined; + } + } + + async setUserSettings(input: ConfigInput): Promise { + try { + const data = this.client.mutate({ + mutation: SET_USER_SETTINGS_MUTATION, + variables: { + input, + }, + }); + console.log(data); + // return data; + return true; + } catch { + return undefined; + } + } +} diff --git a/src/mutations/index.ts b/src/mutations/index.ts index 393caab3..daf2628b 100644 --- a/src/mutations/index.ts +++ b/src/mutations/index.ts @@ -16,4 +16,5 @@ export * from './companies.mutation'; export * from './companies-branches.mutation'; export * from './follows.mutation'; export * from './people.mutation'; -export * from './message-comment.mutation'; \ No newline at end of file +export * from './message-comment.mutation'; +export * from './settings.mutation'; diff --git a/src/mutations/settings.mutation.ts b/src/mutations/settings.mutation.ts new file mode 100644 index 00000000..4589bfc0 --- /dev/null +++ b/src/mutations/settings.mutation.ts @@ -0,0 +1,13 @@ +import { gql } from '@apollo/client/core'; + +export const SET_USER_SETTINGS_MUTATION = gql` + mutation setUserSetting($input: ModuleConfigInput!) { + setUserSetting(input: $input) + } +`; + +export const SET_APP_SETTINGS_MUTATION = gql` + mutation setAppSetting($input: ModuleConfigInput!) { + setAppSetting(input: $input) + } +`; diff --git a/src/queries/settings.query.ts b/src/queries/settings.query.ts index fbbcdb98..25826bec 100644 --- a/src/queries/settings.query.ts +++ b/src/queries/settings.query.ts @@ -1,20 +1,34 @@ import { gql } from '@apollo/client/core'; +export type ConfigInput = { + key: string; + value: any; + entity_uuid: string; +}; + export const AppSettingsQuery = gql` query getAppSettings($appKey: String!) { getAppSettings(key: $appKey) { - name, + name settings } } `; - export const CompanySettingsQuery = gql` query getCompanySettings { companySettings { - name, + name settings } } -`; \ No newline at end of file +`; + +export const USERS_SETTINGS_QUERY = gql` + query userSettings($entityUUID: String!) { + userSettings(entity_uuid: $entityUUID) { + key + value + } + } +`; diff --git a/src/types/settings.ts b/src/types/settings.ts index 363549d6..fb7b6516 100644 --- a/src/types/settings.ts +++ b/src/types/settings.ts @@ -3,10 +3,14 @@ export interface SettingsResponse { settings: T; } -export interface AppSettingsResponse{ +export interface AppSettingsResponse { getAppSettings: SettingsResponse; -}; +} export interface CompanySettingsResponse { companySettings: SettingsResponse; -}; \ No newline at end of file +} + +export interface userSettingsResponse { + userSettings: Array<{ key: string; value: any }>; +}