I have this controller:
import asyncHandler from "express-async-handler";
import { Request, Response } from "express";
import sequelize from "../db/connection"
export const bookTicketController = asyncHandler( async (req: Request, res: Response) => {
const transaction = await sequelize.transaction();
res.status(201).json({ message: "yes" });
});
and this connection.ts:
import { Sequelize } from 'sequelize-typescript';
import { User } from './models/User'; // Add more models as needed
import configDB from './config/config';
import { Event } from './models/Event';
import { Booking } from './models/Booking';
import { Category } from './models/Category';
const env = process.env.NODE_ENV || 'development';
const currentConfig = configDB[env];
const sequelize = new Sequelize({
...currentConfig,
models: [Event, User, Booking, Category],
});
export const connectToDatabase = async () => {
try {
await sequelize.authenticate();
console.log("Database connected!");
await sequelize.sync();
console.log("Models synced!");
} catch (error) {
console.error("Unable to connect to the database:", error);
}
};
export default sequelize;
it give me this error:
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript: src/utils/swagger.ts:2:5 - error TS7022: '__importDefault' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
2 var __importDefault = (this && this.__importDefault) || function (mod) { ~~~~~~~~~~~~~~~ src/utils/swagger.ts:2:67 - error TS7006: Parameter 'mod' implicitly has an 'any' type.
2 var __importDefault = (this && this.__importDefault) || function (mod) { ~~~ src/utils/swagger.ts:47:23 - error TS7006: Parameter 'app' implicitly has an 'any' type.
47 function setupSwagger(app) { ~~~
at createTSError (C:\Users\inbal\Projects\event-booking-api\node_modules\ts-node\src\index.ts:859:12)
at reportTSError (C:\Users\inbal\Projects\event-booking-api\node_modules\ts-node\src\index.ts:863:19)
at getOutput (C:\Users\inbal\Projects\event-booking-api\node_modules\ts-node\src\index.ts:1077:36)
at Objectpile (C:\Users\inbal\Projects\event-booking-api\node_modules\ts-node\src\index.ts:1433:41)
at Module.m._compile (C:\Users\inbal\Projects\event-booking-api\node_modules\ts-node\src\index.ts:1617:30)
at Module.m._compile (C:\Users\inbal\Projects\event-booking-api\node_modules\ts-node\src\index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
at require.extensions.<computed> (C:\Users\inbal\Projects\event-booking-api\node_modules\ts-node\src\index.ts:1621:12)
at Object.require.extensions.<computed> [as .ts] (C:\Users\inbal\Projects\event-booking-api\node_modules\ts-node\src\index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1133:32) {
diagnosticCodes: [ 7022, 7006, 7006 ] }
and when i delete the transaction line: const transaction = await sequelize.transaction(); it work, wht sequelize not work good with swagger and how i can fix this error?