team -> ts

This commit is contained in:
Alex Holliday committed 2026-01-21 11:46:49 -08:00
1 parent 9fa0113f2b
commit 36e02e0a9a
10 files changed
+110 -21

No files matched your search

+3
View File
@@ -27,3 +27,6 @@ export { default as MongoNotificationsRepository } from "@/repositories/notifica
export * from "@/repositories/incidents/IIncidentsRepository.js";
export { default as MongoIncidentRepository } from "@/repositories/incidents/MongoIncidentRepository.js";
export * from "@/repositories/teams/ITeamsRepository.js";
export { default as MongoTeamsRepository } from "@/repositories/teams/MongoTeamsRepository.js";
@@ -0,0 +1,9 @@
import type { Team } from "@/types/index.js";
export interface ITeamRepository {
// create
create(email: string): Promise<Team>;
// fetch
// update
// delete
// other
}
@@ -0,0 +1,36 @@
import { Team } from "@/types/index.js";
import { TeamDocument, TeamModel } from "@/db/models/index.js";
import { ITeamRepository } from "@/repositories/index.js";
import mongoose from "mongoose";
class MongoTeamRepository implements ITeamRepository {
private toStringId = (value?: mongoose.Types.ObjectId | string | null): string => {
if (!value) {
return "";
}
return value instanceof mongoose.Types.ObjectId ? value.toString() : String(value);
};
private toDateString = (value?: Date | string | null): string => {
if (!value) {
return new Date(0).toISOString();
}
return value instanceof Date ? value.toISOString() : new Date(value).toISOString();
};
private toEntity = (doc: TeamDocument): Team => {
return {
id: this.toStringId(doc._id),
email: doc.email,
createdAt: this.toDateString(doc.createdAt),
updatedAt: this.toDateString(doc.updatedAt),
};
};
create = async (email: string) => {
const team = await TeamModel.create({ email });
return this.toEntity(team);
};
}
export default MongoTeamRepository;