Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/backend/src/allocations/allocations.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Allocation {
@Column({ name: 'order_id', type: 'int' })
orderId: number;

@Column({ name: 'item_id', type: 'int' })
@Column({ name: 'item_id', type: 'int', nullable: false })
itemId: number;

@ManyToOne(() => DonationItem, (item) => item.allocations)
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/src/config/typeorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { UpdateRequestTable1741571847063 } from '../migrations/1741571847063-upd
import { RemoveOrderIdFromRequests1744133526650 } from '../migrations/1744133526650-removeOrderIdFromRequests.ts';
import { AddOrders1739496585940 } from '../migrations/1739496585940-addOrders';
import { UpdatePantriesTable1742739750279 } from '../migrations/1742739750279-updatePantriesTable';
import { RemoveOrdersDonationId1761500262238 } from '../migrations/1761500262238-RemoveOrdersDonationId';

const config = {
type: 'postgres',
Expand Down Expand Up @@ -47,6 +48,7 @@ const config = {
UpdateFoodRequests1744051370129,
RemoveOrderIdFromRequests1744133526650,
UpdatePantriesTable1742739750279,
RemoveOrdersDonationId1761500262238,
],
};

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/foodRequests/request.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Column,
PrimaryGeneratedColumn,
CreateDateColumn,
OneToOne,
OneToMany,
} from 'typeorm';
import { Order } from '../orders/order.entity';

Expand Down Expand Up @@ -40,6 +40,6 @@ export class FoodRequest {
@Column({ name: 'photos', type: 'text', array: true, nullable: true })
photos: string[];

@OneToOne(() => Order, (order) => order.request, { nullable: true })
@OneToMany(() => Order, (order) => order.request, { nullable: true })
order: Order;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class RemoveOrdersDonationId1761500262238 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE orders
DROP COLUMN donation_id
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE orders
ADD COLUMN donation_id INT NOT NULL
`);
}
}
8 changes: 0 additions & 8 deletions apps/backend/src/orders/order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Order } from './order.entity';
import { Pantry } from '../pantries/pantries.entity';
import { FoodManufacturer } from '../foodManufacturers/manufacturer.entity';
import { FoodRequest } from '../foodRequests/request.entity';
import { Donation } from '../donations/donations.entity';
import { AllocationsService } from '../allocations/allocations.service';

@Controller('orders')
Expand Down Expand Up @@ -66,13 +65,6 @@ export class OrdersController {
return this.ordersService.findOrderFoodManufacturer(orderId);
}

@Get(':orderId/donation')
async getDonationFromOrder(
@Param('orderId', ParseIntPipe) orderId: number,
): Promise<Donation> {
return this.ordersService.findOrderDonation(orderId);
}

@Get('/:orderId')
async getOrder(
@Param('orderId', ParseIntPipe) orderId: number,
Expand Down
12 changes: 2 additions & 10 deletions apps/backend/src/orders/order.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { FoodRequest } from '../foodRequests/request.entity';
import { Pantry } from '../pantries/pantries.entity';
import { FoodManufacturer } from '../foodManufacturers/manufacturer.entity';
import { Donation } from '../donations/donations.entity';

@Entity('orders')
export class Order {
Expand All @@ -24,7 +23,7 @@ export class Order {
})
pantry: Pantry;

@OneToOne(() => FoodRequest, { nullable: false })
@ManyToOne(() => FoodRequest, { nullable: false })
@JoinColumn({
name: 'request_id',
referencedColumnName: 'requestId',
Expand All @@ -34,7 +33,7 @@ export class Order {
@Column({ name: 'request_id' })
requestId: number;

@ManyToOne(() => FoodManufacturer, { nullable: true })
@ManyToOne(() => FoodManufacturer, { nullable: false })
@JoinColumn({
name: 'shipped_by',
referencedColumnName: 'foodManufacturerId',
Expand All @@ -44,13 +43,6 @@ export class Order {
@Column({ name: 'shipped_by', nullable: true })
shippedBy: number;

@ManyToOne(() => Donation, { nullable: false })
@JoinColumn({
name: 'donation_id',
referencedColumnName: 'donationId',
})
donation: Donation;

@Column({ name: 'status', type: 'varchar', length: 25, default: 'pending' })
status: string;

Expand Down
14 changes: 0 additions & 14 deletions apps/backend/src/orders/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,6 @@ export class OrdersService {
return order.foodManufacturer;
}

async findOrderDonation(orderId: number): Promise<Donation> {
validateId(orderId, 'Order');

const order = await this.repo.findOne({
where: { orderId },
relations: ['donation'],
});

if (!order) {
throw new NotFoundException(`Order ${orderId} not found`);
}
return order.donation;
}

async updateStatus(orderId: number, newStatus: string) {
validateId(orderId, 'Order');

Expand Down
6 changes: 0 additions & 6 deletions apps/frontend/src/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ export class ApiClient {
return this.get(`/api/requests/${requestId}`) as Promise<FoodRequest>;
}

public async getDonationFromOrder(orderId: number): Promise<Donation | null> {
return this.axiosInstance
.get(`/api/orders/${orderId}/donation`)
.then((response) => response.data);
}

public async getOrderDonation(donationId: number): Promise<Donation> {
return this.get(`/api/donations/${donationId}`) as Promise<Donation>;
}
Expand Down