-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for transaction groups (#324)
* Catch failed transactions in worker * Add transaction groups
- Loading branch information
Showing
7 changed files
with
95 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PrismaTransaction } from "../../schema/prisma"; | ||
import { getPrismaWithPostgresTx } from "../client"; | ||
import { cleanTxs } from "./cleanTxs"; | ||
|
||
interface GetTxsByGroupIdParams { | ||
pgtx?: PrismaTransaction; | ||
groupId: string; | ||
} | ||
|
||
export const getTxsByGroupId = async ({ | ||
pgtx, | ||
groupId, | ||
}: GetTxsByGroupIdParams) => { | ||
const prisma = getPrismaWithPostgresTx(pgtx); | ||
const txs = await prisma.transactions.findMany({ | ||
where: { | ||
groupId, | ||
}, | ||
}); | ||
|
||
if (!txs) { | ||
return []; | ||
} | ||
|
||
return cleanTxs(txs); | ||
}; |
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "transactions" ADD COLUMN "groupId" TEXT; |
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,43 @@ | ||
import { Static, Type } from "@sinclair/typebox"; | ||
import { FastifyInstance } from "fastify"; | ||
import { StatusCodes } from "http-status-codes"; | ||
import { getTxsByGroupId } from "../../../db/transactions/getTxsByGroupId"; | ||
import { standardResponseSchema } from "../../schemas/sharedApiSchemas"; | ||
import { transactionResponseSchema } from "../../schemas/transaction"; | ||
|
||
const ParamsSchema = Type.Object({ | ||
groupId: Type.String(), | ||
}); | ||
|
||
const ReplySchema = Type.Object({ | ||
result: Type.Array(transactionResponseSchema), | ||
}); | ||
|
||
export async function checkGroupStatus(fastify: FastifyInstance) { | ||
fastify.route<{ | ||
Params: Static<typeof ParamsSchema>; | ||
Reply: Static<typeof ReplySchema>; | ||
}>({ | ||
method: "GET", | ||
url: "/transaction/status/group/:groupId", | ||
schema: { | ||
summary: "Get transaction status for a group", | ||
description: "Get the status for a transaction group.", | ||
tags: ["Transaction"], | ||
operationId: "status", | ||
params: ParamsSchema, | ||
response: { | ||
...standardResponseSchema, | ||
[StatusCodes.OK]: ReplySchema, | ||
}, | ||
}, | ||
handler: async (req, res) => { | ||
const { groupId } = req.params; | ||
const txs = await getTxsByGroupId({ groupId }); | ||
|
||
res.status(StatusCodes.OK).send({ | ||
result: txs, | ||
}); | ||
}, | ||
}); | ||
} |
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