@@ -37,6 +37,7 @@ import { InstrumentMeasuresService } from './instrument-measures.service';
3737
3838import type { InitData , RecordType } from './thread-types' ;
3939import { P } from 'ts-pattern' ;
40+ import type { AppAbility } from '@/auth/auth.types' ;
4041
4142// type ExpandDataType =
4243// | {
@@ -145,7 +146,7 @@ export class InstrumentRecordsService {
145146 return this . instrumentRecordModel . exists ( where ) ;
146147 }
147148
148- async exportRecords ( { groupId : _ } : { groupId ?: string } = { } , { ability : __ } : EntityOperationOptions = { } ) {
149+ async exportRecords ( { groupId } : { groupId ?: string } = { } , { ability } : EntityOperationOptions = { } ) {
149150 //separate this into seperate queries that are done within the thread (ie find session and subject info in thread instead with prisma model)
150151 // const records = await this.instrumentRecordModel.findMany({
151152 // include: {
@@ -178,7 +179,9 @@ export class InstrumentRecordsService {
178179
179180 // TBD IMPORTANT - add permissions
180181
181- const records = await this . queryRecordsRaw ( ) ;
182+ //const permissions = accessibleQuery(ability, 'read', 'InstrumentRecord')
183+
184+ const records = await this . queryRecordsRaw ( ability , groupId ) ;
182185
183186 // console.log(records[0]
184187 // records.forEach((record) => {
@@ -524,17 +527,18 @@ export class InstrumentRecordsService {
524527 return JSON . parse ( JSON . stringify ( data ) , reviver ) as unknown ;
525528 }
526529
527- private async queryRecordsRaw ( ) {
530+ private async queryRecordsRaw ( appAbility ?: AppAbility , groupId ?: string ) {
531+ const permissions = accessibleQuery ( appAbility , 'read' , 'InstrumentRecord' ) ;
528532 const pipeline = [
529- // {
530- // $match: {
531- // $and: [
532- // // Filter by groupId if provided
533- // ...(groupId ? [{ groupIds: { $in: [groupId] } }] : []),
534- // //permissionFilter
535- // ]
536- // }
537- // },
533+ {
534+ $match : {
535+ $and : [
536+ // Filter by groupId if provided
537+ ...( groupId ? [ { groupIds : { $in : [ groupId ] } } ] : [ ] ) ,
538+ permissions
539+ ]
540+ }
541+ } ,
538542 {
539543 // Join with Session collection
540544 $lookup : {
0 commit comments