Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bakaphp/kanvas-core-js into AP-309
Browse files Browse the repository at this point in the history
  • Loading branch information
FredPeal committed Jan 15, 2024
2 parents 9373711 + 3063799 commit d6a5410
Show file tree
Hide file tree
Showing 7 changed files with 55 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.75",
"version": "0.0.77",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
23 changes: 16 additions & 7 deletions src/modules/companies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,31 @@ import {
CompanyInput,
CompanyInterface,
CompanySettings,
WhereCondition
WhereCondition,
OrderBy,
CreatedCompanies
} from '../../types';

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

public async getCompanies(
where: WhereCondition,
first?: number,
page?: number
): Promise<CompanyInterface> {
options: {
first?: number;
page?: number;
where?: WhereCondition;
orderBy?: OrderBy[];
} = {}
): Promise<CreatedCompanies> {
const { first, page, where, orderBy } = options;

const response = await this.client.query({
query: COMPANIES_QUERY,
variables: { where, first, page },
variables: { where, first, page, orderBy },
fetchPolicy: 'network-only',
partialRefetch: true,
});
return response.data as CompanyInterface;
return response.data;
}

public async getCompanyUsers(
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
5 changes: 2 additions & 3 deletions src/queries/companies.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export const COMPANIES_QUERY = gql`
query companies(
$where: QueryCompaniesWhereWhereConditions
$orderBy: [QueryCompaniesOrderByOrderByClause!]
$first: Int!
$page: Int!
$first: Int
$page: Int
) {
companies(where: $where, orderBy: $orderBy, first: $first, page: $page) {
data {
Expand Down Expand Up @@ -39,7 +39,6 @@ export const COMPANIES_QUERY = gql`
}
groups {
id
uuid
name
}
branches {
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
}
}
`;
8 changes: 8 additions & 0 deletions src/types/companies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UserInterface } from 'index';
import { PaginatorInfo } from './paginator';

export interface CompanyInterface {
id: string;
Expand Down Expand Up @@ -57,3 +58,10 @@ export interface CompanySettings {
name: string;
settings: any;
}

export interface CreatedCompanies {
companies: {
data: CompanyInterface[];
paginatorInfo?: PaginatorInfo;
};
}
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 d6a5410

Please sign in to comment.