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] 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 }); }