From 9bfc270d2f21788b6fba83ef12714df0b32ff967 Mon Sep 17 00:00:00 2001 From: Samuel Imolorhe Date: Sat, 2 Dec 2023 00:08:48 +0100 Subject: [PATCH] pass extra collection fields to remote --- packages/altair-api-utils/src/query.ts | 5 ++++ .../dto/create-query-collection.dto.ts | 26 +++++++++++++++++++ .../query-collections.service.ts | 14 ++++++++++ .../altair/services/api/api.service.ts | 24 +++++++++++++++-- .../altair/store/async-storage-sync.ts | 6 ++++- packages/altair-electron/src/updates.ts | 6 ++--- 6 files changed, 75 insertions(+), 6 deletions(-) diff --git a/packages/altair-api-utils/src/query.ts b/packages/altair-api-utils/src/query.ts index 91f03c7752..e5d844ad11 100644 --- a/packages/altair-api-utils/src/query.ts +++ b/packages/altair-api-utils/src/query.ts @@ -10,6 +10,11 @@ export interface ICreateQueryCollectionDto { queries?: Omit[]; workspaceId?: string; teamId?: string; + description?: string; + preRequestScript?: string; + preRequestScriptEnabled?: boolean; + postRequestScript?: string; + postRequestScriptEnabled?: boolean; } export type IUpdateQueryCollectionDto = Partial; diff --git a/packages/altair-api/src/query-collections/dto/create-query-collection.dto.ts b/packages/altair-api/src/query-collections/dto/create-query-collection.dto.ts index 25727e0425..8bf906c78b 100644 --- a/packages/altair-api/src/query-collections/dto/create-query-collection.dto.ts +++ b/packages/altair-api/src/query-collections/dto/create-query-collection.dto.ts @@ -5,6 +5,7 @@ import { IsNotEmpty, IsOptional, IsString, + IsBoolean, ValidateNested, } from 'class-validator'; import { CreateQuerySansCollectionIdDto } from 'src/queries/dto/create-query.dto'; @@ -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; } diff --git a/packages/altair-api/src/query-collections/query-collections.service.ts b/packages/altair-api/src/query-collections/query-collections.service.ts index b95a4ddcef..c48b393882 100644 --- a/packages/altair-api/src/query-collections/query-collections.service.ts +++ b/packages/altair-api/src/query-collections/query-collections.service.ts @@ -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 }); @@ -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) { diff --git a/packages/altair-app/src/app/modules/altair/services/api/api.service.ts b/packages/altair-app/src/app/modules/altair/services/api/api.service.ts index 55832fa61f..08469cda8d 100644 --- a/packages/altair-app/src/app/modules/altair/services/api/api.service.ts +++ b/packages/altair-app/src/app/modules/altair/services/api/api.service.ts @@ -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({ @@ -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, }); } @@ -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, }); } diff --git a/packages/altair-app/src/app/modules/altair/store/async-storage-sync.ts b/packages/altair-app/src/app/modules/altair/store/async-storage-sync.ts index 76fce8fa53..cd4b5466bf 100644 --- a/packages/altair-app/src/app/modules/altair/store/async-storage-sync.ts +++ b/packages/altair-app/src/app/modules/altair/store/async-storage-sync.ts @@ -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; } diff --git a/packages/altair-electron/src/updates.ts b/packages/altair-electron/src/updates.ts index c1361c81be..699e39ce83 100644 --- a/packages/altair-electron/src/updates.ts +++ b/packages/altair-electron/src/updates.ts @@ -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() @@ -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) => { @@ -93,5 +93,5 @@ export const checkForUpdates = (menuItem: MenuItem) => { updater.enabled = false; } isSilentCheck = false; - autoUpdater.checkForUpdates(); + autoUpdater.checkForUpdates().catch((err) => console.error(err)); };