Skip to content

Commit

Permalink
[nan-239] fix types and use uppercase (NangoHQ#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
khaliqgant authored Jan 15, 2024
1 parent e08257e commit 0a583e1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const args = process.argv.slice(2);
const nango = new Nango({ host: 'http://localhost:3003', secretKey: args[0] });

nango
.getRecords({
.listRecords({
providerConfigKey: args[1],
connectionId: args[2],
model: args[3]
model: args[3],
filter: args[4]
})
.then((response) => {
console.log(response);
Expand Down
2 changes: 1 addition & 1 deletion packages/node-client/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface NangoSyncWebhookBody {
queryTimeStamp: string | null;
}

export type LastAction = 'added' | 'updated' | 'deleted';
export type LastAction = 'ADDED' | 'UPDATED' | 'DELETED';

export interface RecordMetadata {
first_seen_at: Date;
Expand Down
2 changes: 1 addition & 1 deletion packages/node-client/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface ProxyConfiguration {
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream';
}

type FilterAction = 'added' | 'updated' | 'deleted';
type FilterAction = 'added' | 'updated' | 'deleted' | 'ADDED' | 'UPDATED' | 'DELETED';
type CombinedFilterAction = `${FilterAction},${FilterAction}`;

export interface GetRecordsRequestConfig {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib/models/Sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export interface DataRecord extends Timestamps {
pending_delete?: boolean;
}

export type LastAction = 'added' | 'updated' | 'deleted';
export type LastAction = 'ADDED' | 'UPDATED' | 'DELETED' | 'added' | 'updated' | 'deleted';

interface RecordMetadata {
first_seen_at: Date;
Expand Down
33 changes: 18 additions & 15 deletions packages/shared/lib/services/sync/data/records.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {
RecordWrapCustomerFacingDataRecord,
CustomerFacingDataRecord,
DataRecordWithMetadata,
GetRecordsResponse
GetRecordsResponse,
LastAction
} from '../../../models/Sync.js';
import type { DataResponse } from '../../../models/Data.js';
import type { ServiceResponse } from '../../../models/Generic.js';
Expand Down Expand Up @@ -95,7 +96,7 @@ export async function getDataRecords(
limit?: number | string,
sortBy?: string,
order?: 'asc' | 'desc',
filter?: 'added' | 'updated' | 'deleted',
filter?: LastAction,
includeMetaData = false
): Promise<ServiceResponse<CustomerFacingDataRecord[] | DataRecordWithMetadata[] | null>> {
if (!model) {
Expand Down Expand Up @@ -245,29 +246,30 @@ export async function getDataRecords(
}

if (filter) {
const formattedFilter = filter.toUpperCase();
switch (true) {
case filter.includes('added') && filter.includes('updated'):
case formattedFilter.includes('ADDED') && formattedFilter.includes('UPDATED'):
query = query.andWhere('external_deleted_at', null).andWhere(function () {
this.where('created_at', '=', db.knex.raw('updated_at')).orWhere('created_at', '!=', db.knex.raw('updated_at'));
});
break;
case filter.includes('updated') && filter.includes('deleted'):
case formattedFilter.includes('UPDATED') && formattedFilter.includes('DELETED'):
query = query.andWhere(function () {
this.where('external_is_deleted', true).orWhere('external_deleted_at', null).andWhere('created_at', '!=', db.knex.raw('updated_at'));
});
break;
case filter.includes('added') && filter.includes('deleted'):
case formattedFilter.includes('ADDED') && formattedFilter.includes('DELETED'):
query = query.andWhere(function () {
this.where('external_is_deleted', true).orWhere('external_deleted_at', null).andWhere('created_at', '=', db.knex.raw('updated_at'));
});
break;
case filter === 'added':
case formattedFilter === 'ADDED':
query = query.andWhere('external_deleted_at', null).andWhere('created_at', '=', db.knex.raw('updated_at'));
break;
case filter === 'updated':
case formattedFilter === 'UPDATED':
query = query.andWhere('external_deleted_at', null).andWhere('created_at', '!=', db.knex.raw('updated_at'));
break;
case filter === 'deleted':
case formattedFilter === 'DELETED':
query = query.andWhere({ external_is_deleted: true });
break;
}
Expand Down Expand Up @@ -333,7 +335,7 @@ export async function getAllDataRecords(
model: string,
delta?: string,
limit?: number | string,
filter?: 'added' | 'updated' | 'deleted',
filter?: LastAction,
cursorValue?: string | null
): Promise<ServiceResponse<GetRecordsResponse>> {
try {
Expand Down Expand Up @@ -409,29 +411,30 @@ export async function getAllDataRecords(
}

if (filter) {
const formattedFilter = filter.toUpperCase();
switch (true) {
case filter.includes('added') && filter.includes('updated'):
case formattedFilter.includes('ADDED') && formattedFilter.includes('UPDATED'):
query = query.andWhere('external_deleted_at', null).andWhere(function () {
this.where('created_at', '=', db.knex.raw('updated_at')).orWhere('created_at', '!=', db.knex.raw('updated_at'));
});
break;
case filter.includes('updated') && filter.includes('deleted'):
case formattedFilter.includes('UPDATED') && formattedFilter.includes('DELETED'):
query = query.andWhere(function () {
this.where('external_is_deleted', true).orWhere('external_deleted_at', null).andWhere('created_at', '!=', db.knex.raw('updated_at'));
});
break;
case filter.includes('added') && filter.includes('deleted'):
case formattedFilter.includes('ADDED') && formattedFilter.includes('DELETED'):
query = query.andWhere(function () {
this.where('external_is_deleted', true).orWhere('external_deleted_at', null).andWhere('created_at', '=', db.knex.raw('updated_at'));
});
break;
case filter === 'added':
case formattedFilter === 'ADDED':
query = query.andWhere('external_deleted_at', null).andWhere('created_at', '=', db.knex.raw('updated_at'));
break;
case filter === 'updated':
case formattedFilter === 'UPDATED':
query = query.andWhere('external_deleted_at', null).andWhere('created_at', '!=', db.knex.raw('updated_at'));
break;
case filter === 'deleted':
case formattedFilter === 'DELETED':
query = query.andWhere({ external_is_deleted: true });
break;
}
Expand Down

0 comments on commit 0a583e1

Please sign in to comment.