Skip to content

Commit

Permalink
fix!: updated incorrect types and routes (#789)
Browse files Browse the repository at this point in the history
* fix!: updated incorrect types and routes
SVCINT-2734

* fix: woops this should always be baseUrl
SVCINT-2734
  • Loading branch information
pathiery authored Jan 17, 2024
1 parent 4f2b0a2 commit b357a81
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 67 deletions.
9 changes: 9 additions & 0 deletions src/resources/BaseInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ export type PageModel<T = any, TItemsKey extends string = 'items'> = {

export type New<T, K extends keyof T | null = null> = Omit<T, 'id' | NonNullable<K>>;

export type NewHostedInterface<T, K extends keyof T | null = null> = Omit<
Partial<T> & {name: string},
'id' | 'created' | 'createdBy' | 'updated' | 'updatedBy' | NonNullable<K>
>;
export type ExistingHostedInterface<T, K extends keyof T | null = null> = Omit<
T,
'id' | 'created' | 'createdBy' | 'updated' | 'updatedBy' | NonNullable<K>
>;

export interface IdAndDisplayNameModel {
id: string;
displayName?: string;
Expand Down
15 changes: 6 additions & 9 deletions src/resources/IPXInterfaces/IPXInterface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import API from '../../APICore.js';
import {New, PageModel} from '../BaseInterfaces.js';
import {ExistingHostedInterface, NewHostedInterface, PageModel} from '../BaseInterfaces.js';
import {ListHostedInterfacesParams} from '../HostedInterfacesCore/index.js';
import Resource from '../Resource.js';
import {IPXInterfaceConfiguration} from './IPXInterface.model.js';
Expand All @@ -11,7 +11,7 @@ export default class IPXInterface extends Resource {
return this.api.get<PageModel<IPXInterfaceConfiguration>>(this.buildPath(IPXInterface.baseUrl, options));
}

create(ipxInterfaceConfig: New<IPXInterfaceConfiguration>) {
create(ipxInterfaceConfig: NewHostedInterface<IPXInterfaceConfiguration>) {
return this.api.post<IPXInterfaceConfiguration>(IPXInterface.baseUrl, ipxInterfaceConfig);
}

Expand All @@ -23,19 +23,16 @@ export default class IPXInterface extends Resource {
return this.api.get<IPXInterfaceConfiguration>(`${IPXInterface.baseUrl}/${ipxInterfaceId}`);
}

update(ipxInterfaceConfig: IPXInterfaceConfiguration) {
return this.api.put<IPXInterfaceConfiguration>(
`${IPXInterface.baseUrl}/${ipxInterfaceConfig.id}`,
ipxInterfaceConfig,
);
update(ipxInterfaceId: string, ipxInterfaceConfig: NewHostedInterface<IPXInterfaceConfiguration>) {
return this.api.put<IPXInterfaceConfiguration>(`${IPXInterface.baseUrl}/${ipxInterfaceId}`, ipxInterfaceConfig);
}

getLoader(ipxInterfaceId: string) {
return this.api.get<IPXInterfaceConfiguration>(`${IPXInterface.baseUrl}/${ipxInterfaceId}/loader`);
}

generatePreview(ipxInterfaceConfig: IPXInterfaceConfiguration) {
return this.api.post<string>(`${IPXInterface.baseUrl}/${ipxInterfaceConfig.id}/preview`, ipxInterfaceConfig);
generatePreview(ipxId: string, ipxInterfaceConfig: ExistingHostedInterface<IPXInterfaceConfiguration>) {
return this.api.post<string>(`${IPXInterface.baseUrl}/${ipxId}/preview`, ipxInterfaceConfig);
}

getEditInterface(ipxInterfaceId: string) {
Expand Down
8 changes: 4 additions & 4 deletions src/resources/IPXInterfaces/tests/IPXInterface.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ describe('IPXInterface', () => {
it('should make an UPDATE call to the IPXInterface base url', () => {
const id = 'IPInterface-id-to-update';

ipxInterface.update({...config, id});
ipxInterface.update(id, config);

expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(`${IPXInterface.baseUrl}/${id}`, {...config, id});
expect(api.put).toHaveBeenCalledWith(`${IPXInterface.baseUrl}/${id}`, config);
});
});

Expand Down Expand Up @@ -204,10 +204,10 @@ describe('IPXInterface', () => {
it('should make a POST call to the IPXInterface base url appended with /preview', () => {
const id = 'IPInterface-id-to-preview';

ipxInterface.generatePreview({...config, id});
ipxInterface.generatePreview(id, config);

expect(api.post).toHaveBeenCalledTimes(1);
expect(api.post).toHaveBeenCalledWith(`${IPXInterface.baseUrl}/${id}/preview`, {...config, id});
expect(api.post).toHaveBeenCalledWith(`${IPXInterface.baseUrl}/${id}/preview`, config);
});
});

Expand Down
6 changes: 0 additions & 6 deletions src/resources/NextGenSearchPages/NextGenSearchPages.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
HostedInterfaceResultTemplateBadge,
IAccesses,
ISortCriteria,
New,
} from '../index.js';

export enum SearchPageResultActions {
Expand Down Expand Up @@ -155,8 +154,3 @@ export interface SearchPageInterfaceConfiguration extends Omit<HostedInterfaceCo
*/
updatedBy: string;
}

export type NewSearchPageInterfaceConfiguration = Omit<
New<SearchPageInterfaceConfiguration>,
'created' | 'createdBy' | 'updated' | 'updatedBy'
>;
58 changes: 33 additions & 25 deletions src/resources/NextGenSearchPages/NextGenSearchPages.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,92 @@
import API from '../../APICore.js';
import Resource from '../Resource.js';
import {IAccesses, ListHostedInterfacesParams, PageModel} from '../index.js';
import {NewSearchPageInterfaceConfiguration, SearchPageInterfaceConfiguration} from './NextGenSearchPages.model.js';
import {
ExistingHostedInterface,
IAccesses,
ListHostedInterfacesParams,
NewHostedInterface,
PageModel,
} from '../index.js';
import {SearchPageInterfaceConfiguration} from './NextGenSearchPages.model.js';

export default class NextGenSearchPages extends Resource {
static getBaseUrl = `/rest/organizations/${API.orgPlaceholder}/searchpage/v1/interfaces`;
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/searchpage/v1/interfaces`;

list(options?: ListHostedInterfacesParams): Promise<PageModel<SearchPageInterfaceConfiguration>> {
return this.api.get<PageModel<SearchPageInterfaceConfiguration>>(
this.buildPath(NextGenSearchPages.getBaseUrl, options),
this.buildPath(NextGenSearchPages.baseUrl, options),
);
}

create(searchPageConfiguration: NewSearchPageInterfaceConfiguration): Promise<SearchPageInterfaceConfiguration> {
return this.api.post<SearchPageInterfaceConfiguration>(NextGenSearchPages.getBaseUrl, searchPageConfiguration);
create(
searchPageConfiguration: NewHostedInterface<SearchPageInterfaceConfiguration>,
): Promise<SearchPageInterfaceConfiguration> {
return this.api.post<SearchPageInterfaceConfiguration>(NextGenSearchPages.baseUrl, searchPageConfiguration);
}

delete(searchPageId: string): Promise<void> {
return this.api.delete(`${NextGenSearchPages.baseUrl}/${searchPageId}`);
}

get(searchPageId: string): Promise<SearchPageInterfaceConfiguration> {
return this.api.get<SearchPageInterfaceConfiguration>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}`);
return this.api.get<SearchPageInterfaceConfiguration>(`${NextGenSearchPages.baseUrl}/${searchPageId}`);
}

update(
searchPageId: string,
searchPageConfiguration: NewSearchPageInterfaceConfiguration,
searchPageConfiguration: NewHostedInterface<SearchPageInterfaceConfiguration>,
): Promise<SearchPageInterfaceConfiguration> {
return this.api.put<SearchPageInterfaceConfiguration>(
`${NextGenSearchPages.getBaseUrl}/${searchPageId}`,
`${NextGenSearchPages.baseUrl}/${searchPageId}`,
searchPageConfiguration,
);
}

generatePreview(searchPageConfiguration: NewSearchPageInterfaceConfiguration & {id: string}): Promise<string> {
return this.api.post<string>(
`${NextGenSearchPages.getBaseUrl}/${searchPageConfiguration.id}/preview`,
searchPageConfiguration,
);
generatePreview(
searchPageId: string,
searchPageConfiguration: ExistingHostedInterface<SearchPageInterfaceConfiguration>,
): Promise<string> {
return this.api.post<string>(`${NextGenSearchPages.baseUrl}/${searchPageId}/preview`, searchPageConfiguration);
}

getView(searchPageId: string): Promise<string> {
return this.api.get<string>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/preview`);
return this.api.get<string>(`${NextGenSearchPages.baseUrl}/${searchPageId}/preview`);
}

getToken(searchPageId: string): Promise<{token: string}> {
return this.api.get<{token: string}>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/token`);
return this.api.get<{token: string}>(`${NextGenSearchPages.baseUrl}/${searchPageId}/token`);
}

getEditInterface(searchPageId: string): Promise<string> {
return this.api.get<string>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/edit`);
return this.api.get<string>(`${NextGenSearchPages.baseUrl}/${searchPageId}/edit`);
}

getLoader(searchPageId: string): Promise<string> {
return this.api.get<string>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/loader`);
return this.api.get<string>(`${NextGenSearchPages.baseUrl}/${searchPageId}/loader`);
}

getLoginPage(searchPageId: string): Promise<string> {
return this.api.get<string>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/login`);
return this.api.get<string>(`${NextGenSearchPages.baseUrl}/${searchPageId}/login`);
}

getAccesses(searchPageId: string): Promise<IAccesses> {
return this.api.get<IAccesses>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses`);
return this.api.get<IAccesses>(`${NextGenSearchPages.baseUrl}/${searchPageId}/accesses`);
}

updateAccesses(searchPageId: string, accesses: IAccesses): Promise<SearchPageInterfaceConfiguration> {
return this.api.put<SearchPageInterfaceConfiguration>(
`${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses`,
`${NextGenSearchPages.baseUrl}/${searchPageId}/accesses`,
accesses,
);
}

getAccessesUsers(searchPageId: string): Promise<string[]> {
return this.api.get<string[]>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses/users`);
return this.api.get<string[]>(`${NextGenSearchPages.baseUrl}/${searchPageId}/accesses/users`);
}

updateAccessesUsers(searchPageId: string, users: string[]): Promise<SearchPageInterfaceConfiguration> {
return this.api.put<SearchPageInterfaceConfiguration>(
`${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses/users`,
`${NextGenSearchPages.baseUrl}/${searchPageId}/accesses/users`,
users,
);
}
Expand All @@ -91,12 +99,12 @@ export default class NextGenSearchPages extends Resource {
): Promise<SearchPageInterfaceConfiguration> {
const body = message ? {users, message} : {users};
return this.api.post<SearchPageInterfaceConfiguration>(
`${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses/users${notify ? '?notify=1' : ''}`,
`${NextGenSearchPages.baseUrl}/${searchPageId}/accesses/users${notify ? '?notify=1' : ''}`,
body,
);
}

requestAccess(searchPageId: string): Promise<void> {
return this.api.post<void>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses/request`);
return this.api.post<void>(`${NextGenSearchPages.baseUrl}/${searchPageId}/accesses/request`);
}
}
Loading

0 comments on commit b357a81

Please sign in to comment.