Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export class UpdateFoodManufacturerApplicationDto {
secondaryContactLastName?: string;

@IsOptional()
@IsEmail()
@IsEmail(
{},
{ message: 'Secondary contact email must be a valid email address.' },
)
@IsNotEmpty()
@MaxLength(255)
secondaryContactEmail?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,23 @@ describe('FoodManufacturersController', () => {
expect(mockManufacturersService.deny).toHaveBeenCalledWith(1);
});
});

describe('getCurrentUserFoodManufacturerId', () => {
it('returns foodManufacturerId for authenticated user', async () => {
const req = { user: { id: 1 } };
const manufacturer: Partial<FoodManufacturer> = {
foodManufacturerId: 10,
};
mockManufacturersService.findByUserId.mockResolvedValueOnce(
manufacturer as FoodManufacturer,
);

const result = await controller.getCurrentUserFoodManufacturerId(
req as AuthenticatedRequest,
);

expect(result).toEqual(10);
expect(mockManufacturersService.findByUserId).toHaveBeenCalledWith(1);
});
});
});
11 changes: 11 additions & 0 deletions apps/backend/src/foodManufacturers/manufacturers.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ export class FoodManufacturersController {
return this.foodManufacturersService.getPendingManufacturers();
}

@Roles(Role.FOODMANUFACTURER)
@Get('/my-id')
async getCurrentUserFoodManufacturerId(
@Req() req: AuthenticatedRequest,
): Promise<number> {
const manufacturer = await this.foodManufacturersService.findByUserId(
req.user.id,
);
return manufacturer.foodManufacturerId;
}

@Get('/:foodManufacturerId')
async getFoodManufacturer(
@Param('foodManufacturerId', ParseIntPipe) foodManufacturerId: number,
Expand Down
15 changes: 15 additions & 0 deletions apps/backend/src/foodManufacturers/manufacturers.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,21 @@ describe('FoodManufacturersService', () => {
});
});

describe('findByUserId', () => {
it('findByUserId success', async () => {
const manufacturer = await service.findOne(1);
const userId = manufacturer.foodManufacturerRepresentative.id;
const result = await service.findByUserId(userId);
expect(result.foodManufacturerId).toBe(1);
});

it('findByUserId with non-existent user throws NotFoundException', async () => {
await expect(service.findByUserId(9999)).rejects.toThrow(
new NotFoundException('Food Manufacturer for User 9999 not found'),
);
});
});

describe('getStats', () => {
it('returns proper stats for manufacturer', async () => {
const manufacturerId = 1;
Expand Down
15 changes: 15 additions & 0 deletions apps/backend/src/foodManufacturers/manufacturers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ export class FoodManufacturersService {
return foodManufacturer;
}

async findByUserId(userId: number): Promise<FoodManufacturer> {
validateId(userId, 'User');

const manufacturer = await this.repo.findOne({
where: { foodManufacturerRepresentative: { id: userId } },
});

if (!manufacturer) {
throw new NotFoundException(
`Food Manufacturer for User ${userId} not found`,
);
}
return manufacturer;
}

async getFMDonations(
foodManufacturerId: number,
currentUserId: number,
Expand Down
20 changes: 18 additions & 2 deletions apps/backend/src/pantries/dtos/update-pantry-application.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export class UpdatePantryApplicationDto {
secondaryContactLastName?: string;

@IsOptional()
@IsEmail()
@IsEmail(
{},
{ message: 'Secondary contact email must be a valid email address.' },
)
@IsNotEmpty()
@MaxLength(255)
secondaryContactEmail?: string;
Expand All @@ -42,7 +45,7 @@ export class UpdatePantryApplicationDto {
@IsString()
@IsPhoneNumber('US', {
message:
'secondaryContactPhone must be a valid phone number (make sure all the digits are correct)',
'Secondary contact phone must be a valid phone number (make sure all the digits are correct)',
})
@IsNotEmpty()
secondaryContactPhone?: string;
Expand Down Expand Up @@ -132,6 +135,15 @@ export class UpdatePantryApplicationDto {
@MaxLength(255, { each: true })
restrictions?: string[];

@IsBoolean()
@IsOptional()
acceptFoodDeliveries?: boolean;

@IsOptional()
@IsString()
@IsNotEmpty()
deliveryWindowInstructions?: string;

@IsEnum(RefrigeratedDonation)
@IsOptional()
refrigeratedDonation?: RefrigeratedDonation;
Expand All @@ -140,6 +152,10 @@ export class UpdatePantryApplicationDto {
@IsOptional()
reserveFoodForAllergic?: ReserveFoodForAllergic;

@IsOptional()
@IsString()
reservationExplanation?: string | null;
Comment thread
amywng marked this conversation as resolved.

@IsBoolean()
@IsOptional()
dedicatedAllergyFriendly?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/pantries/pantries.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export class PantriesController {
}

@Roles(Role.PANTRY)
@Patch('/:pantryId/update')
@Patch('/:pantryId/application')
async updatePantryApplication(
@Req() req: AuthenticatedRequest,
@Param('pantryId', ParseIntPipe) pantryId: number,
Expand Down
26 changes: 26 additions & 0 deletions apps/frontend/src/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
TotalStats,
CreateDonationDto,
UpdateProfileFields,
UpdatePantryApplicationDto,
UpdateFoodManufacturerApplicationDto,
MatchingManufacturersDto,
MatchingItemsDto,
CreateOrderDto,
Expand Down Expand Up @@ -379,6 +381,15 @@ export class ApiClient {
});
}

public async updatePantryApplicationData(
pantryId: number,
data: UpdatePantryApplicationDto,
): Promise<Pantry> {
return this.axiosInstance
.patch(`/api/pantries/${pantryId}/application`, data)
.then((response) => response.data);
}

public async createOrder(
dto: CreateOrderDto,
): Promise<OrderWithoutRelations> {
Expand Down Expand Up @@ -436,6 +447,21 @@ export class ApiClient {
.then((response) => response.data);
}

public async getCurrentUserFoodManufacturerId(): Promise<number> {
return this.axiosInstance
.get('/api/manufacturers/my-id')
.then((response) => response.data);
}

public async updateFoodManufacturerApplicationData(
Comment thread
dburkhart07 marked this conversation as resolved.
manufacturerId: number,
data: UpdateFoodManufacturerApplicationDto,
): Promise<FoodManufacturer> {
return this.axiosInstance
.patch(`/api/manufacturers/${manufacturerId}/application`, data)
.then((response) => response.data);
}

public async getMe(): Promise<User> {
return this.axiosInstance
.get('/api/users/me')
Expand Down
Loading
Loading