Skip to content

Commit

Permalink
Started work on use cases
Browse files Browse the repository at this point in the history
Jira ticket: CAMS-461
  • Loading branch information
fmaddenflx committed Nov 16, 2024
1 parent 4b1bea7 commit 4729eaf
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 5 deletions.
33 changes: 32 additions & 1 deletion backend/functions/lib/use-cases/orders/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export interface SyncOrdersStatus {
maxTxId: string;
}

export interface ImportConsolidationOptions {}

export class OrdersUseCase {
private readonly casesRepo: CasesRepository;
private readonly casesGateway: CasesInterface;
Expand Down Expand Up @@ -169,12 +171,41 @@ export class OrdersUseCase {
}
}

public async getConsolidationPageCount(
context: ApplicationContext,
_options?: ImportConsolidationOptions,
): Promise<number> {
try {
//const pageCount = await this.legacyDatabaseRepo.read('', '');
//context.logger.info(MODULE_NAME, 'Got page count for import from repo.', pageCount);
//return pageCount;
} catch (error) {
const message = 'Failed to get page count for consolidation import from repo.';
context.logger.info(MODULE_NAME, message, error);
throw new CamsError(MODULE_NAME, { message });
}
return 0;
}

public async importConsolidationData(
context: ApplicationContext,
_options?: ImportConsolidationOptions,
): Promise<void> {
try {
//const consolidations = await this.legacyDatabaseRepo.read('', '');
} catch (error) {
const message = 'Failed to get consolidation data from repo.';
context.logger.info(MODULE_NAME, message, error);
throw new CamsError(MODULE_NAME, { message });
}
return;
}

public async syncOrders(
context: ApplicationContext,
options?: SyncOrdersOptions,
): Promise<SyncOrdersStatus> {
let initialSyncState: OrderSyncState;

try {
initialSyncState = await this.runtimeStateRepo.read('ORDERS_SYNC_STATE', '');
context.logger.info(
Expand Down
42 changes: 38 additions & 4 deletions backend/functions/poc/activity/getPageCount.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
import { InvocationContext } from '@azure/functions';
import { PredicateAndPage } from '../model';
import { OrdersUseCase } from '../../lib/use-cases/orders/orders';
import {
getCasesRepository,
getCasesGateway,
getOrdersRepository,
getOrdersGateway,
getRuntimeStateRepository,
getConsolidationOrdersRepository,
getStorageGateway,
} from '../../lib/factory';
import { OrderSyncState } from '../../lib/use-cases/gateways.types';
import ContextCreator from '../../azure/application-context-creator';
import { CamsError } from '../../lib/common-errors/cams-error';

async function getPageCount(input: PredicateAndPage, context: InvocationContext) {
// Do some stuff
context.log('#################GetPageCount', JSON.stringify(input));
return 4;
const MODULE_NAME = 'IMPORT-ACTION-GET-PAGE-COUNT';

async function getPageCount(input: PredicateAndPage, invocationContext: InvocationContext) {
const logger = ContextCreator.getLogger(invocationContext);
try {
const context = await ContextCreator.applicationContextCreator(invocationContext, logger);

// Do some stuff
console.log('#################GetPageCount', JSON.stringify(input));
// TODO: This seems silly to have to supply all of these repos and gateways.
// Are we going to add yet another for ACMS?
const orders = new OrdersUseCase(
getCasesRepository(context),
getCasesGateway(context),
getOrdersRepository(context),
getOrdersGateway(context),
getRuntimeStateRepository<OrderSyncState>(context),
getConsolidationOrdersRepository(context),
getStorageGateway(context),
);

return orders.getConsolidationPageCount(context, {});
} catch (originalError) {
throw new CamsError(MODULE_NAME, { originalError });
}
}

export default {
Expand Down
1 change: 1 addition & 0 deletions user-interface/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4729eaf

Please sign in to comment.