Skip to content

Commit

Permalink
Merge branch 'fix-payment' of https://github.com/atlp-rwanda/knights-…
Browse files Browse the repository at this point in the history
…ecomm-be into fix-payment
  • Loading branch information
maxCastro1 committed Jul 17, 2024
2 parents 50bca3d + aed8a54 commit 685c692
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 30 deletions.
29 changes: 0 additions & 29 deletions migrations/1714595134552-UserMigration.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/__test__/orderManagement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const sampleOrder = {
buyer: sampleBuyer,
orderStatus: 'received',
address: 'Rwanda, Kigali, KK20st',
cartId: uuid()
};
const sampleOrder2 = {
id: order2Id,
Expand All @@ -142,6 +143,7 @@ const sampleOrder2 = {
buyer: sampleBuyer,
orderStatus: 'order placed',
address: 'Rwanda, Kigali, KK20st',
cartId: uuid()
};

const sampleOrderItem = {
Expand Down
2 changes: 2 additions & 0 deletions src/__test__/user.entity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const sampleOrder = {
quantity: 2,
orderDate: new Date(),
buyer: sampleBuyer,
cartId:uuid(),
orderStatus: 'received',
address: 'Rwanda, Kigali, KK20st',
};
Expand Down Expand Up @@ -247,6 +248,7 @@ describe('User Entity', () => {
buyer: savedUser,
orderStatus: 'order placed',
address: 'Rwanda, Kigali, KK20st',
cartId: uuid(),
});

const savedOrder = await orderRepository.save(order);
Expand Down
8 changes: 7 additions & 1 deletion src/entities/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
OneToMany,
CreateDateColumn,
UpdateDateColumn,
OneToOne,
} from 'typeorm';
import { IsNotEmpty, IsNumber, IsDate, IsIn } from 'class-validator';
import { User } from './User';
import { OrderItem } from './OrderItem';
import { Transaction } from './transaction';
import { Feedback } from './Feedback';
import { Cart } from './Cart';

@Entity()
export class Order {
Expand All @@ -22,7 +24,11 @@ export class Order {
@ManyToOne(() => User, user => user.orders)
@IsNotEmpty()
buyer!: User;


@Column('uuid')
@IsNotEmpty()
cartId!: string;

@OneToMany(() => OrderItem, orderItem => orderItem.order, { cascade: true })
@IsNotEmpty()
orderItems!: OrderItem[];
Expand Down
2 changes: 2 additions & 0 deletions src/services/orderServices/createOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const createOrderService = async (req: Request, res: Response) => {
newOrder.quantity = cart.items.reduce((acc, item) => acc + item.quantity, 0);
newOrder.orderDate = new Date();
newOrder.address = `${address.country}, ${address.city}, ${address.street}`;
newOrder.cartId = cart.id;

await getManager().transaction(async transactionalEntityManager => {
for (const item of cart.items) {
Expand Down Expand Up @@ -107,6 +108,7 @@ export const createOrderService = async (req: Request, res: Response) => {
quantity: newOrder.quantity,
orderDate: newOrder.orderDate,
address: newOrder.address,
cartId: newOrder.cartId
};

const message = {
Expand Down
1 change: 1 addition & 0 deletions src/services/orderServices/getOrderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const getOrderService = async (req: Request, res: Response) => {
quantity: order.quantity,
address: order.address,
orderDate: order.orderDate,
cartId: order.cartId,
createdAt: order.createdAt,
updatedAt: order.updatedAt,
buyer: {
Expand Down

0 comments on commit 685c692

Please sign in to comment.