Skip to content

Commit

Permalink
Merge branch 'misc-fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
kapil1garg committed May 21, 2024
2 parents 66e1e9e + e298102 commit 80d7c49
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion controllers/capNotes/createSoapNote.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mongoose from 'mongoose';
import dbConnect from '../../lib/dbConnect';
import CAPNoteModel from '../../models/CAPNoteModel';
import IssueObjectModel from '../../models/IssueObjectModel';
import { createNewTextEntryBlock } from '../textEntryBlock/createNewTextEntryBlock';

/**
Expand Down Expand Up @@ -44,7 +45,16 @@ export const createCAPNote = async (projectName: string, noteDate: Date) => {
let pastIssues = [];
let trackedPractices = [];
if (previousCAPNote) {
pastIssues = previousCAPNote.currentIssues;
// fetch all IssueObjects for pastIssues so we only keep the ones that weren't deleted
const pastIssueIds = previousCAPNote?.pastIssues;
const issueObjects = await IssueObjectModel.find({
_id: { $in: pastIssueIds }
});
pastIssues = issueObjects
.filter((issue) => !issue.wasDeleted)
.map((issue) => issue._id);

// keep all tracked practices
trackedPractices = previousCAPNote.trackedPractices;
}

Expand Down

0 comments on commit 80d7c49

Please sign in to comment.