Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bakaphp/kanvas-core-js into message…
Browse files Browse the repository at this point in the history
…s-types
  • Loading branch information
FredPeal committed Jan 8, 2024
2 parents ea3b063 + ae8ba1c commit ffee437
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 27 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.73",
"version": "0.0.75",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
17 changes: 12 additions & 5 deletions src/modules/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
FILESYSTEM,
SystemModuleEntityInput,
WhereCondition,
FILESYSTEM_ATTACH_INPUT
FILESYSTEM_ATTACH_INPUT,
} from '../../types';
import { ATTACH_FILE_MUTATION, DETACH_FILE_MUTATION } from '../../mutations';
import { ENTITY_FILES_QUERY } from '../../queries';
Expand Down Expand Up @@ -77,18 +77,25 @@ export class FileSystem {
return response.data.deAttachFiles as boolean;
}

public async uploadFile(data: any): Promise<UPLOAD_INTERFACE> {
public async uploadFile(data: File): Promise<UPLOAD_INTERFACE> {
if (!this.options || !this.axiosClient)
throw new Error('FileSystem module not initialized');

const formData = new FormData();
formData.append(
'operations',
'{ "query": "mutation ($file: Upload!) { upload(file: $file) {id, uuid, name, url } }"}'
JSON.stringify({
query:
'mutation ($file: Upload!) { upload(file: $file) {id, uuid, name, url } }',
variables: {
file: null,
},
})
);
formData.append('map', '{"0": ["variables.file"]}');
formData.append('0', data);
formData.append('map', JSON.stringify({ '0': ['variables.file'] }));
formData.append('0', data, data.name);
let response = await this.axiosClient.post('', formData);

return response.data.data.upload as UPLOAD_INTERFACE;
}
}
2 changes: 1 addition & 1 deletion src/modules/leads/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Leads {
variables: { input: leadData },
});

return response.data as CreateLeadData;
return response.data.createLead as CreateLeadData;
}

public async getAllLeads(first?: number, page?: number): Promise<LeadsData> {
Expand Down
57 changes: 52 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,35 @@ 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 {
await this.client.mutate({
mutation: SET_USER_SETTINGS_MUTATION,
variables: {
input,
},
});
return true;
} catch {
return undefined;
}
}
}
26 changes: 25 additions & 1 deletion src/modules/system-modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,33 @@ import { SystemModuleInterface } from '../../types/';
export class SystemModules {
constructor(protected client: ClientType) {}

public async getSystemModules(): Promise<SystemModuleInterface[]> {
public async getSystemModules(
first: number,
page?: number
): Promise<SystemModuleInterface[]> {
const response = await this.client.query({
query: SYSTEM_MODULES_QUERY,
variables: {
first,
page,
},
});
return response.data.systemModels.data as SystemModuleInterface[];
}

public async getSystemModulesBySlug(
slug: string
): Promise<SystemModuleInterface[]> {
const response = await this.client.query({
query: SYSTEM_MODULES_QUERY,
variables: {
first: 1,
where: {
column: 'SLUG',
operator: 'EQ',
value: slug,
},
},
});
return response.data.systemModels.data as SystemModuleInterface[];
}
Expand Down
1 change: 1 addition & 0 deletions src/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './companies-branches.mutation';
export * from './follows.mutation';
export * from './people.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
}
}
`;
6 changes: 4 additions & 2 deletions src/queries/system-module.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { gql } from '@apollo/client/core';
export const SYSTEM_MODULES_QUERY = gql`
query systemModels(
$where: QuerySystemModelsWhereWhereConditions
$orderBy: [QuerySystemModelsOrderByOrderByClause]
$orderBy: [QuerySystemModelsOrderByOrderByClause!]
$first: Int!
$page: Int
) {
systemModels {
systemModels(where: $where, orderBy: $orderBy, first: $first, page: $page) {
data {
id
uuid
Expand All @@ -29,3 +29,5 @@ export const SYSTEM_MODULES_QUERY = gql`
}
}
`;


2 changes: 1 addition & 1 deletion src/types/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface FILESYSTEM_ATTACH_INPUT {
filesystem_uuid: string;
field_name: string;
system_module_uuid: string;
entity_uuid: string;
entity_id: string;
}

export interface FILESYSTEM {
Expand Down
8 changes: 4 additions & 4 deletions src/types/people.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export interface PeopleInputInterface {
address?: [AddressInputInterface];
}
export interface PeopleInterface {
id: string;
uuid: string;
id?: string;
uuid?: string;
name?: string;
firstname?: string;
lastname?: string;
company: CompanyInterface;
user: UserInterface;
company?: CompanyInterface;
user?: UserInterface;
contacts: ContactInterface[];
address?: AddressInterface[];
custom_fields?: CustomFieldInput[];
Expand Down
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 ffee437

Please sign in to comment.