reorg to domain and api

This commit is contained in:
Alex Holliday committed 2026-06-09 12:34:15 -07:00
1 parent 0fb210e9e1
commit d022f7d849
190 files changed
+643 -830

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
import { Schema, model, type Types } from "mongoose";
import type { Team } from "@/domain/teams/team.type.js";
type TeamDocumentBase = Omit<Team, "id" | "createdAt" | "updatedAt"> & {};
interface TeamDocument extends TeamDocumentBase {
_id: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const TeamSchema = new Schema<TeamDocument>(
{
email: {
type: String,
required: true,
unique: true,
},
},
{
timestamps: true,
}
);
const TeamModel = model<TeamDocument>("Team", TeamSchema);
export type { TeamDocument };
export { TeamModel };
export default TeamModel;
@@ -0,0 +1,10 @@
import type { Team } from "@/domain/teams/team.type.js";
export interface ITeamsRepository {
// create
create(email: string): Promise<Team>;
// fetch
// update
// delete
// other
findAllTeamIds(): Promise<string[]>;
}
@@ -0,0 +1,41 @@
import { Team } from "@/domain/teams/team.type.js";
import { TeamDocument, TeamModel } from "@/domain/teams/team.model.js";
import { ITeamsRepository } from "@/domain/teams/team.repository.interface.js";
import mongoose from "mongoose";
class MongoTeamsRepository implements ITeamsRepository {
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);
};
findAllTeamIds = async (): Promise<string[]> => {
const teams = await TeamModel.find({}, { _id: 1 }).lean();
return teams.map((team) => this.toStringId(team._id));
};
}
export default MongoTeamsRepository;
+6
View File
@@ -0,0 +1,6 @@
export interface Team {
id: string;
email: string;
createdAt: string;
updatedAt: string;
}