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
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 @@ -528,6 +528,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
14 changes: 14 additions & 0 deletions apps/backend/src/pantries/dtos/update-pantry-application.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,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 +149,11 @@ export class UpdatePantryApplicationDto {
@IsOptional()
reserveFoodForAllergic?: ReserveFoodForAllergic;

@IsOptional()
@IsString()
@IsNotEmpty()
reservationExplanation?: string | null;

@IsBoolean()
@IsOptional()
dedicatedAllergyFriendly?: boolean;
Expand Down
25 changes: 25 additions & 0 deletions apps/frontend/src/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
PantryWithUser,
Assignments,
UpdateProfileFields,
UpdatePantryApplicationDto,
UpdateFoodManufacturerApplicationDto,
} from 'types/types';

const defaultBaseUrl =
Expand Down Expand Up @@ -330,6 +332,15 @@ export class ApiClient {
});
}

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

public async updatePantry(
pantryId: number,
decision: 'approve' | 'deny',
Expand Down Expand Up @@ -366,6 +377,20 @@ export class ApiClient {
return data as number;
}

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

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

public async getMe(): Promise<User> {
const data = await this.get('/api/users/me');
return data as User;
Expand Down
Loading
Loading