Skip to content
2 changes: 2 additions & 0 deletions apps/backend/src/config/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { UpdateOrderEntity1769990652833 } from '../migrations/1769990652833-Upda
import { DonationItemFoodTypeNotNull1771524930613 } from '../migrations/1771524930613-DonationItemFoodTypeNotNull';
import { MoveRequestFieldsToOrders1770571145350 } from '../migrations/1770571145350-MoveRequestFieldsToOrders';
import { RenameDonationMatchingStatus1771260403657 } from '../migrations/1771260403657-RenameDonationMatchingStatus';
import { AddAssigneeToOrders1773009000618 } from '../migrations/1773009000618-AddAssigneeToOrders';
import { DropDonationTotalColumns1772241115031 } from '../migrations/1772241115031-DropDonationTotalColumns';
import { FixTrackingLinks1773041840374 } from '../migrations/1773041840374-FixTrackingLinks';
import { CleanupRequestsAndAllocations1771821377918 } from '../migrations/1771821377918-CleanupRequestsAndAllocations';
Expand Down Expand Up @@ -73,6 +74,7 @@ const schemaMigrations = [
DonationItemFoodTypeNotNull1771524930613,
MoveRequestFieldsToOrders1770571145350,
RenameDonationMatchingStatus1771260403657,
AddAssigneeToOrders1773009000618,
DropDonationTotalColumns1772241115031,
FixTrackingLinks1773041840374,
CleanupRequestsAndAllocations1771821377918,
Expand Down
30 changes: 30 additions & 0 deletions apps/backend/src/migrations/1773009000618-AddAssigneeToOrders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddAssigneeToOrders1773009000618 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE orders ADD COLUMN assignee_id INT`);

await queryRunner.query(`
UPDATE orders o SET assignee_id = (
SELECT va.volunteer_id FROM volunteer_assignments va
JOIN food_requests fr ON fr.pantry_id = va.pantry_id
WHERE fr.request_id = o.request_id
LIMIT 1
)
`);

await queryRunner.query(`
ALTER TABLE orders

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here we can edit the dummy data to add ids for the asignee for each order

ALTER COLUMN assignee_id SET NOT NULL,
ADD CONSTRAINT fk_assignee_id FOREIGN KEY (assignee_id) REFERENCES users(user_id) ON DELETE RESTRICT
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE orders
DROP CONSTRAINT IF EXISTS fk_assignee_id,
DROP COLUMN assignee_id
`);
}
}
8 changes: 8 additions & 0 deletions apps/backend/src/orders/order.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { FoodRequest } from '../foodRequests/request.entity';
import { FoodManufacturer } from '../foodManufacturers/manufacturers.entity';
import { OrderStatus } from './types';
import { Allocation } from '../allocations/allocations.entity';
import { User } from '../users/users.entity';

@Entity('orders')
export class Order {
Expand Down Expand Up @@ -99,4 +100,11 @@ export class Order {
},
})
shippingCost!: number | null;

@ManyToOne(() => User, { nullable: false, onDelete: 'RESTRICT' })
@JoinColumn({ name: 'assignee_id' })
assignee!: User;

@Column({ name: 'assignee_id' })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add type: 'int'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ bumping

assigneeId!: number;
}
8 changes: 4 additions & 4 deletions apps/backend/src/orders/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class OrdersService {
.createQueryBuilder('order')
.leftJoinAndSelect('order.request', 'request')
.leftJoinAndSelect('request.pantry', 'pantry')
.leftJoinAndSelect('pantry.volunteers', 'volunteers')
.leftJoinAndSelect('order.assignee', 'assignee')
.select([
'order.orderId',
'order.status',
Expand All @@ -40,9 +40,9 @@ export class OrdersService {
'order.deliveredAt',
'request.pantryId',
'pantry.pantryName',
'volunteers.id',
'volunteers.firstName',
'volunteers.lastName',
'assignee.id',
'assignee.firstName',
'assignee.lastName',
]);

if (filters?.status) {
Expand Down
50 changes: 17 additions & 33 deletions apps/frontend/src/containers/adminOrderManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ const AdminOrderManagement: React.FC = () => {
const status = order.status;

const orderWithColor: OrderWithColor = { ...order };
if (
order.request.pantry.volunteers &&
order.request.pantry.volunteers.length > 0
) {
orderWithColor.assigneeColor =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need to assign assigneeColor so UI doesn't fall back to gray! rn every user on the page is gray

ASSIGNEE_COLORS[counters[status] % ASSIGNEE_COLORS.length];
counters[status]++;
}
grouped[status].push(orderWithColor);
}

Expand Down Expand Up @@ -613,7 +605,6 @@ const OrderStatusSection: React.FC<OrderStatusSectionProps> = ({
<Table.Body>
{orders.map((order, index) => {
const pantry = order.request.pantry;
const volunteers = pantry.volunteers || [];

return (
<Table.Row
Expand Down Expand Up @@ -670,26 +661,21 @@ const OrderStatusSection: React.FC<OrderStatusSectionProps> = ({
alignItems="center"
justifyContent="center"
>
{volunteers && volunteers.length > 0 ? (
<Box
key={index}
borderRadius="full"
bg={order.assigneeColor || 'gray'}
width="33px"
height="33px"
display="flex"
alignItems="center"
justifyContent="center"
color="white"
p={2}
>
{/* TODO: Change logic later to only get one volunteer */}
{volunteers[0].firstName.charAt(0).toUpperCase()}
{volunteers[0].lastName.charAt(0).toUpperCase()}
</Box>
) : (
<Box>No Assignees</Box>
)}
<Box
key={index}
borderRadius="full"
bg={order.assigneeColor || 'gray'}
width="33px"
height="33px"
display="flex"
alignItems="center"
justifyContent="center"
color="white"
p={2}
>
{order.assignee.firstName.charAt(0).toUpperCase()}
{order.assignee.lastName.charAt(0).toUpperCase()}
</Box>
</Box>
</Table.Cell>
<Table.Cell
Expand All @@ -712,10 +698,8 @@ const OrderStatusSection: React.FC<OrderStatusSectionProps> = ({
<Table.Cell
{...tableCellStyles}
textAlign="left"
color="neutral.700"
>
{/* TODO: IMPLEMENT WHAT GOES HERE */}
</Table.Cell>
bg="#FAFAFA"
></Table.Cell>
</Table.Row>
);
})}
Expand Down
5 changes: 5 additions & 0 deletions apps/frontend/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ export interface OrderSummary {
}[];
};
};
assignee: {
id: number;
firstName: string;
lastName: string;
};
}

export enum ApplicationStatus {
Expand Down
Loading