Skip to content

Commit 8b8c254

Browse files
committed
feat: add test changes
1 parent 83b4837 commit 8b8c254

1 file changed

Lines changed: 39 additions & 25 deletions

File tree

apps/api/src/instrument-records/instrument-records.service.ts

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import type {
2424
import { Prisma } from '@prisma/client';
2525
import type { Session } from '@prisma/client';
2626
import { isNumber, mergeWith, pickBy } from 'lodash-es';
27+
import { ObjectId } from 'mongodb';
2728

2829
import { accessibleQuery } from '@/auth/ability.utils';
30+
import type { AppAbility } from '@/auth/auth.types';
2931
import type { EntityOperationOptions } from '@/core/types';
3032
import { GroupsService } from '@/groups/groups.service';
3133
import { InstrumentsService } from '@/instruments/instruments.service';
@@ -36,8 +38,6 @@ import { SubjectsService } from '@/subjects/subjects.service';
3638
import { InstrumentMeasuresService } from './instrument-measures.service';
3739

3840
import type { InitData, RecordType } from './thread-types';
39-
import { P } from 'ts-pattern';
40-
import type { AppAbility } from '@/auth/auth.types';
4141

4242
// type ExpandDataType =
4343
// | {
@@ -205,21 +205,21 @@ export class InstrumentRecordsService {
205205
// throw new Error()
206206
// }
207207

208-
for (let i = 0; i < records.length; i++) {
209-
const record = records[i];
210-
if (Object.getPrototypeOf(record) !== Object.prototype) {
211-
console.log(record);
212-
throw new Error('Bad prototype');
213-
}
214-
// for (const key in record) {
215-
// structuredClone(record[key])
216-
// }
217-
records[i] = {
218-
...record
219-
};
220-
}
208+
// for (let i = 0; i < records.length; i++) {
209+
// const record = records[i];
210+
// if (Object.getPrototypeOf(record) !== Object.prototype) {
211+
// console.log(record);
212+
// throw new Error('Bad prototype');
213+
// }
214+
// // for (const key in record) {
215+
// // structuredClone(record[key])
216+
// // }
217+
// records[i] = {
218+
// ...record
219+
// };
220+
// }
221221

222-
console.log(records[0]);
222+
// console.log(records[0]);
223223

224224
// throw new Error("NULL")
225225
structuredClone(records);
@@ -529,16 +529,8 @@ export class InstrumentRecordsService {
529529

530530
private async queryRecordsRaw(appAbility?: AppAbility, groupId?: string) {
531531
const permissions = accessibleQuery(appAbility, 'read', 'InstrumentRecord');
532+
532533
const pipeline = [
533-
{
534-
$match: {
535-
$and: [
536-
// Filter by groupId if provided
537-
...(groupId ? [{ groupIds: { $in: [groupId] } }] : []),
538-
permissions
539-
]
540-
}
541-
},
542534
{
543535
// Join with Session collection
544536
$lookup: {
@@ -559,6 +551,28 @@ export class InstrumentRecordsService {
559551
}
560552
},
561553
{ $unwind: { path: '$subject', preserveNullAndEmptyArrays: true } },
554+
...(groupId
555+
? [
556+
{
557+
$match: {
558+
'subject.groupIds': { $in: [new ObjectId(groupId)] }
559+
}
560+
}
561+
]
562+
: []),
563+
// {
564+
// $match: {
565+
// $subject: {
566+
// $in: groupId ? [groupId, "groupIds"] : [undefined]
567+
// }
568+
// }
569+
// },
570+
// ...(groupId ? [{
571+
// $match: {
572+
// '$subject.groupIds': { $in: [new ObjectId(groupId)] }
573+
// }
574+
// }] : []),
575+
562576
{
563577
$project: {
564578
computedMeasures: 1,

0 commit comments

Comments
 (0)