Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.

Commit 2662f52

Browse files
committed
blah
1 parent d71bd65 commit 2662f52

34 files changed

Lines changed: 97 additions & 1253 deletions

backend/dist/repositories/payment.repository.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,24 @@ class PaymentRepository {
3333
return res.rows[0] || null;
3434
}
3535
async create(data) {
36-
const { mode } = data;
36+
const mode = data.mode;
37+
const status = data.status || 'paid';
38+
const paymentDate = data.paymentDate || new Date();
3739
const res = await postgres_1.pgPool.query(`
38-
INSERT INTO payment (mode)
39-
VALUES ($1)
40-
RETURNING *;
41-
`, [mode]);
40+
INSERT INTO payment (mode, status, payment_date)
41+
VALUES ($1, $2, $3)
42+
RETURNING *;
43+
`, [mode, status, paymentDate]);
4244
return res.rows[0];
4345
}
46+
async linkInvoice(invoiceId, paymentId, status = 'paid') {
47+
const query = `
48+
UPDATE invoice
49+
SET payment_id = $1, status = $2, updated_at = NOW()
50+
WHERE id = $3;
51+
`;
52+
await postgres_1.pgPool.query(query, [paymentId, status, invoiceId]);
53+
}
4454
async update(id, data) {
4555
const fields = [];
4656
const values = [];

backend/dist/services/payment.service.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ class PaymentService {
2323
return this.mapToResponse(payment);
2424
}
2525
async create(data) {
26+
let dbMode = data.mode;
27+
if (data.mode === 'card') {
28+
dbMode = 'credit_card';
29+
}
2630
const payment = await this.repository.create({
27-
mode: data.mode
31+
mode: dbMode,
32+
status: data.status || 'paid',
33+
paymentDate: data.paymentDate || new Date()
2834
});
35+
if (data.invoiceId) {
36+
await this.repository.linkInvoice(data.invoiceId, payment.id, 'paid');
37+
}
2938
const paymentResponse = await this.mapToResponse(payment);
3039
return {
3140
payment: paymentResponse
@@ -54,11 +63,11 @@ class PaymentService {
5463
async mapToResponse(payment) {
5564
return {
5665
id: payment.id,
57-
paymentDate: payment.paymentDate,
66+
paymentDate: payment.paymentDate || payment.PaymentDate || payment.payment_date,
5867
mode: payment.mode,
5968
status: payment.status,
60-
createdAt: payment.createdAt,
61-
updatedAt: payment.updatedAt
69+
createdAt: payment.createdAt || payment.CreatedAt || payment.created_at,
70+
updatedAt: payment.updatedAt || payment.UpdatedAt || payment.updated_at
6271
};
6372
}
6473
}

backend/src/models/payment.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export interface Payment {
3333
}
3434

3535
export interface CreatePaymentDTO {
36+
invoiceId: number;
3637
mode: PaymentMode;
38+
paymentDate?: Date;
39+
status?: PaymentStatus;
3740
}
3841

3942
export interface UpdatePaymentDTO {

backend/src/repositories/payment.repository.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,32 @@ export class PaymentRepository {
3535
return res.rows[0] || null;
3636
}
3737

38-
async create(data: Omit<Payment, 'id' | 'paymentDate' | 'status' | 'createdAt' | 'updatedAt'>): Promise<Payment> {
39-
const {
40-
mode
41-
} = data;
38+
async create(data: { mode: string; status?: string; paymentDate?: Date }): Promise<Payment> {
39+
const mode = data.mode;
40+
const status = data.status || 'paid';
41+
const paymentDate = data.paymentDate || new Date();
4242

4343
const res = await pgPool.query(
44-
`
45-
INSERT INTO payment (mode)
46-
VALUES ($1)
47-
RETURNING *;
48-
`,
49-
[mode]
44+
`
45+
INSERT INTO payment (mode, status, payment_date)
46+
VALUES ($1, $2, $3)
47+
RETURNING *;
48+
`,
49+
[mode, status, paymentDate]
5050
);
5151

5252
return res.rows[0];
5353
}
5454

55+
async linkInvoice(invoiceId: number, paymentId: number, status: string = 'paid'): Promise<void> {
56+
const query = `
57+
UPDATE invoice
58+
SET payment_id = $1, status = $2, updated_at = NOW()
59+
WHERE id = $3;
60+
`;
61+
await pgPool.query(query, [paymentId, status, invoiceId]);
62+
}
63+
5564
async update(id: number, data: UpdatePaymentDTO): Promise<Payment | null> {
5665
const fields = [];
5766
const values = [];

backend/src/services/payment.service.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,21 @@ export class PaymentService {
2828
}
2929

3030
async create(data: CreatePaymentDTO) {
31+
let dbMode: any = data.mode;
32+
if ((data.mode as any) === 'card') {
33+
dbMode = 'credit_card';
34+
}
35+
3136
const payment = await this.repository.create({
32-
mode: data.mode
37+
mode: dbMode,
38+
status: data.status || 'paid',
39+
paymentDate: data.paymentDate || new Date()
3340
});
3441

42+
if (data.invoiceId) {
43+
await this.repository.linkInvoice(data.invoiceId, payment.id, 'paid');
44+
}
45+
3546
const paymentResponse = await this.mapToResponse(payment);
3647

3748
return {
@@ -67,11 +78,11 @@ export class PaymentService {
6778
private async mapToResponse(payment: any): Promise<Payment> {
6879
return {
6980
id: payment.id,
70-
paymentDate: payment.paymentDate,
81+
paymentDate: payment.paymentDate || payment.PaymentDate || payment.payment_date,
7182
mode: payment.mode,
7283
status: payment.status,
73-
createdAt: payment.createdAt,
74-
updatedAt: payment.updatedAt
84+
createdAt: payment.createdAt || payment.CreatedAt || payment.created_at,
85+
updatedAt: payment.updatedAt || payment.UpdatedAt || payment.updated_at
7586
};
7687
}
7788
}

frontend/src/app/cart.component.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class CartComponent {
111111
return {
112112
type: 'product',
113113
name: prod.name,
114-
price: prod.price,
114+
price: prod.basePrice || prod.price,
115115
quantity: item.quantity,
116116
options
117117
};
@@ -147,7 +147,7 @@ export class CartComponent {
147147
});
148148

149149
return {
150-
name: cust.productName,
150+
name: 'Sélection',
151151
item: {
152152
name: cust.productName,
153153
delta: 0,
@@ -181,10 +181,21 @@ export class CartComponent {
181181

182182
this.orderService.placeOrder(backendOrder).subscribe({
183183
next: (res) => {
184-
console.log('[Order] Commande soumise avec succès, ID:', res.data.id);
185-
this.cartService.clearCart();
186-
this.checkoutForm.reset();
187-
this.step.set('confirm');
184+
const invoiceId = res.data.id;
185+
console.log('[Order] Commande soumise avec succès, ID:', invoiceId);
186+
187+
this.orderService.makePayment(invoiceId, 'card').subscribe({
188+
next: () => {
189+
console.log('[Order] Paiement établi avec succès pour invoice:', invoiceId);
190+
this.cartService.clearCart();
191+
this.checkoutForm.reset();
192+
this.step.set('confirm');
193+
},
194+
error: (payErr) => {
195+
console.error('[Order] Erreur de paiement:', payErr);
196+
alert("Une erreur s'est produite lors du paiement. Veuillez réessayer.");
197+
}
198+
});
188199
},
189200
error: (err) => {
190201
console.error('[Order] Erreur de commande:', err);

frontend/src/app/services/cart.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface CartProductEntry {
99
description: string;
1010
image: string;
1111
price: number;
12+
basePrice: number;
1213
customization: {
1314
ingredients: Ingredient[];
1415
extras: Extra[];
@@ -125,6 +126,7 @@ export class CartService {
125126
description: product.description,
126127
image: product.image,
127128
price,
129+
basePrice: product.price,
128130
customization: {
129131
ingredients: ingredients.map(i => ({ ...i })),
130132
extras: extras.map(e => ({ ...e })),
@@ -194,6 +196,7 @@ export class CartService {
194196
product: {
195197
...i.product!,
196198
price,
199+
basePrice: basePrice,
197200
customization: {
198201
ingredients: ingredients.map(x => ({ ...x })),
199202
extras: extras.map(x => ({ ...x })),

frontend/src/app/services/order.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ export class OrderService {
4343
{ headers: this.authHeaders }
4444
);
4545
}
46+
47+
makePayment(invoiceId: number, mode: string): Observable<{ success: boolean; message: string }> {
48+
return this.http.post<{ success: boolean; message: string }>(
49+
`${this.apiUrl}/payments`,
50+
{
51+
invoiceId,
52+
mode,
53+
date: new Date().toISOString()
54+
},
55+
{ headers: this.authHeaders }
56+
);
57+
}
4658
}

legacy/db/migrations/R__automatic_account_deletion.sql

Lines changed: 0 additions & 10 deletions
This file was deleted.

legacy/db/migrations/V1_0_0__primary_tables.sql

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)