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
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';

const schemaMigrations = [
User1725726359198,
Expand Down Expand Up @@ -70,6 +71,7 @@ const schemaMigrations = [
DonationItemFoodTypeNotNull1771524930613,
MoveRequestFieldsToOrders1770571145350,
RenameDonationMatchingStatus1771260403657,
AddAssigneeToOrders1773009000618,
];

export default schemaMigrations;
20 changes: 20 additions & 0 deletions apps/backend/src/migrations/1773009000618-AddAssigneeToOrders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddAssigneeToOrders1773009000618 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
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

ADD COLUMN assignee_id INT,

Choose a reason for hiding this comment

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

I think that asignees should not be able to be nullable

Copy link
Author

Choose a reason for hiding this comment

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

since there isn't an order creation workflow yet, i think it might be best to keep it nullable for now and change it later once that's implemented. the existing orders currently have null assignees so it might break things

Choose a reason for hiding this comment

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

@Yurika-Kan what do you think? I don't think it will break anything since the null assignees are new here but will defer to your judgement

ADD CONSTRAINT fk_assignee_id
FOREIGN KEY (assignee_id) REFERENCES users(user_id) ON DELETE SET NULL
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE orders
DROP CONSTRAINT IF EXISTS fk_assignee_id,
DROP COLUMN assignee_id
`);
}
}
5 changes: 5 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/user.entity';

@Entity('orders')
export class Order {
Expand Down Expand Up @@ -95,4 +96,8 @@ export class Order {
nullable: true,
})
shippingCost!: number | null;

Choose a reason for hiding this comment

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

I see the relation but we should add an explicity assignee_id column definition to this entity since we add a table column

@ManyToOne(() => User, { nullable: true })

Choose a reason for hiding this comment

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

should not be nullable

@JoinColumn({ name: 'assignee_id', referencedColumnName: 'id' })
assignee!: User | null;

Choose a reason for hiding this comment

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

remove | null

}
10 changes: 7 additions & 3 deletions apps/backend/src/orders/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export class OrdersService {
async getAll(filters?: { status?: string; pantryNames?: string[] }) {
const qb = this.repo
.createQueryBuilder('order')
.leftJoinAndSelect('order.request', 'request')
.leftJoinAndSelect('request.pantry', 'pantry')
.leftJoinAndSelect('pantry.volunteers', 'volunteers')
.leftJoin('order.request', 'request')
.leftJoin('request.pantry', 'pantry')
.leftJoin('pantry.volunteers', 'volunteers')
.leftJoin('order.assignee', 'assignee')
.select([
'order.orderId',
'order.status',
Expand All @@ -43,6 +44,9 @@ export class OrdersService {
'volunteers.id',
'volunteers.firstName',
'volunteers.lastName',
'assignee.id',
'assignee.firstName',
'assignee.lastName',
]);

if (filters?.status) {
Expand Down
9 changes: 4 additions & 5 deletions apps/frontend/src/containers/adminOrderManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ const OrderStatusSection: React.FC<OrderStatusSectionProps> = ({
alignItems="center"
justifyContent="center"
>
{volunteers && volunteers.length > 0 ? (
{order.assignee ? (
<Box
key={index}
borderRadius="full"
Expand All @@ -677,9 +677,8 @@ const OrderStatusSection: React.FC<OrderStatusSectionProps> = ({
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()}
{order.assignee?.firstName.charAt(0).toUpperCase()}
{order.assignee?.lastName.charAt(0).toUpperCase()}
</Box>
) : (
<Box>No Assignees</Box>

Choose a reason for hiding this comment

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

can remove the no assignee case

Expand All @@ -706,7 +705,7 @@ const OrderStatusSection: React.FC<OrderStatusSectionProps> = ({
<Table.Cell
{...tableCellStyles}
textAlign="left"
color="neutral.700"
bg="#FAFAFA"
>
{/* TODO: IMPLEMENT WHAT GOES HERE */}
</Table.Cell>
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 @@ -361,6 +361,11 @@ export interface OrderSummary {
}[];
};
};
assignee: {
id: number;
firstName: string;
lastName: string;
} | null;

Choose a reason for hiding this comment

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

remove | null

}

export enum ApplicationStatus {
Expand Down