Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 18 additions & 1 deletion apps/backend/src/foodManufacturers/manufacturers.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -28,6 +32,7 @@ export class FoodManufacturersService {

const foodManufacturer = await this.repo.findOne({
where: { foodManufacturerId },
relations: ['foodManufacturerRepresentative'],
});

if (!foodManufacturer) {
Expand Down Expand Up @@ -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,
Expand All @@ -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 });
}
}
13 changes: 13 additions & 0 deletions apps/backend/src/pantries/pantries.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Inject,
Injectable,
NotFoundException,
BadRequestException,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { In, Repository } from 'typeorm';
Expand Down Expand Up @@ -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,
Expand All @@ -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 });
}

Expand Down