more pouplate fixes

This commit is contained in:
Rob Colbert 2026-05-01 17:43:56 -04:00
parent f353c2153a
commit af09b6dcc3
2 changed files with 15 additions and 6 deletions

View File

@ -5,12 +5,19 @@
import { IChatSession, ChatSessionMode, GadgetId } from "@gadget/api"; import { IChatSession, ChatSessionMode, GadgetId } from "@gadget/api";
import { DtpService } from "../lib/service.js"; import { DtpService } from "../lib/service.js";
import { PopulateOptions } from "mongoose";
import ChatSession from "../models/chat-session.js"; import ChatSession from "../models/chat-session.js";
import ChatTurn from "../models/chat-turn.js"; import ChatTurn from "../models/chat-turn.js";
import Project from "../models/project.js"; import Project from "../models/project.js";
import AiProvider from "../models/ai-provider.js"; import AiProvider from "../models/ai-provider.js";
class ChatSessionService extends DtpService { class ChatSessionService extends DtpService {
private populateSession: PopulateOptions[] = [
{ path: "user", select: "-passwordSalt -password" },
{ path: "project" },
{ path: "provider" },
];
get name(): string { get name(): string {
return "ChatSessionService"; return "ChatSessionService";
} }
@ -75,7 +82,7 @@ class ChatSessionService extends DtpService {
model: selectedModel, model: selectedModel,
}); });
return session; return session.populate(this.populateSession);
} }
/** /**
@ -83,7 +90,7 @@ class ChatSessionService extends DtpService {
*/ */
async getById(chatSessionId: GadgetId): Promise<IChatSession> { async getById(chatSessionId: GadgetId): Promise<IChatSession> {
const session = await ChatSession.findById(chatSessionId) const session = await ChatSession.findById(chatSessionId)
.populate("user") .populate("user", "-passwordSalt -password")
.populate("project") .populate("project")
.populate("provider") .populate("provider")
.lean(); .lean();
@ -100,7 +107,7 @@ class ChatSessionService extends DtpService {
*/ */
async getByProject(projectId: GadgetId): Promise<IChatSession[]> { async getByProject(projectId: GadgetId): Promise<IChatSession[]> {
const sessions = await ChatSession.find({ project: projectId }) const sessions = await ChatSession.find({ project: projectId })
.populate("user") .populate("user", "-passwordSalt -password")
.populate("project") .populate("project")
.populate("provider") .populate("provider")
.sort({ createdAt: -1 }) .sort({ createdAt: -1 })
@ -114,7 +121,7 @@ class ChatSessionService extends DtpService {
*/ */
async getByUser(userId: GadgetId): Promise<IChatSession[]> { async getByUser(userId: GadgetId): Promise<IChatSession[]> {
const sessions = await ChatSession.find({ user: userId }) const sessions = await ChatSession.find({ user: userId })
.populate("user") .populate("user", "-passwordSalt -password")
.populate("project") .populate("project")
.populate("provider") .populate("provider")
.sort({ createdAt: -1 }) .sort({ createdAt: -1 })
@ -191,7 +198,7 @@ class ChatSessionService extends DtpService {
*/ */
async getTurns(chatSessionId: GadgetId): Promise<any[]> { async getTurns(chatSessionId: GadgetId): Promise<any[]> {
const turns = await ChatTurn.find({ session: chatSessionId }) const turns = await ChatTurn.find({ session: chatSessionId })
.populate("user") .populate("user", "-passwordSalt -password")
.populate("project") .populate("project")
.populate("provider") .populate("provider")
.sort({ createdAt: 1 }) .sort({ createdAt: 1 })

View File

@ -134,7 +134,9 @@ The ${env.site.name} Team
} }
async verifyEmailCode(code: string): Promise<IEmailVerification> { async verifyEmailCode(code: string): Promise<IEmailVerification> {
const verification = await EmailVerification.findOne({ code }).lean(); const verification = await EmailVerification.findOne({ code })
.populate(this.populateEmailVerification)
.lean();
if (!verification) { if (!verification) {
const error = new Error("Invalid verification code"); const error = new Error("Invalid verification code");
error.statusCode = 400; error.statusCode = 400;