Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typings to queries #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
/dist
/dist
.idea
6 changes: 6 additions & 0 deletions src/Api/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Pageable {
perPage?: number;
next_page_cursor?: string;
prev_page_cursor?: string;
direction?: 'next' | 'prev';
}
12 changes: 6 additions & 6 deletions src/Api/portal-link.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Client } from '../client';
import { ResponseHelper } from '../utils/helpers/response-helper';
import { CreatePortalLink, UpdatePortalLink } from '../interfaces/portal-links';
import { CreatePortalLink, QueryPortalLinks, UpdatePortalLink } from '../interfaces/portal-links';

export class PortalLink {
private client: Client;
Expand All @@ -9,9 +9,9 @@ export class PortalLink {
this.client = client;
}

async create(attributes: CreatePortalLink, query?: any) {
async create(attributes: CreatePortalLink) {
try {
const { data } = await this.client.httpPost(`/portal-links`, attributes, query);
const { data } = await this.client.httpPost(`/portal-links`, attributes);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
Expand All @@ -27,7 +27,7 @@ export class PortalLink {
}
}

async all(query?: any) {
async all(query?: QueryPortalLinks) {
try {
const { data } = await this.client.httpGet(`/portal-links`, query);
return data;
Expand All @@ -36,9 +36,9 @@ export class PortalLink {
}
}

async update(id: string, attributes: UpdatePortalLink, query?: any) {
async update(id: string, attributes: UpdatePortalLink) {
try {
const { data } = await this.client.httpPut(`/portal-links/${id}`, attributes, query);
const { data } = await this.client.httpPut(`/portal-links/${id}`, attributes);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
Expand Down
8 changes: 4 additions & 4 deletions src/Api/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ export class Project {
}
}

async update(attributes: UpdateProject, query?: any) {
async update(attributes: UpdateProject) {
try {
const { data } = await this.client.httpPut(`/`, attributes, query);
const { data } = await this.client.httpPut(`/`, attributes);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
}
}

async delete(attributes?: any, query?: any) {
async delete(attributes?: any) {
try {
const { data } = await this.client.httpDelete(`/`, attributes, query);
const { data } = await this.client.httpDelete(`/`, attributes);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
Expand Down
20 changes: 10 additions & 10 deletions src/Api/source.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client } from '../client';
import { CreateSource, UpdateSource } from '../interfaces/source';
import { CreateSource, QuerySources, UpdateSource } from '../interfaces/source';
import { ResponseHelper } from '../utils/helpers/response-helper';

export class Source {
Expand All @@ -9,7 +9,7 @@ export class Source {
this.client = client;
}

async all(query?: any) {
async all(query?: QuerySources) {
try {
const { data } = await this.client.httpGet(`/sources`, query);
return data;
Expand All @@ -18,36 +18,36 @@ export class Source {
}
}

async create(attributes: CreateSource, query?: any) {
async create(attributes: CreateSource) {
try {
const { data } = await this.client.httpPost(`/sources`, attributes, query);
const { data } = await this.client.httpPost(`/sources`, attributes);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
}
}

async find(id: string, query?: any) {
async find(id: string) {
try {
const { data } = await this.client.httpGet(`/sources/${id}`, query);
const { data } = await this.client.httpGet(`/sources/${id}`);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
}
}

async update(id: string, attributes: UpdateSource, query?: any) {
async update(id: string, attributes: UpdateSource) {
try {
const { data } = await this.client.httpPut(`/sources/${id}`, attributes, query);
const { data } = await this.client.httpPut(`/sources/${id}`, attributes);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
}
}

async delete(id: string, attributes?: any, query?: any) {
async delete(id: string) {
try {
const { data } = await this.client.httpDelete(`/sources/${id}`, attributes, query);
const { data } = await this.client.httpDelete(`/sources/${id}`);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
Expand Down
16 changes: 8 additions & 8 deletions src/Api/subscription.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client } from '../client';
import { CreateSubscription, UpdateSubscription } from '../interfaces/subscription';
import { CreateSubscription, QuerySubscriptions, UpdateSubscription } from '../interfaces/subscription';
import { ResponseHelper } from '../utils/helpers/response-helper';

export class Subscription {
Expand All @@ -9,7 +9,7 @@ export class Subscription {
this.client = client;
}

async all(query?: any) {
async all(query?: QuerySubscriptions) {
try {
const { data } = await this.client.httpGet(`/subscriptions`, query);
return data;
Expand All @@ -18,9 +18,9 @@ export class Subscription {
}
}

async create(attributes: CreateSubscription, query?: any) {
async create(attributes: CreateSubscription) {
try {
const { data } = await this.client.httpPost(`/subscriptions`, attributes, query);
const { data } = await this.client.httpPost(`/subscriptions`, attributes);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
Expand All @@ -36,18 +36,18 @@ export class Subscription {
}
}

async update(id: string, attributes: UpdateSubscription, query?: any) {
async update(id: string, attributes: UpdateSubscription) {
try {
const { data } = await this.client.httpPut(`/subscriptions/${id}`, attributes, query);
const { data } = await this.client.httpPut(`/subscriptions/${id}`, attributes);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
}
}

async delete(id: string, attributes?: any, query?: any) {
async delete(id: string) {
try {
const { data } = await this.client.httpDelete(`/subscriptions/${id}`, attributes, query);
const { data } = await this.client.httpDelete(`/subscriptions/${id}`);
return data;
} catch (error) {
ResponseHelper.handleErrors(error);
Expand Down
13 changes: 12 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ export class Client {
}

private buildQueryParams(query: any) {
return new URLSearchParams(query).toString();
const params = new URLSearchParams();
for (const k of Object.keys(query)) {
if (Array.isArray(query[k])) {
for (let i = 0; i < query[k].length; i++) {
params.append(k, query[k][i]);
}
} else {
params.append(k, query[k]);
}
}

return params.toString();
}

private hasQueryParameters(query: any): boolean {
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/portal-links.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Pageable } from '../Api/common';

export interface CreatePortalLink {
name: string;
endpoints: string[];
Expand All @@ -6,3 +8,7 @@ export interface CreatePortalLink {
}

export interface UpdatePortalLink extends CreatePortalLink {}

export interface QueryPortalLinks extends Pageable {
endpointId?: string[];
}
7 changes: 7 additions & 0 deletions src/interfaces/source.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Pageable } from '../Api/common';

export interface CreateSource {
created_at: Date;
deleted_at: number;
Expand Down Expand Up @@ -31,3 +33,8 @@ export interface CreateSource {
}

export interface UpdateSource extends CreateSource {}

export interface QuerySources extends Pageable {
type?: string;
provider?: string;
}
6 changes: 6 additions & 0 deletions src/interfaces/subscription.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Pageable } from '../Api/common';

export interface CreateSubscription {
name: string;
type: 'cli' | 'api';
Expand All @@ -20,3 +22,7 @@ export interface CreateSubscription {
}

export interface UpdateSubscription extends CreateSubscription {}

export interface QuerySubscriptions extends Pageable {
endpointId?: string[];
}
Loading