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 @@ -17,6 +17,7 @@ import { UpdateRequestTable1741571847063 } from '../migrations/1741571847063-upd
import { RemoveOrderIdFromRequests1744133526650 } from '../migrations/1744133526650-removeOrderIdFromRequests';
import { AddOrders1739496585940 } from '../migrations/1739496585940-addOrders';
import { UpdatePantriesTable1742739750279 } from '../migrations/1742739750279-updatePantriesTable';
import { UpdatePantryUserFields1731171000000 } from '../migrations/1731171000000-UpdatePantryUserFields';
import { RemoveOrdersDonationId1761500262238 } from '../migrations/1761500262238-RemoveOrdersDonationId';

const config = {
Expand Down Expand Up @@ -48,6 +49,7 @@ const config = {
UpdateFoodRequests1744051370129,
RemoveOrderIdFromRequests1744133526650,
UpdatePantriesTable1742739750279,
UpdatePantryUserFields1731171000000,
RemoveOrdersDonationId1761500262238,
],
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class UpdatePantryUserFields1731171000000 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE pantries DROP COLUMN IF EXISTS ssf_representative_id;
ALTER TABLE pantries RENAME COLUMN pantry_representative_id TO pantry_user_id;`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE pantries RENAME COLUMN pantry_user_id TO pantry_representative_id;
ALTER TABLE pantries ADD COLUMN ssf_representative_id INT;
ALTER TABLE pantries ADD CONSTRAINT fk_ssf_representative_id
FOREIGN KEY (ssf_representative_id) REFERENCES users(user_id);`,
);
}
}
2 changes: 1 addition & 1 deletion apps/backend/src/orders/order.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const mockPantry: Pantry = {
serveAllergicChildren: '',
newsletterSubscription: false,
restrictions: [],
pantryRepresentative: null as unknown as User,
pantryUser: null as unknown as User,
status: 'active',
dateApplied: new Date(),
activities: [],
Expand Down
8 changes: 0 additions & 8 deletions apps/backend/src/pantries/pantries.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@nestjs/common';
import { Pantry } from './pantries.entity';
import { PantriesService } from './pantries.service';
import { User } from '../users/user.entity';
import { PantryApplicationDto } from './dtos/pantry-application.dto';
import { ApiBody } from '@nestjs/swagger';

Expand All @@ -21,13 +20,6 @@ export class PantriesController {
return this.pantriesService.getPendingPantries();
}

@Get('/:pantryId/ssf-contact')
async getSSFRep(
@Param('pantryId', ParseIntPipe) pantryId: number,
): Promise<User> {
return this.pantriesService.findSSFRep(pantryId);
}

@Get('/:pantryId')
async getPantry(
@Param('pantryId', ParseIntPipe) pantryId: number,
Expand Down
16 changes: 4 additions & 12 deletions apps/backend/src/pantries/pantries.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
PrimaryGeneratedColumn,
OneToOne,
JoinColumn,
ManyToOne,
} from 'typeorm';
import { User } from '../users/user.entity';

Expand Down Expand Up @@ -89,22 +88,15 @@ export class Pantry {
@Column({ name: 'restrictions', type: 'text', array: true })
restrictions: string[];

@ManyToOne(() => User, { nullable: true })
@JoinColumn({
name: 'ssf_representative_id',
referencedColumnName: 'id',
})
ssfRepresentative?: User;

// cascade: ['insert'] means that when we create a new
// pantry, the representative will automatically be added
// pantry, the pantry user will automatically be added
// to the User table
@OneToOne(() => User, { nullable: false, cascade: ['insert'] })
@OneToOne(() => User, { nullable: false, cascade: ['insert'], onDelete: 'CASCADE' })
@JoinColumn({
name: 'pantry_representative_id',
name: 'pantry_user_id',
referencedColumnName: 'id',
})
pantryRepresentative: User;
pantryUser: User;

@Column({ name: 'status', type: 'varchar', length: 50, default: 'pending' })
status: string;
Expand Down
22 changes: 5 additions & 17 deletions apps/backend/src/pantries/pantries.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export class PantriesService {
}

async getPendingPantries(): Promise<Pantry[]> {
return await this.repo.find({ where: { status: 'pending' } });
return await this.repo.find({
where: { status: 'pending' },
relations: ['pantryUser'],
});
}

async addPantry(pantryData: PantryApplicationDto) {
Expand All @@ -36,7 +39,7 @@ export class PantriesService {
pantryContact.email = pantryData.contactEmail;
pantryContact.phone = pantryData.contactPhone;

pantry.pantryRepresentative = pantryContact;
pantry.pantryUser = pantryContact;

pantry.pantryName = pantryData.pantryName;
pantry.addressLine1 = pantryData.addressLine1;
Expand Down Expand Up @@ -86,19 +89,4 @@ export class PantriesService {

await this.repo.update(id, { status: 'denied' });
}

async findSSFRep(pantryId: number): Promise<User> {
validateId(pantryId, 'Pantry');

const pantry = await this.repo.findOne({
where: { pantryId },
relations: ['ssfRepresentative'],
});

if (!pantry) {
throw new NotFoundException(`Pantry ${pantryId} not found`);
}

return pantry.ssfRepresentative;
}
}
33 changes: 7 additions & 26 deletions apps/frontend/src/components/forms/pantryApplicationModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';

Check warning on line 1 in apps/frontend/src/components/forms/pantryApplicationModal.tsx

View workflow job for this annotation

GitHub Actions / pre-deploy

'useState' is defined but never used

Check warning on line 1 in apps/frontend/src/components/forms/pantryApplicationModal.tsx

View workflow job for this annotation

GitHub Actions / pre-deploy

'useEffect' is defined but never used
import { Button, Dialog, Grid, GridItem, Text } from '@chakra-ui/react';
import ApiClient from '@api/apiClient';

Check warning on line 3 in apps/frontend/src/components/forms/pantryApplicationModal.tsx

View workflow job for this annotation

GitHub Actions / pre-deploy

'ApiClient' is defined but never used
import { Pantry, User } from 'types/types';

Check warning on line 4 in apps/frontend/src/components/forms/pantryApplicationModal.tsx

View workflow job for this annotation

GitHub Actions / pre-deploy

'User' is defined but never used
Expand All @@ -14,26 +14,7 @@
isOpen,
onClose,
}) => {
const [user, setUser] = useState<User | null>(null);

// TODO: Make sure clients of this modal actually include
// the pantry representative ID (or the representative User
// itself) in the provided data
/*useEffect(() => {
const fetchUser = async () => {
if (pantry.pantryRepresentativeId) {
const data = await ApiClient.getRepresentativeUser(
pantry.pantryRepresentativeId,
);
setUser(data);
}
};

if (isOpen) {
fetchUser();
}
}, [isOpen, pantry.pantryRepresentativeId]);*/

const pantryUser = pantry.pantryUser;
return (
<Dialog.Root
open={isOpen}
Expand All @@ -48,30 +29,30 @@
<Dialog.Content>
<Dialog.Header>Pantry Application Details</Dialog.Header>
<Dialog.Body>
{user ? (
{pantryUser ? (
<Grid templateColumns="2fr 1fr" gap={4}>
<GridItem>
<Text fontWeight="bold">Representative Name</Text>
<Text fontWeight="bold">Pantry User Name</Text>
</GridItem>

<GridItem>
{user.firstName} {user.lastName}
{pantryUser.firstName} {pantryUser.lastName}
</GridItem>

<GridItem>
<Text fontWeight="bold">Email</Text>
</GridItem>
<GridItem>{user.email}</GridItem>
<GridItem>{pantryUser.email}</GridItem>

<GridItem>
<Text fontWeight="bold">Phone</Text>
</GridItem>
<GridItem>{user.phone}</GridItem>
<GridItem>{pantryUser.phone}</GridItem>

<GridItem>
<Text fontWeight="bold">Role</Text>
</GridItem>
<GridItem>{user.role}</GridItem>
<GridItem>{pantryUser.role}</GridItem>
</Grid>
) : (
<Text>No user details available.</Text>
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface Pantry {
serveAllergicChildren?: string;
newsletterSubscription: boolean;
restrictions: string[];
pantryUser?: User;
status: string;
dateApplied: string;
activities: string[];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@
"vite": "^4.3.9",
"vitest": "^0.32.0"
}
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14370,4 +14370,4 @@ yocto-queue@^0.1.0:
yocto-queue@^1.0.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.2.1.tgz#36d7c4739f775b3cbc28e6136e21aa057adec418"
integrity sha512-AyeEbWOu/TAXdxlV9wmGcR0+yh2j3vYPGOECcIj2S7MkrLyC7ne+oye2BKTItt0ii2PHk4cDy+95+LshzbXnGg==
integrity sha512-AyeEbWOu/TAXdxlV9wmGcR0+yh2j3vYPGOECcIj2S7MkrLyC7ne+oye2BKTItt0ii2PHk4cDy+95+LshzbXnGg==
Loading