Skip to content

Commit

Permalink
handle drop_image null
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho9900 committed Jul 16, 2024
1 parent 96ae4e1 commit 81626db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 21 additions & 11 deletions packages/drops/src/domain/Drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,7 @@ export class Drop {
emailReservationCount: number;

public static fromCompass(response: DropResponse): Drop {
const images: { crop: string; original: string } =
response.drop_image.gateways.reduce(
(images, gateway) => ({
...images,
[gateway.type.toLowerCase()]: gateway.url,
}),
{
crop: response.image_url,
original: response.image_url,
},
);
const images = Drop.getDropImageFromCompass(response);

return new Drop({
id: Number(response.id),
Expand Down Expand Up @@ -70,6 +60,26 @@ export class Drop {
});
}

private static getDropImageFromCompass(response: DropResponse): {
crop: string;
original: string;
} {
const defaultImage = {
crop: response.image_url,
original: response.image_url,
};

return (
response.drop_image?.gateways.reduce(
(images, gateway) => ({
...images,
[gateway.type.toLowerCase()]: gateway.url,
}),
defaultImage,
) || defaultImage
);
}

public static fromProvider(response: ProviderDropResponse): Drop {
return new Drop({
id: response.id,
Expand Down
2 changes: 1 addition & 1 deletion packages/drops/src/types/DropResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export interface DropResponse {
type: 'CROP' | 'ORIGINAL';
url: string;
}>;
};
} | null;
}

0 comments on commit 81626db

Please sign in to comment.