Skip to content

Commit

Permalink
pass extra collection fields to remote
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Dec 1, 2023
1 parent d48c89c commit 9bfc270
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/altair-api-utils/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export interface ICreateQueryCollectionDto {
queries?: Omit<ICreateQueryDto, 'collectionId'>[];
workspaceId?: string;
teamId?: string;
description?: string;
preRequestScript?: string;
preRequestScriptEnabled?: boolean;
postRequestScript?: string;
postRequestScriptEnabled?: boolean;
}

export type IUpdateQueryCollectionDto = Partial<ICreateQueryCollectionDto>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IsNotEmpty,
IsOptional,
IsString,
IsBoolean,
ValidateNested,
} from 'class-validator';
import { CreateQuerySansCollectionIdDto } from 'src/queries/dto/create-query.dto';
Expand Down Expand Up @@ -32,4 +33,29 @@ export class CreateQueryCollectionDto implements ICreateQueryCollectionDto {
@IsNotEmpty()
@ApiProperty()
teamId?: string;

@IsString()
@IsOptional()
@ApiProperty()
description?: string;

@IsString()
@IsOptional()
@ApiProperty()
preRequestScript?: string;

@IsBoolean()
@IsOptional()
@ApiProperty()
preRequestScriptEnabled?: boolean;

@IsString()
@IsOptional()
@ApiProperty()
postRequestScript?: string;

@IsBoolean()
@IsOptional()
@ApiProperty()
postRequestScriptEnabled?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ export class QueryCollectionsService {
queries: {
create: createQueryCollectionDtoQueries,
},
description: createQueryCollectionDto.description,
preRequestScript: createQueryCollectionDto.preRequestScript,
preRequestScriptEnabled:
createQueryCollectionDto.preRequestScriptEnabled,
postRequestScript: createQueryCollectionDto.postRequestScript,
postRequestScriptEnabled:
createQueryCollectionDto.postRequestScriptEnabled,
},
});
this.eventService.emit(EVENTS.COLLECTION_UPDATE, { id: res.id });
Expand Down Expand Up @@ -145,6 +152,13 @@ export class QueryCollectionsService {
},
data: {
name: updateQueryCollectionDto.name,
description: updateQueryCollectionDto.description,
preRequestScript: updateQueryCollectionDto.preRequestScript,
preRequestScriptEnabled:
updateQueryCollectionDto.preRequestScriptEnabled,
postRequestScript: updateQueryCollectionDto.postRequestScript,
postRequestScriptEnabled:
updateQueryCollectionDto.postRequestScriptEnabled,
},
});
if (res.count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ const serverCollectionToLocalCollection = (
queries: collection.queries.map(serverQueryToLocalQuery),
storageType: 'api',
workspaceId: collection.workspaceId,
description: collection.description ?? '',
preRequest: {
script: collection.preRequestScript ?? '',
enabled: collection.preRequestScriptEnabled,
},
postRequest: {
script: collection.postRequestScript ?? '',
enabled: collection.postRequestScriptEnabled,
},
};
};
@Injectable({
Expand All @@ -58,6 +67,11 @@ export class ApiService {
name: q.windowName,
content: q,
})),
description: queryCollection.description,
preRequestScript: queryCollection.preRequest?.script,
preRequestScriptEnabled: queryCollection.preRequest?.enabled,
postRequestScript: queryCollection.postRequest?.script,
postRequestScriptEnabled: queryCollection.postRequest?.enabled,
});
}

Expand Down Expand Up @@ -91,14 +105,20 @@ export class ApiService {
) {
return await apiClient.updateCollection(collectionServerId, {
name: collection.title,

queries: collection.queries.map((q) => ({
name: q.windowName,
content: {
...q,
collectionId: q.collectionId || '',
collectionId: q.collectionId ?? '',
},
collectionId: q.collectionId || '',
collectionId: q.collectionId ?? '',
})),
description: collection.description,
preRequestScript: collection.preRequest?.script,
preRequestScriptEnabled: collection.preRequest?.enabled,
postRequestScript: collection.postRequest?.script,
postRequestScriptEnabled: collection.postRequest?.enabled,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ const syncStateUpdate = async () => {
try {
if (syncTransaction) {
debug.log('Deliberately aborting any current transaction');
syncTransaction.abort();
try {
syncTransaction.abort();
} catch {
// ignore
}
syncTransaction = null;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/altair-electron/src/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let updater: MenuItem | undefined;
let isSilentCheck = true;
autoUpdater.autoDownload = false;

autoUpdater.on('error', error => {
autoUpdater.on('error', (error) => {
dialog.showErrorBox(
'Error: ',
!!error === null ? 'unknown' : (error.stack || error).toString()
Expand Down Expand Up @@ -64,7 +64,7 @@ export const setupAutoUpdates = () => {
log.transports.file.level = 'info';
autoUpdater.logger = log;
// autoUpdater.checkForUpdatesAndNotify();
autoUpdater.checkForUpdates();
autoUpdater.checkForUpdates().catch((err) => console.error(err));
};

// autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
Expand Down Expand Up @@ -93,5 +93,5 @@ export const checkForUpdates = (menuItem: MenuItem) => {
updater.enabled = false;
}
isSilentCheck = false;
autoUpdater.checkForUpdates();
autoUpdater.checkForUpdates().catch((err) => console.error(err));
};

0 comments on commit 9bfc270

Please sign in to comment.