generated from jsynowiec/node-typescript-boilerplate
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REFACTOR: Changed Data Model for storing data in Database (#4)
* FEATURE: Added PassiveSearch v1 - Added Connection to ElasticSearch - Added 2 API's - /ping and /passive - Keyword Search using /passive - Added Storing to DB capability when using /search * Fix: Added error handling -added error handling for passivesearch api endpoint * FEATURE: Added Simple Query String - Changed ElasticSearch Search type to Simple Query String * REFACTOR: Improved Active Search -Made Active Search make better use of downtimes (Rate Limits or Validation Downtime) * FIX: Issues with Active Search -Fixed errors with parrallel processing * FEATURE: Added SeedScript - Added RootQuery as an optional query param for activesearch which basically takes out the prompt builder and takes a raw query to look for in Github API. - Added Python SeedScript * REFACTOR: Changed Data Model for Storing in Database - Added other fields like LastUpdated, ETAG, URL, LastModified to Schema. - Added SHA hash as the unique parameter to not allow duplicates in the database * REFACTOR: Minor Log Refactor - Changed console.log to console.info / console.error * FIX: Storing only the reqd part of URL * FEATURE: Update API -Added PUT /database endpoint for updating the database - Changed name of the endpoints - Commented Database Trace Logs * FIX: Update API Fix + Global ElasticSearch and Octokit Clients - Fixed GetFileContents - Added Global variables for EsClient and Octokit for easy access and clean code - Better logs * FIX: Minor Comment * REFACTOR: UpdateAPI refactor - Update API Refactored * REFACTOR: Minor Fixes - Better API Naming - Fixed Update API
- Loading branch information
Showing
9 changed files
with
369 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,77 @@ | ||
export async function checkClusterHealth(esClient: any) : Promise<string> { | ||
try { | ||
const response = await esClient.cat.health(); | ||
console.log('Cluster health:', response); | ||
return response; | ||
} catch (error) { | ||
console.error('Error checking cluster health:', error); | ||
return ""; | ||
} | ||
} | ||
|
||
export async function BulkStoreToDB(validFiles: any,esClient: any) : Promise<void>{ | ||
try { | ||
if(validFiles.length == 0){ | ||
return; | ||
} | ||
const response = await esClient.bulk({ body: validFiles }); | ||
// console.log('Bulk response:', response); | ||
return response; | ||
} catch (error) { | ||
console.error('Error bulk indexing:', error); | ||
} | ||
} | ||
import { esClient } from "../app.js"; | ||
|
||
export async function checkClusterHealth(): Promise<string> { | ||
try { | ||
const response = await esClient.cat.health(); | ||
console.info('Cluster health:', response); | ||
return response; | ||
} catch (error) { | ||
console.error('Error checking cluster health:', error); | ||
return ''; | ||
} | ||
} | ||
|
||
export async function BulkStoreToDB( | ||
validFiles: any, | ||
): Promise<void> { | ||
try { | ||
if (validFiles.length == 0) { | ||
return; | ||
} | ||
const response = await esClient.bulk({ body: validFiles }); | ||
return response; | ||
} catch (error) { | ||
console.error('Error bulk indexing:', error); | ||
} | ||
} | ||
|
||
export async function DeleteDocumentWithId(Id : string): Promise<void> { | ||
try { | ||
const index = 'openapi'; | ||
const updatedDocument = { | ||
isDeleted: true, | ||
}; | ||
await esClient.update({ | ||
index, | ||
id: Id, | ||
body: { | ||
doc: updatedDocument, | ||
}, | ||
}); | ||
console.info(`Document with ID ${Id} soft deleted.`); | ||
} catch (error) { | ||
console.error('Error deleting document from the database:', error); | ||
} | ||
} | ||
|
||
export async function CreateDocument(Id:string, document: any): Promise<void> { | ||
try { | ||
const index = 'openapi'; | ||
await esClient.index({ | ||
index, | ||
id: Id, | ||
body: { | ||
doc: document, | ||
}, | ||
}); | ||
console.info(`New Document Added with ID ${Id}`); | ||
} catch (error) { | ||
//TODO: Add error handling for 400 over here | ||
console.error('Error creating the document:', error); | ||
} | ||
} | ||
|
||
export async function GetDocumentWithId(Id:string): Promise<any> { | ||
try { | ||
const index = 'openapi'; | ||
const document = await esClient.get({ | ||
index, | ||
id: Id, | ||
}); | ||
return document; | ||
} catch (error) { | ||
console.error('Error getting document from database:', error); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.