From fe6b6da4b27b79fe440bece9f720585268616e1f Mon Sep 17 00:00:00 2001 From: James Brooks <12275865+jamesobrooks@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:00:19 -0500 Subject: [PATCH] Use ARRAY_CONTAINS to query roles Jira ticket: CAMS-283 --- .../lib/adapters/gateways/cosmos/cosmos.repository.ts | 3 ++- .../lib/adapters/gateways/offices.cosmosdb.repository.ts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/functions/lib/adapters/gateways/cosmos/cosmos.repository.ts b/backend/functions/lib/adapters/gateways/cosmos/cosmos.repository.ts index a46fe3d87..3ef7d606a 100644 --- a/backend/functions/lib/adapters/gateways/cosmos/cosmos.repository.ts +++ b/backend/functions/lib/adapters/gateways/cosmos/cosmos.repository.ts @@ -5,6 +5,7 @@ import { CosmosConfig } from '../../types/database'; import { ServerConfigError } from '../../../common-errors/server-config-error'; import { isPreExistingDocumentError } from './cosmos.helper'; import { DocumentRepository } from '../../../use-cases/gateways.types'; +import { UnknownError } from '../../../common-errors/unknown-error'; export class CosmosDbRepository implements DocumentRepository { protected cosmosDbClient; @@ -35,7 +36,7 @@ export class CosmosDbRepository implements DocumentRepository { originalError, }); } else { - throw originalError; + throw new UnknownError(this.moduleName, { originalError }); } } } diff --git a/backend/functions/lib/adapters/gateways/offices.cosmosdb.repository.ts b/backend/functions/lib/adapters/gateways/offices.cosmosdb.repository.ts index ebbd8b1e4..a887b0e90 100644 --- a/backend/functions/lib/adapters/gateways/offices.cosmosdb.repository.ts +++ b/backend/functions/lib/adapters/gateways/offices.cosmosdb.repository.ts @@ -29,7 +29,7 @@ export class OfficesCosmosDbRepository implements OfficesRepository { context: ApplicationContext, officeCode: string, ): Promise { - const query = `SELECT * FROM c WHERE c.officeCode = @officeCode and c.documentType = 'OFFICE_STAFF' and ${CamsRole.TrialAttorney} IN c.roles`; + const query = `SELECT * FROM c WHERE c.officeCode = @officeCode and c.documentType = 'OFFICE_STAFF' and ARRAY_CONTAINS(c.roles, @role)`; const querySpec = { query, parameters: [ @@ -37,6 +37,10 @@ export class OfficesCosmosDbRepository implements OfficesRepository { name: '@officeCode', value: officeCode, }, + { + name: '@role', + value: CamsRole.TrialAttorney, + }, ], }; return await this.officeStaffRepo.query(context, querySpec);