generated from HugoRCD/nuxt3-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
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
21 changed files
with
272 additions
and
40 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
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,34 @@ | ||
import { cryptos } from '@currencia/cryptos' | ||
import { PrismaClient } from '@prisma/client' | ||
|
||
export const prisma = new PrismaClient() | ||
|
||
async function main() { | ||
for (const crypto of cryptos) { | ||
await prisma.crypto.upsert({ | ||
where: { symbol: crypto.symbol }, | ||
update: { | ||
name: crypto.name, | ||
symbol: crypto.symbol, | ||
logo: crypto.logo, | ||
description: crypto.description, | ||
}, | ||
create: { | ||
name: crypto.name, | ||
symbol: crypto.symbol, | ||
logo: crypto.logo, | ||
description: crypto.description | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
main() | ||
.then(async () => { | ||
await prisma.$disconnect() | ||
}) | ||
.catch(async (e) => { | ||
console.error(e) | ||
await prisma.$disconnect() | ||
process.exit(1) | ||
}) |
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,33 @@ | ||
import { z } from 'zod' | ||
|
||
const symbolParams = z.object({ | ||
symbol: z.string(), | ||
}) | ||
|
||
export default defineEventHandler(async (event) => { | ||
const { symbol } = await getValidatedRouterParams(event, symbolParams.parse) | ||
const { price, timestamp } = await readValidatedBody(event, z.object({ | ||
price: z.number(), | ||
timestamp: z.bigint(), | ||
}).parse) | ||
|
||
const crypto = await prisma.crypto.findUnique({ | ||
where: { | ||
symbol, | ||
} | ||
}) | ||
if (!crypto) return createError({ statusCode: 404, message: 'Crypto not found' }) | ||
await prisma.prices.create({ | ||
data: { | ||
cryptoId: crypto.id, | ||
timestamp, | ||
price | ||
} | ||
}) | ||
return { | ||
statusCode: 201, | ||
body: { | ||
message: 'Price saved successfully' | ||
} | ||
} | ||
}) |
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 |
---|---|---|
@@ -1,16 +1,36 @@ | ||
import { MongoDBClient } from '@currencia/mongo' | ||
import { RabbitMQClient } from '~/utils/rabbit' | ||
|
||
export default defineTask({ | ||
meta: { | ||
name: 'sync:mongo', | ||
description: 'Send MongoID to RabbitMQ', | ||
}, | ||
async run() { | ||
const client = await MongoDBClient.create() | ||
console.log('Syncing MongoID to RabbitMQ') | ||
const price = await client.getLatestPrices() | ||
console.log('Price:', price) | ||
console.log('Ids to sync:', price?._id) | ||
return { result: 'Success' } | ||
const runtimeConfig = useRuntimeConfig() | ||
const rabbitClient = new RabbitMQClient({ | ||
url: runtimeConfig.rabbit.url, | ||
queue: runtimeConfig.rabbit.queue, | ||
}) | ||
const mongoClient = await MongoDBClient.create() | ||
|
||
try { | ||
console.log('Syncing MongoID to RabbitMQ') | ||
|
||
const prices = await mongoClient.getLatestPrices() | ||
|
||
await rabbitClient.connect() | ||
|
||
await rabbitClient.publishMessages({ _id: prices._id }) | ||
|
||
console.log('IDs sent to RabbitMQ successfully') | ||
|
||
return { result: 'Success' } | ||
} catch (error) { | ||
console.error('Error in sync task:', error) | ||
throw error | ||
} finally { | ||
await rabbitClient.disconnect() | ||
} | ||
}, | ||
}) |
Oops, something went wrong.