Skip to content

Commit 2462b6d

Browse files
committed
Update ImageDto exchange format
1 parent 3f20288 commit 2462b6d

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

apps/api/src/helpers/dtoHelpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class DtoHelpers {
55
public static getImageDto(key?: string): ImageDto {
66
const hasImage = key != undefined;
77
const url = Utils.getApiBaseUrl() + `images/${key || 'default'}`;
8-
return { hasImage, url };
8+
return { hasImage: true, url };
99
}
1010
}
1111

apps/client/src/components/Dropzone.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Dropzone({ onChange, render }: DropzoneProps) {
2222

2323
const url = await PromiseFileReader.readAsDataURL(file);
2424

25-
onChange({ hasImage: true, url });
25+
onChange({ hasImage: true, url, data: url });
2626
};
2727

2828
const { getRootProps, getInputProps, isDragActive } = useDropzone({

apps/client/src/components/Product/ProductUpdateForm.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface ProductCreateFormProps {
2323
type Inputs = {
2424
name: string;
2525
description?: string;
26-
image?: ImageDto;
26+
image: ImageDto;
2727
buyPrice?: number;
2828
sellPrice?: number;
2929
unit?: string;
@@ -48,10 +48,16 @@ function ProductUpdateForm({ product }: ProductCreateFormProps) {
4848
function onSubmit(inputs: Inputs) {
4949
setLoading(true);
5050

51+
const { image, ...rest } = inputs;
52+
5153
const dto: UpdateProductDto = {
5254
organizationId: appContext.organization.id,
5355
...product,
54-
...inputs,
56+
image: {
57+
hasImage: image.hasImage,
58+
data: image.data,
59+
},
60+
...rest,
5561
};
5662

5763
Utils.postFetcher<ProductDto>(`/api/products/${product.id}`, dto, { method: 'PUT' })

packages/shared-types/src/ImageDto.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import { IsBase64, IsBoolean, IsEmpty } from "class-validator";
1+
import { IsBoolean, IsDataURI, IsEmpty, IsOptional } from "class-validator";
22

33
export class ImageDto {
44
@IsBoolean()
55
hasImage: boolean;
66

7-
@IsBase64()
7+
@IsEmpty()
8+
@IsOptional()
89
url?: string;
10+
11+
@IsOptional()
12+
@IsDataURI()
13+
data?: string;
914
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import { ValidateNested } from "class-validator";
12
import { ImageDto } from "../ImageDto";
23
import { CreateProductDto } from "./CreateProductDto";
4+
import { Type } from "class-transformer";
35

46
export class UpdateProductDto extends CreateProductDto {
7+
@ValidateNested()
8+
@Type(() => ImageDto)
59
image: ImageDto;
610
}

0 commit comments

Comments
 (0)