Type of `tx` when using `db.transactions`
I want to use helper functions within
so basically i don't know how to type
db.transactionsdb.transactions but I can't get the type of txtx workingso basically i don't know how to type
txtx in the updateUserNotificationsupdateUserNotifications functionconst updateUserNotifications = async (
userId: UpdateUserAttributes["id"],
notifications: Required<UpdateUserAttributes>["notifications"],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
tx: any, // TODO: what's the type of this
) => {
// check if user has a notification settings record
const userNotificationSettings = await tx.select().from(userNotifications).where(eq(users.id, userId));
// create user notification settings record if it doesn't exist
if (!userNotificationSettings.length) {
await tx.insert(userNotifications).values({
userId,
favorites: notifications.favorites,
});
}
await tx.update(userNotifications).set({ favorites: notifications.favorites }).where(eq(users.id, userId));
};
export const updateUser = async (userAttributes: UpdateUserAttributes) => {
await db.transaction(async (tx) => {
// update user notification settings
if (userAttributes.notifications) {
await updateUserNotifications(userAttributes.id, userAttributes.notifications, tx);
}
});
};const updateUserNotifications = async (
userId: UpdateUserAttributes["id"],
notifications: Required<UpdateUserAttributes>["notifications"],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
tx: any, // TODO: what's the type of this
) => {
// check if user has a notification settings record
const userNotificationSettings = await tx.select().from(userNotifications).where(eq(users.id, userId));
// create user notification settings record if it doesn't exist
if (!userNotificationSettings.length) {
await tx.insert(userNotifications).values({
userId,
favorites: notifications.favorites,
});
}
await tx.update(userNotifications).set({ favorites: notifications.favorites }).where(eq(users.id, userId));
};
export const updateUser = async (userAttributes: UpdateUserAttributes) => {
await db.transaction(async (tx) => {
// update user notification settings
if (userAttributes.notifications) {
await updateUserNotifications(userAttributes.id, userAttributes.notifications, tx);
}
});
};