From 8193770f9c35138b170c12d5667fcaa3d95b1364 Mon Sep 17 00:00:00 2001 From: skewalia <145241312+swarkewalia@users.noreply.github.com> Date: Sun, 8 Mar 2026 11:16:35 -0400 Subject: [PATCH 1/3] backend validation accept/deny --- .../manufacturers.service.ts | 19 ++++++++++++++++++- apps/backend/src/pantries/pantries.service.ts | 13 +++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/backend/src/foodManufacturers/manufacturers.service.ts b/apps/backend/src/foodManufacturers/manufacturers.service.ts index 73a3a12d..21b2d426 100644 --- a/apps/backend/src/foodManufacturers/manufacturers.service.ts +++ b/apps/backend/src/foodManufacturers/manufacturers.service.ts @@ -1,4 +1,8 @@ -import { Injectable, NotFoundException } from '@nestjs/common'; +import { + Injectable, + NotFoundException, + BadRequestException, +} from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { FoodManufacturer } from './manufacturers.entity'; import { Repository } from 'typeorm'; @@ -28,6 +32,7 @@ export class FoodManufacturersService { const foodManufacturer = await this.repo.findOne({ where: { foodManufacturerId }, + relations: ['foodManufacturerRepresentative'], }); if (!foodManufacturer) { @@ -126,6 +131,12 @@ export class FoodManufacturersService { throw new NotFoundException(`Food Manufacturer ${id} not found`); } + if (foodManufacturer.status !== ApplicationStatus.PENDING) { + throw new BadRequestException( + `Cannot approve a Food Manufacturer with status: ${foodManufacturer.status}`, + ); + } + const createUserDto: userSchemaDto = { email: foodManufacturer.foodManufacturerRepresentative.email, firstName: foodManufacturer.foodManufacturerRepresentative.firstName, @@ -152,6 +163,12 @@ export class FoodManufacturersService { throw new NotFoundException(`Food Manufacturer ${id} not found`); } + if (foodManufacturer.status !== ApplicationStatus.PENDING) { + throw new BadRequestException( + `Cannot deny a Food Manufacturer with status: ${foodManufacturer.status}`, + ); + } + await this.repo.update(id, { status: ApplicationStatus.DENIED }); } } diff --git a/apps/backend/src/pantries/pantries.service.ts b/apps/backend/src/pantries/pantries.service.ts index 9c7cffe3..15cd3d1c 100644 --- a/apps/backend/src/pantries/pantries.service.ts +++ b/apps/backend/src/pantries/pantries.service.ts @@ -3,6 +3,7 @@ import { Inject, Injectable, NotFoundException, + BadRequestException, } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { In, Repository } from 'typeorm'; @@ -117,6 +118,12 @@ export class PantriesService { throw new NotFoundException(`Pantry ${id} not found`); } + if (pantry.status !== ApplicationStatus.PENDING) { + throw new BadRequestException( + `Cannot approve a pantry with status: ${pantry.status}`, + ); + } + const createUserDto: userSchemaDto = { ...pantry.pantryUser, role: Role.PANTRY, @@ -138,6 +145,12 @@ export class PantriesService { throw new NotFoundException(`Pantry ${id} not found`); } + if (pantry.status !== ApplicationStatus.PENDING) { + throw new BadRequestException( + `Cannot deny a pantry with status: ${pantry.status}`, + ); + } + await this.repo.update(id, { status: ApplicationStatus.DENIED }); } From f1503f59bc6f0f11ecc112a3c1a9b704de41e62b Mon Sep 17 00:00:00 2001 From: skewalia <145241312+swarkewalia@users.noreply.github.com> Date: Wed, 11 Mar 2026 17:47:45 -0400 Subject: [PATCH 2/3] updated exception --- apps/backend/src/foodManufacturers/manufacturers.service.ts | 6 +++--- apps/backend/src/pantries/pantries.service.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/backend/src/foodManufacturers/manufacturers.service.ts b/apps/backend/src/foodManufacturers/manufacturers.service.ts index 25584fca..b65e73ac 100644 --- a/apps/backend/src/foodManufacturers/manufacturers.service.ts +++ b/apps/backend/src/foodManufacturers/manufacturers.service.ts @@ -1,7 +1,7 @@ import { Injectable, NotFoundException, - BadRequestException, + ConflictException, } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { FoodManufacturer } from './manufacturers.entity'; @@ -132,7 +132,7 @@ export class FoodManufacturersService { } if (foodManufacturer.status !== ApplicationStatus.PENDING) { - throw new BadRequestException( + throw new ConflictException( `Cannot approve a Food Manufacturer with status: ${foodManufacturer.status}`, ); } @@ -164,7 +164,7 @@ export class FoodManufacturersService { } if (foodManufacturer.status !== ApplicationStatus.PENDING) { - throw new BadRequestException( + throw new ConflictException( `Cannot deny a Food Manufacturer with status: ${foodManufacturer.status}`, ); } diff --git a/apps/backend/src/pantries/pantries.service.ts b/apps/backend/src/pantries/pantries.service.ts index 06ecdc26..24eec40b 100644 --- a/apps/backend/src/pantries/pantries.service.ts +++ b/apps/backend/src/pantries/pantries.service.ts @@ -3,7 +3,7 @@ import { Inject, Injectable, NotFoundException, - BadRequestException, + ConflictException, } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { In, Repository } from 'typeorm'; @@ -119,7 +119,7 @@ export class PantriesService { } if (pantry.status !== ApplicationStatus.PENDING) { - throw new BadRequestException( + throw new ConflictException( `Cannot approve a pantry with status: ${pantry.status}`, ); } @@ -146,7 +146,7 @@ export class PantriesService { } if (pantry.status !== ApplicationStatus.PENDING) { - throw new BadRequestException( + throw new ConflictException( `Cannot deny a pantry with status: ${pantry.status}`, ); } From 2d54612fa061c6235c5d5865dbe5242906ef08b2 Mon Sep 17 00:00:00 2001 From: skewalia <145241312+swarkewalia@users.noreply.github.com> Date: Sat, 14 Mar 2026 13:47:12 -0400 Subject: [PATCH 3/3] fixed findone bug --- .../src/foodManufacturers/manufacturers.service.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/apps/backend/src/foodManufacturers/manufacturers.service.ts b/apps/backend/src/foodManufacturers/manufacturers.service.ts index b65e73ac..63c43349 100644 --- a/apps/backend/src/foodManufacturers/manufacturers.service.ts +++ b/apps/backend/src/foodManufacturers/manufacturers.service.ts @@ -124,9 +124,7 @@ export class FoodManufacturersService { async approve(id: number) { validateId(id, 'Food Manufacturer'); - const foodManufacturer = await this.repo.findOne({ - where: { foodManufacturerId: id }, - }); + const foodManufacturer = await this.findOne(id); if (!foodManufacturer) { throw new NotFoundException(`Food Manufacturer ${id} not found`); } @@ -156,9 +154,7 @@ export class FoodManufacturersService { async deny(id: number) { validateId(id, 'Food Manufacturer'); - const foodManufacturer = await this.repo.findOne({ - where: { foodManufacturerId: id }, - }); + const foodManufacturer = await this.findOne(id); if (!foodManufacturer) { throw new NotFoundException(`Food Manufacturer ${id} not found`); }