Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/backend/src/sessions/sessions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,28 @@ export class SessionsService {
};
}

// Helper function to pick only allowed fields
private pick(obj: Record<string, any>, allowed: string[]): Record<string, any> {
return Object.keys(obj)
.filter(key => allowed.includes(key))
.reduce((acc, key) => {
acc[key] = obj[key];
return acc;
}, {} as Record<string, any>);
}

async update(
id: string,
updateSessionDto: UpdateSessionDto,
): Promise<Session> {
// Define the list of fields that are safe to update
const allowedFields = [
// TODO: Replace with the actual allowed UpdateSessionDto fields, such as:
"field1", "field2", "field3"
];
const safeUpdate = this.pick(updateSessionDto, allowedFields);
const updated = await this.sessionModel
.findByIdAndUpdate(id, updateSessionDto, { new: true })
.findByIdAndUpdate(id, safeUpdate, { new: true })
.exec();
if (!updated) {
throw new NotFoundException(`Session with id ${id} not found`);
Expand Down
Loading