diff --git a/server/src/repositories/teams/TimescaleTeamsRepository.ts b/server/src/repositories/teams/TimescaleTeamsRepository.ts new file mode 100644 index 000000000..be16b7790 --- /dev/null +++ b/server/src/repositories/teams/TimescaleTeamsRepository.ts @@ -0,0 +1,24 @@ +import type { Pool } from "pg"; +import { ITeamsRepository } from "@/repositories/teams/ITeamsRepository.js"; +import { Team } from "@/types/team.js"; + +export class TimescaleTeamsRepository implements ITeamsRepository { + constructor(private pool: Pool) {} + + create = async (email: string): Promise => { + const result = await this.pool.query(`INSERT INTO teams (email) VALUES ($1) RETURNING id, email, created_at, updated_at`, [email]); + return this.toEntity(result.rows[0]); + }; + + findAllTeamIds = async (): Promise => { + const result = await this.pool.query(`SELECT id FROM teams`); + return result.rows.map((row) => row.id); + }; + + private toEntity = (row: { id: string; email: string; created_at: Date; updated_at: Date }): Team => ({ + id: row.id, + email: row.email, + createdAt: row.created_at.toISOString(), + updatedAt: row.updated_at.toISOString(), + }); +}