-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
111 additions
and
66 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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// workers/auth.js | ||
import { expose } from 'threads/worker'; | ||
import { WorkerModule } from 'threads/dist/types/worker'; | ||
import { getClusterMatchingAdapter } from '../../adapters/adaptersFactory'; | ||
import { EstimatedClusterMatching } from '../../entities/estimatedClusterMatching'; | ||
|
||
type EstimatedClusterMatchingWorkerFunctions = | ||
| 'fetchEstimatedClusterMatching' | ||
| 'updateEstimatedClusterMatching'; | ||
|
||
export type EstimatedClusterMatchingWorker = | ||
WorkerModule<EstimatedClusterMatchingWorkerFunctions>; | ||
|
||
const worker: EstimatedClusterMatchingWorker = { | ||
async fetchEstimatedClusterMatching(matchingDataInput: any) { | ||
return await getClusterMatchingAdapter().fetchEstimatedClusterMatchings( | ||
matchingDataInput, | ||
); | ||
}, | ||
|
||
async updateEstimatedClusterMatching(qfRoundId: number, matchingData: any) { | ||
try { | ||
// Prepare values for bulk insert | ||
const values = matchingData | ||
.map( | ||
data => `( | ||
(SELECT id FROM project WHERE title = '${data.project_name}'), | ||
${qfRoundId}, | ||
${data.matching_amount} | ||
)`, | ||
) | ||
.join(','); | ||
|
||
const query = ` | ||
INSERT INTO estimated_cluster_matching ("projectId", "qfRoundId", matching) | ||
VALUES ${values} | ||
ON CONFLICT ("projectId", "qfRoundId") | ||
DO UPDATE SET matching = EXCLUDED.matching | ||
RETURNING "projectId", "qfRoundId", matching; | ||
`; | ||
|
||
const result = await EstimatedClusterMatching.query(query); | ||
if (result.length === 0) { | ||
throw new Error('No records were inserted or updated.'); | ||
} | ||
|
||
console.log('Matching data processed successfully with raw SQL.'); | ||
} catch (error) { | ||
console.error('Error processing matching data:', error.message); | ||
// You can also log specific error codes here if needed | ||
} | ||
}, | ||
}; | ||
|
||
expose(worker); |
This file was deleted.
Oops, something went wrong.
Empty file.