diff --git a/apps/backend/src/allocations/allocations.entity.ts b/apps/backend/src/allocations/allocations.entity.ts index 16dbc5d0..724af4bd 100644 --- a/apps/backend/src/allocations/allocations.entity.ts +++ b/apps/backend/src/allocations/allocations.entity.ts @@ -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) diff --git a/apps/backend/src/config/typeorm.ts b/apps/backend/src/config/typeorm.ts index 9f66b3ca..8907de17 100644 --- a/apps/backend/src/config/typeorm.ts +++ b/apps/backend/src/config/typeorm.ts @@ -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', @@ -47,6 +48,7 @@ const config = { UpdateFoodRequests1744051370129, RemoveOrderIdFromRequests1744133526650, UpdatePantriesTable1742739750279, + RemoveOrdersDonationId1761500262238, ], }; diff --git a/apps/backend/src/donationItems/donationItems.entity.ts b/apps/backend/src/donationItems/donationItems.entity.ts index 5994d568..c6f3734b 100644 --- a/apps/backend/src/donationItems/donationItems.entity.ts +++ b/apps/backend/src/donationItems/donationItems.entity.ts @@ -14,9 +14,6 @@ export class DonationItem { @PrimaryGeneratedColumn({ name: 'item_id' }) itemId: number; - @Column({ name: 'donation_id', type: 'int' }) - donationId: number; - @ManyToOne(() => Donation, { nullable: false }) @JoinColumn({ name: 'donation_id', referencedColumnName: 'donationId' }) donation: Donation; diff --git a/apps/backend/src/donationItems/donationItems.module.ts b/apps/backend/src/donationItems/donationItems.module.ts index c93e0614..a416372f 100644 --- a/apps/backend/src/donationItems/donationItems.module.ts +++ b/apps/backend/src/donationItems/donationItems.module.ts @@ -5,9 +5,10 @@ import { DonationItem } from './donationItems.entity'; import { JwtStrategy } from '../auth/jwt.strategy'; import { AuthService } from '../auth/auth.service'; import { DonationItemsController } from './donationItems.controller'; +import { Donation } from '../donations/donations.entity'; @Module({ - imports: [TypeOrmModule.forFeature([DonationItem])], + imports: [TypeOrmModule.forFeature([DonationItem, Donation])], controllers: [DonationItemsController], providers: [DonationItemsService, AuthService, JwtStrategy], }) diff --git a/apps/backend/src/donationItems/donationItems.service.ts b/apps/backend/src/donationItems/donationItems.service.ts index a675eb16..85f8d243 100644 --- a/apps/backend/src/donationItems/donationItems.service.ts +++ b/apps/backend/src/donationItems/donationItems.service.ts @@ -3,16 +3,18 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { DonationItem } from './donationItems.entity'; import { validateId } from '../utils/validation.utils'; +import { Donation } from '../donations/donations.entity'; @Injectable() export class DonationItemsService { constructor( @InjectRepository(DonationItem) private repo: Repository, + @InjectRepository(Donation) private donationRepo: Repository, ) {} async getAllDonationItems(donationId: number): Promise { validateId(donationId, 'Donation'); - return this.repo.findBy({ donationId }); + return this.repo.find({ where: { donation: { donationId } } }); } async create( @@ -25,8 +27,11 @@ export class DonationItemsService { estimatedValue: number, foodType: string, ) { + const donation = await this.donationRepo.findOneBy({ donationId }); + if (!donation) throw new NotFoundException('Donation not found'); + const donationItem = this.repo.create({ - donationId, + donation, itemName, quantity, reservedQuantity, diff --git a/apps/backend/src/foodRequests/request.entity.ts b/apps/backend/src/foodRequests/request.entity.ts index 3c40304e..b4658935 100644 --- a/apps/backend/src/foodRequests/request.entity.ts +++ b/apps/backend/src/foodRequests/request.entity.ts @@ -3,7 +3,7 @@ import { Column, PrimaryGeneratedColumn, CreateDateColumn, - OneToOne, + OneToMany, } from 'typeorm'; import { Order } from '../orders/order.entity'; @@ -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; } diff --git a/apps/backend/src/migrations/1761500262238-RemoveOrdersDonationId.ts b/apps/backend/src/migrations/1761500262238-RemoveOrdersDonationId.ts new file mode 100644 index 00000000..920223a0 --- /dev/null +++ b/apps/backend/src/migrations/1761500262238-RemoveOrdersDonationId.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class RemoveOrdersDonationId1761500262238 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE orders + DROP COLUMN donation_id + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE orders + ADD COLUMN donation_id INT NOT NULL + `); + } +} diff --git a/apps/backend/src/orders/order.controller.ts b/apps/backend/src/orders/order.controller.ts index 42f2214b..230620d2 100644 --- a/apps/backend/src/orders/order.controller.ts +++ b/apps/backend/src/orders/order.controller.ts @@ -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') @@ -66,13 +65,6 @@ export class OrdersController { return this.ordersService.findOrderFoodManufacturer(orderId); } - @Get(':orderId/donation') - async getDonationFromOrder( - @Param('orderId', ParseIntPipe) orderId: number, - ): Promise { - return this.ordersService.findOrderDonation(orderId); - } - @Get('/:orderId') async getOrder( @Param('orderId', ParseIntPipe) orderId: number, diff --git a/apps/backend/src/orders/order.entity.ts b/apps/backend/src/orders/order.entity.ts index 889ccd5b..55b84c9e 100644 --- a/apps/backend/src/orders/order.entity.ts +++ b/apps/backend/src/orders/order.entity.ts @@ -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 { @@ -24,7 +23,7 @@ export class Order { }) pantry: Pantry; - @OneToOne(() => FoodRequest, { nullable: false }) + @ManyToOne(() => FoodRequest, { nullable: false }) @JoinColumn({ name: 'request_id', referencedColumnName: 'requestId', @@ -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', @@ -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; diff --git a/apps/backend/src/orders/order.service.spec.ts b/apps/backend/src/orders/order.service.spec.ts index 586da4c2..f13eea50 100644 --- a/apps/backend/src/orders/order.service.spec.ts +++ b/apps/backend/src/orders/order.service.spec.ts @@ -12,10 +12,15 @@ const mockOrdersRepository = mock>(); const mockPantry: Pantry = { pantryId: 1, pantryName: 'Test Pantry', - address: '123 Test St', + addressLine1: '123 Test St', + addressLine2: 'Apt. 1', + addressCity: 'Boston', + addressState: 'MA', + addressZip: '02115', + addressCountry: 'US', allergenClients: '', refrigeratedDonation: '', - reserveFoodForAllergic: false, + reserveFoodForAllergic: 'Yes', reservationExplanation: '', dedicatedAllergyFriendly: '', clientVisitFrequency: '', @@ -23,12 +28,11 @@ const mockPantry: Pantry = { serveAllergicChildren: '', newsletterSubscription: false, restrictions: [], - ssfRepresentative: null as unknown as User, pantryRepresentative: null as unknown as User, status: 'active', dateApplied: new Date(), - activities: '', - questions: null, + activities: [], + activitiesComments: '', itemsInStock: '', needMoreOptions: '', }; diff --git a/apps/backend/src/orders/order.service.ts b/apps/backend/src/orders/order.service.ts index 611de4bd..13163602 100644 --- a/apps/backend/src/orders/order.service.ts +++ b/apps/backend/src/orders/order.service.ts @@ -116,20 +116,6 @@ export class OrdersService { return order.foodManufacturer; } - async findOrderDonation(orderId: number): Promise { - 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'); diff --git a/apps/backend/src/volunteerAssignments/volunteerAssignments.entity.ts b/apps/backend/src/volunteerAssignments/volunteerAssignments.entity.ts index 438c79aa..d9929fe5 100644 --- a/apps/backend/src/volunteerAssignments/volunteerAssignments.entity.ts +++ b/apps/backend/src/volunteerAssignments/volunteerAssignments.entity.ts @@ -14,9 +14,6 @@ export class Assignments { @PrimaryGeneratedColumn({ name: 'assignment_id' }) assignmentId: number; - @Column({ name: 'volunteer_id' }) - volunteerId: number; - @ManyToOne(() => User, { nullable: false }) @JoinColumn({ name: 'volunteer_id', diff --git a/apps/frontend/src/api/apiClient.ts b/apps/frontend/src/api/apiClient.ts index 1f760c61..e49deaa4 100644 --- a/apps/frontend/src/api/apiClient.ts +++ b/apps/frontend/src/api/apiClient.ts @@ -144,12 +144,6 @@ export class ApiClient { return this.get(`/api/requests/${requestId}`) as Promise; } - public async getDonationFromOrder(orderId: number): Promise { - return this.axiosInstance - .get(`/api/orders/${orderId}/donation`) - .then((response) => response.data); - } - public async getOrderDonation(donationId: number): Promise { return this.get(`/api/donations/${donationId}`) as Promise; }