Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
chore: Minor typing optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjuaneight committed Jul 27, 2022
1 parent cc040c3 commit 9e875d1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/bookmark-tweets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const getTweetDetails = async (url: string): Promise<TwitterData> => {
const cleanText = await expandShortLink(
formattedText,
/(https:\/\/t.co\/[a-zA-z0-9]+)/g
)
);
const tweet = cleanText
.replace(//g, `"`)
.replace(//g, `"`)
Expand Down
25 changes: 13 additions & 12 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
CountColumn,
RecordData,
RequestPayload,
TableAggregate,
TablesAggregate,
} from './typings.d';

// default responses
Expand Down Expand Up @@ -73,6 +73,7 @@ const tagsList: {
const handleAction = async (payload: RequestPayload): Promise<Response> => {
// payload data is present at time point
const data: RecordData = payload.type === 'Insert' ? payload.data : {};
const fmtTable = payload.table.toLowerCase();
// default helps to determine if switch statement runs and correct table is used
let location: string = 'None';
let response: BookmarkingResponse;
Expand All @@ -96,9 +97,9 @@ const handleAction = async (payload: RequestPayload): Promise<Response> => {
);
}
case payload.type === 'Query': {
location = `${payload.type}-${payload.table}`;
location = `${payload.type}-${fmtTable}`;

const queryResults = await queryBookmarkItems(payload.table);
const queryResults = await queryBookmarkItems(fmtTable);

return new Response(
JSON.stringify({
Expand All @@ -109,10 +110,10 @@ const handleAction = async (payload: RequestPayload): Promise<Response> => {
);
}
case payload.type === 'Search': {
location = `${payload.type}-${payload.table}`;
location = `${payload.type}-${fmtTable}`;

const searchResults = await searchBookmarkItems(
payload.table,
fmtTable,
payload.query ?? '',
payload.column ?? ''
);
Expand All @@ -126,10 +127,10 @@ const handleAction = async (payload: RequestPayload): Promise<Response> => {
);
}
case payload.type === 'Count': {
location = `${payload.type}-${payload.table}`;
location = `${payload.type}-${fmtTable}`;

const queryResults = await queryBookmarkAggregateCount(
payload.table as TableAggregate,
fmtTable as TablesAggregate,
payload.countColumn as CountColumn
);

Expand All @@ -142,23 +143,23 @@ const handleAction = async (payload: RequestPayload): Promise<Response> => {
);
}
case payload.table === 'Podcasts':
location = payload.table;
location = fmtTable;
response = await bookmarkPodcasts(data.url, data.tags);
break;
case payload.table === 'Reddits':
location = payload.table;
location = fmtTable;
response = await bookmarkReddits(data.url, data.tags);
break;
case payload.table === 'StackExchange':
location = payload.table;
location = fmtTable;
response = await bookmarkStackExchange(data.url, data.tags);
break;
case payload.table === 'Tweets':
location = payload.table;
location = fmtTable;
response = await bookmarkTweets(data.url, data.tags);
break;
case payload.table === 'Videos':
location = payload.table;
location = fmtTable;

if (data.url.includes('vimeo')) {
response = await bookmarkVimeo(data.url, data.tags);
Expand Down
6 changes: 3 additions & 3 deletions src/hasura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CountColumn,
RecordColumnAggregateCount,
RecordData,
TableAggregate,
TablesAggregate,
} from './typings.d';

const BK_FIELDS = {
Expand Down Expand Up @@ -158,12 +158,12 @@ export const queryBookmarkItems = async (
* @function
* @async
*
* @param {string} table
* @param {TablesAggregate} table
* @param {CountColumn} column
* @returns {Promise<RecordColumnAggregateCount>}
*/
export const queryBookmarkAggregateCount = async (
table: TableAggregate,
table: TablesAggregate,
column: CountColumn
): Promise<RecordColumnAggregateCount> => {
const sort = column === 'tags' ? 'title' : column;
Expand Down
16 changes: 13 additions & 3 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,23 +1139,33 @@ export type CountColumn =
| 'tags'
| 'user';

export type TableAggregate =
export type TablesAggregate =
| 'articles'
| 'comics'
| 'podcasts'
| 'reddits'
| 'tweets'
| 'videos';

export type Tables =
| 'Articles'
| 'Comics'
| 'Podcasts'
| 'Reddits'
| 'Tweets'
| 'Videos';

export interface BookmarkingResponse {
success: boolean;
message: string;
source: string;
}

export type Types = 'Count' | 'Tags' | 'Query' | 'Search' | 'Insert' | 'Update';

export interface RequestPayload {
type: string;
table: string;
type: Types;
table: Tables;
tagList?: string;
query?: string;
column?: string;
Expand Down

0 comments on commit 9e875d1

Please sign in to comment.