hyperdx/packages/api/src/controllers/connection.ts
Dan Hable c2160536ac
feat: group tasks by connection (#1071)
Group the alert tasks fetched from mongo into groups based on what needs to run from the same connection. This sets up for further optimizations and connection reuse.
2025-08-19 15:26:01 +00:00

38 lines
965 B
TypeScript

import Connection, { IConnection } from '@/models/connection';
export function getConnections() {
// Never return password back to the user
// Return all connections in current tenant
return Connection.find({});
}
export function getConnectionById(
team: string,
connectionId: string,
selectPassword = false,
) {
return Connection.findOne({ _id: connectionId, team }).select(
selectPassword ? '+password' : '',
);
}
export function createConnection(
team: string,
connection: Omit<IConnection, 'id' | '_id'>,
) {
return Connection.create({ ...connection, team });
}
export function updateConnection(
team: string,
connectionId: string,
connection: Omit<IConnection, 'id' | '_id'>,
) {
return Connection.findOneAndUpdate({ _id: connectionId, team }, connection, {
new: true,
});
}
export function deleteConnection(team: string, connectionId: string) {
return Connection.findOneAndDelete({ _id: connectionId, team });
}