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
2 changes: 2 additions & 0 deletions apps/backend/src/config/typeorm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { RemoveOrdersDonationId1761500262238 } from '../migrations/1761500262238
import { AddVolunteerPantryUniqueConstraint1760033134668 } from '../migrations/1760033134668-AddVolunteerPantryUniqueConstraint';
import { AllergyFriendlyToBoolType1763963056712 } from '../migrations/1763963056712-AllergyFriendlyToBoolType';
import { UpdatePantryUserFieldsFixed1764350314832 } from '../migrations/1764350314832-UpdatePantryUserFieldsFixed';
import { UpdatePantryFields1763762628431 } from '../migrations/1763762628431-UpdatePantryFields';

const config = {
type: 'postgres',
Expand Down Expand Up @@ -56,6 +57,7 @@ const config = {
UpdateColsToUseEnumType1760886499863,
UpdatePantriesTable1742739750279,
RemoveOrdersDonationId1761500262238,
UpdatePantryFields1763762628431,
AddVolunteerPantryUniqueConstraint1760033134668,
AllergyFriendlyToBoolType1763963056712,
UpdatePantryUserFieldsFixed1764350314832,
Expand Down
81 changes: 81 additions & 0 deletions apps/backend/src/migrations/1763762628431-UpdatePantryFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class UpdatePantryFields1763762628431 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE pantries
ADD COLUMN accept_food_deliveries boolean NOT NULL DEFAULT false,
ADD COLUMN delivery_window_instructions text,
ADD COLUMN mailing_address_line_1 varchar(255) NOT NULL DEFAULT 'A',
ADD COLUMN mailing_address_line_2 varchar(255),
ADD COLUMN mailing_address_city varchar(255) NOT NULL DEFAULT 'A',
ADD COLUMN mailing_address_state varchar(255) NOT NULL DEFAULT 'A',
ADD COLUMN mailing_address_zip varchar(255) NOT NULL DEFAULT 'A',
ADD COLUMN mailing_address_country varchar(255),
ALTER COLUMN newsletter_subscription DROP NOT NULL,
ADD COLUMN has_email_contact BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN email_contact_other TEXT,
ADD COLUMN secondary_contact_first_name VARCHAR(255),
ADD COLUMN secondary_contact_last_name VARCHAR(255),
ADD COLUMN secondary_contact_email VARCHAR(255),
ADD COLUMN secondary_contact_phone VARCHAR(20);

ALTER TABLE pantries
RENAME COLUMN address_line_1 TO shipment_address_line_1;

ALTER TABLE pantries
RENAME COLUMN address_line_2 TO shipment_address_line_2;

ALTER TABLE pantries
RENAME COLUMN address_city TO shipment_address_city;

ALTER TABLE pantries
RENAME COLUMN address_state TO shipment_address_state;

ALTER TABLE pantries
RENAME COLUMN address_zip TO shipment_address_zip;

ALTER TABLE pantries
RENAME COLUMN address_country TO shipment_address_country;
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "pantries"
DROP COLUMN IF EXISTS delivery_window_instructions,
DROP COLUMN IF EXISTS accept_food_deliveries,
DROP COLUMN IF EXISTS mailing_address_line_1,
DROP COLUMN IF EXISTS mailing_address_line_2,
DROP COLUMN IF EXISTS mailing_address_city,
DROP COLUMN IF EXISTS mailing_address_state,
DROP COLUMN IF EXISTS mailing_address_zip,
DROP COLUMN IF EXISTS mailing_address_country,
ALTER COLUMN newsletter_subscription SET NOT NULL,
DROP COLUMN IF EXISTS has_email_contact,
DROP COLUMN IF EXISTS email_contact_other,
DROP COLUMN IF EXISTS secondary_contact_first_name,
DROP COLUMN IF EXISTS secondary_contact_last_name,
DROP COLUMN IF EXISTS secondary_contact_email,
DROP COLUMN IF EXISTS secondary_contact_phone;

ALTER TABLE pantries
RENAME COLUMN shipment_address_line_1 TO address_line_1;

ALTER TABLE pantries
RENAME COLUMN shipment_address_line_2 TO address_line_2;

ALTER TABLE pantries
RENAME COLUMN shipment_address_city TO address_city;

ALTER TABLE pantries
RENAME COLUMN shipment_address_state TO address_state;

ALTER TABLE pantries
RENAME COLUMN shipment_address_zip TO address_zip;

ALTER TABLE pantries
RENAME COLUMN shipment_address_country TO address_country;
`);
}
}
1 change: 1 addition & 0 deletions apps/backend/src/orders/order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { Pantry } from '../pantries/pantries.entity';
import { FoodManufacturer } from '../foodManufacturers/manufacturer.entity';
import { FoodRequest } from '../foodRequests/request.entity';
import { Donation } from '../donations/donations.entity';

Check warning on line 16 in apps/backend/src/orders/order.controller.ts

View workflow job for this annotation

GitHub Actions / pre-deploy

'Donation' is defined but never used
import { AllocationsService } from '../allocations/allocations.service';
import { OrderStatus } from './types';

Expand Down
20 changes: 7 additions & 13 deletions apps/backend/src/orders/order.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ import { OrderStatus } from './types';

const mockOrdersRepository = mock<Repository<Order>>();

const mockPantry: Pantry = {
const mockPantry: Partial<Pantry> = {
pantryId: 1,
pantryName: 'Test Pantry',
addressLine1: '123 Test St',
addressLine2: 'Apt. 1',
addressCity: 'Boston',
addressState: 'MA',
addressZip: '02115',
addressCountry: 'US',
allergenClients: '',
refrigeratedDonation: RefrigeratedDonation.NO,
reserveFoodForAllergic: 'Yes',
Expand Down Expand Up @@ -114,17 +108,17 @@ describe('OrdersService', () => {
{
orderId: 3,
status: OrderStatus.DELIVERED,
pantry: { ...mockPantry, pantryName: 'Test Pantry' },
pantry: { ...(mockPantry as Pantry), pantryName: 'Test Pantry' },
},
{
orderId: 4,
status: OrderStatus.DELIVERED,
pantry: { ...mockPantry, pantryName: 'Test Pantry 2' },
pantry: { ...(mockPantry as Pantry), pantryName: 'Test Pantry 2' },
},
{
orderId: 5,
status: OrderStatus.DELIVERED,
pantry: { ...mockPantry, pantryName: 'Test Pantry 3' },
pantry: { ...(mockPantry as Pantry), pantryName: 'Test Pantry 3' },
},
];

Expand Down Expand Up @@ -162,17 +156,17 @@ describe('OrdersService', () => {
{
orderId: 3,
status: OrderStatus.DELIVERED,
pantry: { ...mockPantry, pantryName: 'Test Pantry 1' },
pantry: { ...(mockPantry as Pantry), pantryName: 'Test Pantry 1' },
},
{
orderId: 4,
status: OrderStatus.DELIVERED,
pantry: { ...mockPantry, pantryName: 'Test Pantry 2' },
pantry: { ...(mockPantry as Pantry), pantryName: 'Test Pantry 2' },
},
{
orderId: 5,
status: OrderStatus.DELIVERED,
pantry: { ...mockPantry, pantryName: 'Test Pantry 2' },
pantry: { ...(mockPantry as Pantry), pantryName: 'Test Pantry 2' },
},
];

Expand Down
114 changes: 105 additions & 9 deletions apps/backend/src/pantries/dtos/pantry-application.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
IsBoolean,
IsEmail,
IsEnum,
IsIn,
IsNotEmpty,
IsOptional,
IsPhoneNumber,
Expand All @@ -23,71 +22,164 @@ import {
export class PantryApplicationDto {
@IsString()
@IsNotEmpty()
@Length(1, 255)
contactFirstName: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
contactLastName: string;

@IsEmail()
@Length(1, 255)
contactEmail: string;

// This validation is very strict and won't accept phone numbers
// that look right but aren't actually possible phone numbers
@IsString()
@IsNotEmpty()
@IsPhoneNumber('US', {
message:
'contactPhone must be a valid phone number (make sure all the digits are correct)',
})
contactPhone: string;

@IsBoolean()
hasEmailContact: boolean;

@IsOptional()
@IsString()
@IsNotEmpty()
@MaxLength(255)
emailContactOther?: string;

@IsOptional()
@IsString()
@IsNotEmpty()
@MaxLength(255)
secondaryContactFirstName?: string;

@IsOptional()
@IsString()
@IsNotEmpty()
@MaxLength(255)
secondaryContactLastName?: string;

@IsOptional()
@IsEmail()
@IsNotEmpty()
@MaxLength(255)
secondaryContactEmail?: string;

@IsOptional()
@IsString()
@IsPhoneNumber('US', {
message:
'secondaryContactPhone must be a valid phone number (make sure all the digits are correct)',
})
@IsNotEmpty()
secondaryContactPhone?: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
pantryName: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
addressLine1: string;
shipmentAddressLine1: string;

@IsOptional()
@IsString()
@MaxLength(255)
addressLine2?: string;
@IsNotEmpty()
shipmentAddressLine2?: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
addressCity: string;
shipmentAddressCity: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
addressState: string;
shipmentAddressState: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
addressZip: string;
shipmentAddressZip: string;

@IsOptional()
@IsString()
@MaxLength(255)
addressCountry?: string;
@IsNotEmpty()
shipmentAddressCountry?: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
mailingAddressLine1: string;

@IsOptional()
@IsString()
@MaxLength(255)
@IsNotEmpty()
mailingAddressLine2?: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
mailingAddressCity: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
mailingAddressState: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
mailingAddressZip: string;

@IsOptional()
@IsString()
@MaxLength(255)
@IsNotEmpty()
mailingAddressCountry?: string;

@IsString()
@IsNotEmpty()
@Length(1, 25)
allergenClients: string;

@IsOptional()
@IsString({ each: true })
@IsNotEmpty({ each: true })
@MaxLength(255, { each: true })
restrictions?: string[];

@IsEnum(RefrigeratedDonation)
refrigeratedDonation: RefrigeratedDonation;

@IsBoolean()
acceptFoodDeliveries: boolean;

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

@IsEnum(ReserveFoodForAllergic)
reserveFoodForAllergic: ReserveFoodForAllergic;

// TODO: Really, this validation should be different depending on the value of reserveFoodForAllergic
@IsOptional()
@IsString()
@IsNotEmpty()
@MaxLength(255)
reservationExplanation?: string;

@IsBoolean()
Expand All @@ -111,17 +203,21 @@ export class PantryApplicationDto {

@IsOptional()
@IsString()
@IsNotEmpty()
@MaxLength(255)
activitiesComments?: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
itemsInStock: string;

@IsString()
@IsNotEmpty()
@Length(1, 255)
needMoreOptions: string;

@IsOptional()
@IsIn(['Yes', 'No'])
newsletterSubscription?: string;
@IsBoolean()
newsletterSubscription?: boolean;
}
Loading
Loading