Skip to content

Commit

Permalink
fix: fix query used for trx ui graphs (#21)
Browse files Browse the repository at this point in the history
* chore: regenerate prisma

* fix test and audit

* log test

* log test

* test

* fix: fix query used for trx ui graphs

* fetch participant from participantId instead of participantCurrency
  • Loading branch information
kleyow authored Aug 30, 2024
1 parent 2d5a52b commit b182c14
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 39 deletions.
14 changes: 13 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ services:
retries: 30
interval: 15s

reporting-hub-bop-api-svc:
build:
context: .
environment:
- LOG_LEVEL=debug
volumes:
- ./config/default.json:/opt/reporting/config/default.json
ports:
- "3000:3000"
# Important to specify the network_mode as host to allow the service to connect to the host machine
network_mode: host

## TODO: The following sections are provided as future proof and can be enabled later.
## Currently we can't query the event information from api service as there is no functionality in ml-core-test-harness to push the audit messages to kafka notification topic.
## When it's implemented, we can enable the following services to process and store the events and run queries on that data from api service.
Expand Down Expand Up @@ -57,4 +69,4 @@ services:

volumes:
db-data:
driver: local
driver: local
1 change: 1 addition & 0 deletions prisma/base/centralLedger.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ model transferParticipant {
participantCurrency participantCurrency? @relation(fields: [participantCurrencyId], references: [participantCurrencyId], onDelete: NoAction, onUpdate: NoAction, map: "transferparticipant_participantcurrencyid_foreign")
transfer transfer @relation(fields: [transferId], references: [transferId], onDelete: NoAction, onUpdate: NoAction, map: "transferparticipant_transferid_foreign")
transferParticipantRoleType transferParticipantRoleType @relation(fields: [transferParticipantRoleTypeId], references: [transferParticipantRoleTypeId], onDelete: NoAction, onUpdate: NoAction, map: "transferparticipant_transferparticipantroletypeid_foreign")
participant participant @relation(fields: [participantId], references: [participantId], onDelete: NoAction, onUpdate: NoAction, map: "participant_participantid_foreign")
@@index([transferId, transferParticipantRoleTypeId, ledgerEntryTypeId], map: "getTransferInfoToChangePosition")
@@index([ledgerEntryTypeId], map: "transferparticipant_ledgerentrytypeid_index")
Expand Down
8 changes: 4 additions & 4 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ export interface Context {
getRequestFields: typeof getRequestFields;
}

const csMongoDBObj = new ConnectionString()
const csMongoDBObj = new ConnectionString();
csMongoDBObj.setDefaults({
protocol: 'mongodb',
hosts: [{ name: Config.EVENT_STORE_DB.HOST, port: Config.EVENT_STORE_DB.PORT}],
hosts: [{ name: Config.EVENT_STORE_DB.HOST, port: Config.EVENT_STORE_DB.PORT }],
user: Config.EVENT_STORE_DB.USER,
password: Config.EVENT_STORE_DB.PASSWORD,
path: [Config.EVENT_STORE_DB.DATABASE]
})
path: [Config.EVENT_STORE_DB.DATABASE],
});

export const createContext = async (ctx: any): Promise<Context> => ({
...ctx,
Expand Down
27 changes: 17 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ import bodyParser from 'body-parser';
const app = express();
const httpServer = http.createServer(app);

const authMiddleware = createAuthMiddleware(Config.USER_ID_HEADER, Config.ORY_KETO_READ_URL, Config.AUTH_CHECK_PARTICIPANTS);
const authMiddleware = createAuthMiddleware(
Config.USER_ID_HEADER,
Config.ORY_KETO_READ_URL,
Config.AUTH_CHECK_PARTICIPANTS
);

const loggerPlugin = {
// Fires whenever a GraphQL request is received from a client.
Expand All @@ -43,17 +47,21 @@ const loggerPlugin = {
const startServer = async () => {
const server = new ApolloServer<Context>({
schema: applyMiddleware(schema, authMiddleware),
plugins: [ApolloServerPluginLandingPageGraphQLPlayground(), loggerPlugin, ApolloServerPluginDrainHttpServer({ httpServer })],
plugins: [
ApolloServerPluginLandingPageGraphQLPlayground(),
loggerPlugin,
ApolloServerPluginDrainHttpServer({ httpServer }),
],
// healthCheckPath: '/health',
});
await server.start();
const corsOptions = {
origin: Config.CORS_WHITELIST,
credentials: Config.ALLOW_CREDENTIALS
}
credentials: Config.ALLOW_CREDENTIALS,
};
app.get('/health', (req, res) => {
res.json({
status: 'OK'
status: 'OK',
});
});
app.use(
Expand All @@ -65,13 +73,12 @@ const startServer = async () => {
// an Apollo Server instance and optional configuration options
expressMiddleware(server, {
context: createContext,
}),
})
);

// Modified server startup
await new Promise<void>((resolve) => httpServer.listen({ port: Config.PORT }, resolve));
console.log(`🚀 Server ready at http://localhost:${Config.PORT}/`);
};

}

startServer()
startServer();
27 changes: 8 additions & 19 deletions src/schema/Transfer/dataloaders/DFSP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,20 @@ const findDfsps = async (ctx: Context, transferIds: string[], type: DFSPType) =>
},
select: {
transferId: true,
participantCurrency: {
include: {
participant: true,
},
},
participant: true
},
});
return Object.fromEntries(
transferParticipant.map((t) => {
const p = t.participantCurrency?.participant;
const p = t.participant;
return [
t.transferId,
p
? {
id: p?.participantId,
name: p?.name,
description: p?.description,
active: p?.isActive,
}
: {
id: 0,
name: 'Unknown',
description: 'Unknown',
active: false,
},
{
id: p?.participantId || 0,
name: p?.name || '-',
description: p?.description || '-',
active: p?.isActive || false,
},
];
})
);
Expand Down
6 changes: 2 additions & 4 deletions src/schema/TransferSummary/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ const Query = extendType({
LEFT JOIN transferFulfilment tF ON t.transferId = tF.transferId
LEFT JOIN transferParticipant tPPayer ON tPPayer.transferId = t.transferId
AND tPPayer.transferParticipantRoleTypeId = (SELECT transferParticipantRoleTypeId from transferParticipantRoleType WHERE name = 'PAYER_DFSP')
LEFT JOIN participantCurrency pCPayer ON pCPayer.participantCurrencyId = tPPayer.participantCurrencyId
LEFT JOIN participant pPayer ON pPayer.participantId = pCPayer.participantId
LEFT JOIN participant pPayer ON pPayer.participantId = tPPayer.participantId
LEFT JOIN transferParticipant tPPayee ON tPPayee.transferId = t.transferId
AND tPPayee.transferParticipantRoleTypeId = (SELECT transferParticipantRoleTypeId from transferParticipantRoleType WHERE name = 'PAYEE_DFSP')
LEFT JOIN participantCurrency pCPayee ON pCPayee.participantCurrencyId = tPPayee.participantCurrencyId
LEFT JOIN participant pPayee ON pPayee.participantId = pCPayee.participantId
LEFT JOIN participant pPayee ON pPayee.participantId = tPPayee.participantId
LEFT JOIN currency c on t.currencyId = c.currencyId
LEFT JOIN transferError tE on t.transferId = tE.transferId
WHERE TRUE
Expand Down
2 changes: 1 addition & 1 deletion src/schema/TransferSummary/TransferSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { objectType } from 'nexus';
const TransferSummary = objectType({
name: 'TransferSummary',
definition(t) {
t.nonNull.int('count');
t.nonNull.bigInt('count');
t.nonNull.decimal('amount');
t.field('errorCode', { type: 'Int' });
t.field('payerDFSP', { type: 'String' });
Expand Down

0 comments on commit b182c14

Please sign in to comment.