Files
outline/server/middlewares/transaction.ts
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

21 lines
688 B
TypeScript

import type { Next } from "koa";
import type { Transaction } from "sequelize";
import { sequelize } from "@server/storage/database";
import type { AppContext } from "@server/types";
/**
* Middleware that wraps a route in a database transaction, useful for mutations
* The transaction is available on the context as `ctx.state.transaction` and
* should be passed to all database calls within the route.
*
* @returns The middleware function.
*/
export function transaction() {
return async function transactionMiddleware(ctx: AppContext, next: Next) {
await sequelize.transaction(async (t: Transaction) => {
ctx.state.transaction = t;
return next();
});
};
}