Skip to content

Commit

Permalink
Merge pull request #13 from StartUpNationLabs/implemBackFront
Browse files Browse the repository at this point in the history
Implem back front
  • Loading branch information
Apoorva64 authored Nov 3, 2024
2 parents fea3f18 + 0d1ccf5 commit 8bca2b5
Show file tree
Hide file tree
Showing 24 changed files with 539 additions and 162 deletions.
3 changes: 2 additions & 1 deletion apps/backend-bff/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
KITCHEN_BASE_URL=https://kitchen-backend.spos.polytech.apoorva64.com
MENU_BASE_URL=https://menu-backend.spos.polytech.apoorva64.com
DINING_BASE_URL=https://dining-backend.spos.polytech.apoorva64.com
ORDERING_BASE_URL=https://ordering.spos.dev.polytech.apoorva64.com
ORDERING_BASE_URL=http://localhost:3003

6 changes: 3 additions & 3 deletions apps/frontend-bff/.env.development
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VITE_KITCHEN_BASE_URL=https://kitchen-backend.spos.polytech.apoorva64.com
VITE_MENU_BASE_URL=https://menu-backend.spos.polytech.apoorva64.com
VITE_DINING_BASE_URL=https://dining-backend.spos.polytech.apoorva64.com
VITE_BFF_BASE_URL=https://backend-bff.spos.dev.polytech.apoorva64.com
VITE_PAYMENT_SHARING_BASE_URL=https://payment-sharing.spos.dev.polytech.apoorva64.com
VITE_ORDERING_BASE_URL=https://ordering.spos.dev.polytech.apoorva64.com
VITE_BFF_BASE_URL=http://localhost:3000
VITE_PAYMENT_SHARING_BASE_URL=http://localhost:3002
VITE_ORDERING_BASE_URL=http://localhost:3003
6 changes: 3 additions & 3 deletions apps/frontend-common-space/.env.development
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VITE_KITCHEN_BASE_URL=https://kitchen-backend.spos.polytech.apoorva64.com
VITE_MENU_BASE_URL=https://menu-backend.spos.polytech.apoorva64.com
VITE_DINING_BASE_URL=https://dining-backend.spos.polytech.apoorva64.com
VITE_BFF_BASE_URL=https://backend-bff.spos.polytech.apoorva64.com
VITE_PAYMENT_SHARING_BASE_URL=https://payment-sharing.spos.polytech.apoorva64.com
VITE_ORDERING_BASE_URL=https://ordering.spos.polytech.apoorva64.com
VITE_BFF_BASE_URL=http://localhost:3000
VITE_PAYMENT_SHARING_BASE_URL=http://localhost:3002
VITE_ORDERING_BASE_URL=http://localhost:3003
7 changes: 4 additions & 3 deletions apps/frontend-common-space/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function App() {
<div>
<Routes>
<Route
path="/payementAsignee"
path="/payementAsignee/:groupId/:tableNumber"
element={
<Box
sx={{
Expand All @@ -36,11 +36,12 @@ export function App() {
}
/>
<Route path="/thanks" element={<Thanks />} />
<Route path="/diningRoomTables" element={<DiningRoomTables />} />
<Route path="/diningRoomTables/:groupId/:tableNumber" element={<DiningRoomTables />} />
<Route
path={"/mealSelectionForPayment/:groupId/:tableNumber"}
path={"/mealSelectionForPayment/:tableNumber"}
element={<MealSelectionForPayment />}
/>

</Routes>
{/* END: routes */}
</div>
Expand Down
5 changes: 3 additions & 2 deletions apps/frontend-personal-space/.env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VITE_KITCHEN_BASE_URL=https://kitchen-backend.spos.polytech.apoorva64.com
VITE_MENU_BASE_URL=https://menu-backend.spos.polytech.apoorva64.com
VITE_DINING_BASE_URL=https://dining-backend.spos.polytech.apoorva64.com
VITE_BFF_BASE_URL=https://backend-bff.spos.dev.polytech.apoorva64.com
VITE_PAYMENT_SHARING_BASE_URL=https://payment-sharing.spos.dev.polytech.apoorva64.com
VITE_BFF_BASE_URL=http://localhost:3000
VITE_PAYMENT_SHARING_BASE_URL=http://localhost:3002
VITE_ORDERING_BASE_URL=http://localhost:3003
2 changes: 1 addition & 1 deletion apps/frontend-personal-space/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function App() {
<div>
<Routes>
<Route path={"/:groupId/:tableNumber/:ownerId"} element={<PersonalOrdering/>} />
<Route path="/personalBilling/:groupId/:tableNumber/:ownerId" element={<PersonalBilling />} />
<Route path="/personalBilling/:tableNumber/:ownerId" element={<PersonalBilling />} />
<Route path="/thanks" element={<Thanks />} />
</Routes>
{/* END: routes */}
Expand Down
59 changes: 44 additions & 15 deletions apps/frontend-personal-space/src/app/pages/Personal-billing.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { useNavigate, useParams } from 'react-router-dom';
import { Box, Button, Typography } from '@mui/material';
import { Box, Button, CircularProgress, Typography } from '@mui/material';
import { SSEProvider, useSSE } from 'react-hooks-sse';
import { TableBillingShell, GroupClosedListener } from '@spos/ui/common';
import { useMutation } from '@tanstack/react-query';
import { GroupClosedListener, TableBillingShell } from '@spos/ui/common';
import { useMutation, useQuery } from '@tanstack/react-query';
import {
Configuration,
ItemRequestDto,
PaymentsApi, PaymentsApiPaymentControllerMakePaymentRequest,
SelectedByCustomerDTO
PaymentsApi,
PaymentsApiPaymentControllerMakePaymentRequest,
SelectedByCustomerDTO,
} from '@spos/clients-payment-sharing';
import { TableItem } from '@spos/services/common';
import React from 'react';
import {
Configuration as ConfigurationGroup,
RemoteGroupApi,
} from '@spos/clients-bff';

interface TablesProps {
groupId: string;
Expand Down Expand Up @@ -180,14 +185,29 @@ const PriceDisplay = () => {

export function PersonalBilling() {
const navigate = useNavigate();
const { groupId, tableNumber, ownerId } = useParams<{
groupId: string;
const { tableNumber, ownerId } = useParams<{
tableNumber: string;
ownerId: string;
}>();
const { data: groupId } = useQuery({
queryKey: ['group', tableNumber],
queryFn: async () => {
const api = new RemoteGroupApi(
new ConfigurationGroup({ basePath: import.meta.env.VITE_BFF_BASE_URL })
);

return (
await api.remoteGroupControllerGetGroupFromTableNumber({
tableNumber: tableNumber || '',
})
).data.id;
},
});

const partialPaymentMutation = useMutation({
mutationFn: (paymentsApiPaymentControllerMakePaymentRequest: PaymentsApiPaymentControllerMakePaymentRequest) => {
mutationFn: (
paymentsApiPaymentControllerMakePaymentRequest: PaymentsApiPaymentControllerMakePaymentRequest
) => {
console.log(paymentsApiPaymentControllerMakePaymentRequest);
return new PaymentsApi(
new Configuration({
Expand All @@ -198,15 +218,21 @@ export function PersonalBilling() {
})
).paymentControllerMakePayment({
groupId: paymentsApiPaymentControllerMakePaymentRequest.groupId,
ownerId: paymentsApiPaymentControllerMakePaymentRequest.ownerId
ownerId: paymentsApiPaymentControllerMakePaymentRequest.ownerId,
});
},
onSuccess: (data) => {
if (data.data) {
navigate('/thanks');
}
}
},
});
if (!tableNumber) {
throw new Error('Table number is required');
}
if (!groupId) {
return <CircularProgress />;
}

return (
<Box
Expand All @@ -228,7 +254,8 @@ export function PersonalBilling() {
<SSEProvider
endpoint={
`${
import.meta.env.VITE_PAYMENT_SHARING_BASE_URL}/api/payments/sse/customer-items/` +
import.meta.env.VITE_PAYMENT_SHARING_BASE_URL
}/api/payments/sse/customer-items/` +
groupId +
'/' +
ownerId
Expand Down Expand Up @@ -269,10 +296,12 @@ export function PersonalBilling() {
>
<PriceDisplay />
<Button
onClick={() => partialPaymentMutation.mutate({
groupId: groupId ?? "",
ownerId: ownerId ?? ""
})}
onClick={() =>
partialPaymentMutation.mutate({
groupId: groupId ?? '',
ownerId: ownerId ?? '',
})
}
variant="contained"
color="inherit"
sx={{
Expand Down
26 changes: 16 additions & 10 deletions apps/payment-sharing/src/app/payment/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class PaymentService {
}

async makePayment(group_id: string, owner_id: string): Promise<boolean> {
return await this.tracer.startActiveSpan('makePayment', async (span) => {
return await this.tracer.startActiveSpan('makePayment', async (span) => {
try {
this.logger.log(
`Making payment for group_id: ${group_id}, owner_id: ${owner_id}`
Expand All @@ -354,13 +354,14 @@ export class PaymentService {
});
});

const isFinished =(
const isFinished = (
await this.billingsApi.remoteBillingControllerPartialPayment({
annotatedMonsieurAxelMenvoie2: {
groupId: group_id,
elementToBePaid: tableItems,
},
})).data;
})
).data;

// remove all selected items
const selectedItems = await this.repository
Expand All @@ -370,15 +371,17 @@ export class PaymentService {
.and('owner_id')
.equals(owner_id)
.return.all();
await this.repository.remove(selectedItems.map((item) => item[EntityId]));
await this.repository.remove(
selectedItems.map((item) => item[EntityId])
);

await this.publishWithContext('update-payment', {
group_id,
owner_id,
action: 'pay',
actionData: {
isFinished,
}
},
});
return isFinished;
} finally {
Expand All @@ -393,11 +396,14 @@ export class PaymentService {
this.logger.log('Handling update payment');
const subscription = this.redisClient.duplicate();
await subscription.connect();
await subscription.subscribe('update-payment', async (message) => {
const data = JSON.parse(message);
this.logger.log(`Received update-payment event: ${message}`);
this.eventEmitter.emit('update-payment', data);
});
await subscription.subscribe(
['update-payment', 'order'],
async (message) => {
const data = JSON.parse(message);
this.logger.log(`Received update-payment event: ${message}`);
this.eventEmitter.emit('update-payment', data);
}
);
} finally {
span.end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ export class BillingServiceWorkflow implements BillingService {
}
}
}

const itemList = Object.values(tableItems).filter(
(item) => item.remaining > 0
)
tableSummary.push({
number: table.number,
elements: Object.values(tableItems),
elements: itemList,
});
}
return tableSummary;
Expand Down
1 change: 0 additions & 1 deletion libs/services/common/src/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export const logger = afterMethod((meta) => {
`Method: ${meta.method.name}',
'Class: ${meta.target.constructor.name}',
'Arguments: ${meta.args}`,
meta.result
);
});
1 change: 1 addition & 0 deletions libs/ui/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ export * from './lib/commandsR/mealSelectionForPayment';
export * from './lib/commandsR/stores/cart';
export * from './lib/thanks/thanks';
export * from './lib/utils/GroupClosedListener';
export * from './lib/utils/uniqueSvgTable';
Loading

0 comments on commit 8bca2b5

Please sign in to comment.