Skip to content

Commit

Permalink
Merge pull request #142 from bakaphp/feat/app-settings
Browse files Browse the repository at this point in the history
feat(settings): add method to fetch app settings
  • Loading branch information
RivierGrullon authored Jan 11, 2024
2 parents 75a330a + 402ca17 commit 3063799
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 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.76",
"version": "0.0.77",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
16 changes: 14 additions & 2 deletions src/modules/settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import {
APP_SETTINGS_QUERY,
AppSettingsQuery,
CompanySettingsQuery,
ConfigInput,
USERS_SETTINGS_QUERY,
} from '../../queries';
import {
AppSettingsQueryResponse,
AppSettingsResponse,
ClientType,
CompanySettingsResponse,
SettingsResponse,
userSettingsResponse,
UserSettingsResponse,
} from '../../index';
import { SET_USER_SETTINGS_MUTATION } from '../../mutations';

export default class Settings {
constructor(protected client: ClientType, protected key: string) {}

async fetchAppSettings(): Promise<AppSettingsQueryResponse | undefined> {
try {
const { data } = await this.client.query({
query: APP_SETTINGS_QUERY,
});
return data;
} catch {
return undefined;
}
}
async getAppSettings(): Promise<SettingsResponse | undefined> {
try {
const {
Expand Down Expand Up @@ -47,7 +59,7 @@ export default class Settings {

async getUserSettings(
entity_uuid: string
): Promise<userSettingsResponse | undefined> {
): Promise<UserSettingsResponse | undefined> {
try {
const { data } = await this.client.query({
query: USERS_SETTINGS_QUERY,
Expand Down
9 changes: 9 additions & 0 deletions src/queries/settings.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,12 @@ export const USERS_SETTINGS_QUERY = gql`
}
}
`;

export const APP_SETTINGS_QUERY = gql`
query {
appSettings {
key
value
}
}
`;
6 changes: 5 additions & 1 deletion src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export interface CompanySettingsResponse<T = any> {
companySettings: SettingsResponse<T>;
}

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

export interface AppSettingsQueryResponse {
appSettings: Array<{ key: string; value: any }>;
}

0 comments on commit 3063799

Please sign in to comment.