Skip to content

Commit

Permalink
feat: add user settings config
Browse files Browse the repository at this point in the history
  • Loading branch information
RivierGrullon committed Jan 6, 2024
1 parent 8cbbc00 commit 323810e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 14 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.0.74",
"version": "0.0.75",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
59 changes: 54 additions & 5 deletions src/modules/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -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<SettingsResponse | undefined> {
try {
const { data: { getAppSettings } } = await this.client.query<AppSettingsResponse>({
const {
data: { getAppSettings },
} = await this.client.query<AppSettingsResponse>({
query: AppSettingsQuery,
variables: { appKey: this.key },
fetchPolicy: 'no-cache',
Expand All @@ -19,7 +33,9 @@ export default class Settings {

async getCompanySettings(): Promise<SettingsResponse | undefined> {
try {
const { data: { companySettings } } = await this.client.query<CompanySettingsResponse>({
const {
data: { companySettings },
} = await this.client.query<CompanySettingsResponse>({
query: CompanySettingsQuery,
fetchPolicy: 'no-cache',
});
Expand All @@ -28,4 +44,37 @@ export default class Settings {
return undefined;
}
}
}

async getUserSettings(
entity_uuid: string
): Promise<userSettingsResponse | undefined> {
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<boolean | undefined> {
try {
const data = this.client.mutate({
mutation: SET_USER_SETTINGS_MUTATION,
variables: {
input,
},
});
console.log(data);
// return data;
return true;
} catch {
return undefined;
}
}
}
3 changes: 2 additions & 1 deletion src/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
export * from './message-comment.mutation';
export * from './settings.mutation';
13 changes: 13 additions & 0 deletions src/mutations/settings.mutation.ts
Original file line number Diff line number Diff line change
@@ -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)
}
`;
22 changes: 18 additions & 4 deletions src/queries/settings.query.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
`;
`;

export const USERS_SETTINGS_QUERY = gql`
query userSettings($entityUUID: String!) {
userSettings(entity_uuid: $entityUUID) {
key
value
}
}
`;
10 changes: 7 additions & 3 deletions src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ export interface SettingsResponse<T = any> {
settings: T;
}

export interface AppSettingsResponse<T = any>{
export interface AppSettingsResponse<T = any> {
getAppSettings: SettingsResponse<T>;
};
}

export interface CompanySettingsResponse<T = any> {
companySettings: SettingsResponse<T>;
};
}

export interface userSettingsResponse {
userSettings: Array<{ key: string; value: any }>;
}

0 comments on commit 323810e

Please sign in to comment.