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
3 changes: 3 additions & 0 deletions src/common/errors/error-catalog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const RENDER_PARAMS: Partial<
CUSTOM_TEXT_DEFAULT_TOO_LONG: { label: '이름', max: 20 },
CUSTOM_3D_ITEM_LIMIT_EXCEEDED: { max: 10 },
CUSTOM_3D_DESIGN_INVALID: { field: 'top[0].size' },
CUSTOM_SLOT_TEXT_REQUIRED: { label: '이름' },
CUSTOM_SLOT_TEXT_TOO_LONG: { label: '이름', max: 20 },
CUSTOM_FREE_EDIT_INVALID: { field: 'freeEdits[0].descriptionText' },
IDS_LENGTH_MISMATCH: { field: 'imageIds' },
INVALID_IDS: { field: 'imageIds' },
PRODUCT_IMAGE_LIMIT_EXCEEDED: { max: 10 },
Expand Down
46 changes: 46 additions & 0 deletions src/common/errors/error-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,52 @@ export const ERROR_CATALOG = {
message: ({ field }) =>
`3D 디자인에 쓸 수 없는 값이 있어요(${field}). 다시 꾸며 주세요.`,
},
CUSTOM_INPUT_REQUIRED: {
status: HttpStatus.BAD_REQUEST,
message: '케이크를 꾸민 뒤 주문해 주세요.',
},
CUSTOM_INPUT_MISMATCH: {
status: HttpStatus.BAD_REQUEST,
message: '이 상품의 꾸미기 방식과 맞지 않는 주문이에요. 다시 꾸며 주세요.',
},
CUSTOM_QUANTITY_FIXED: {
status: HttpStatus.BAD_REQUEST,
message: '꾸민 케이크는 한 번에 1개만 주문할 수 있어요.',
},
CUSTOM_TEMPLATE_CHANGED: {
status: HttpStatus.CONFLICT,
message: '판매자가 꾸미기 설정을 바꿨어요. 다시 꾸며 주세요.',
},
CUSTOM_SLOT_TEXTS_MISMATCH: {
status: HttpStatus.BAD_REQUEST,
message: '문구 자리 입력이 상품 설정과 맞지 않아요. 다시 꾸며 주세요.',
},
CUSTOM_SLOT_TEXT_REQUIRED: {
status: HttpStatus.BAD_REQUEST,
message: ({ label }) => `'${label}'에 문구를 넣어 주세요.`,
},
CUSTOM_SLOT_TEXT_TOO_LONG: {
status: HttpStatus.BAD_REQUEST,
message: ({ label, max }) => `'${label}'에는 ${max}자까지 쓸 수 있어요.`,
},
CUSTOM_FREE_EDIT_INVALID: {
status: HttpStatus.BAD_REQUEST,
message: ({ field }) =>
`자유 편집 요청에 쓸 수 없는 값이 있어요(${field}). 다시 확인해 주세요.`,
},
CUSTOM_RENDER_IMAGES_INVALID: {
status: HttpStatus.BAD_REQUEST,
message:
'3D 렌더 이미지는 윗면과 옆면 앞·뒤·왼쪽·오른쪽이 1장씩 있어야 해요.',
},
CUSTOM_UPLOAD_INVALID: {
status: HttpStatus.BAD_REQUEST,
message: '꾸미기 이미지를 확인할 수 없어요. 이미지를 다시 올려 주세요.',
},
CUSTOM_UPLOAD_EXPIRED: {
status: HttpStatus.BAD_REQUEST,
message: '꾸미기 이미지 보관 기간이 지났어요. 이미지를 다시 올려 주세요.',
},
INVALID_DAY_OF_WEEK: {
status: HttpStatus.BAD_REQUEST,
message: 'dayOfWeek는 0~6이어야 합니다.',
Expand Down
9 changes: 9 additions & 0 deletions src/features/order/constants/order-custom-upload-purposes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { OrderCustomUploadPurpose } from '@/generated/prisma/client';
import type { UploadPurpose } from '@/global/storage/types/storage.types';

/** 구매자 커스텀 업로드 용도 → 저장소 정책(키 접두·형식·크기). 발급과 주문 생성의 소유 검증이 같은 표를 쓴다. */
export const CUSTOM_UPLOAD_PURPOSES = {
RENDER: 'ORDER_CUSTOM_RENDER',
COMPOSITE: 'ORDER_CUSTOM_COMPOSITE',
REFERENCE: 'ORDER_CUSTOM_REFERENCE',
} as const satisfies Record<OrderCustomUploadPurpose, UploadPurpose>;
182 changes: 182 additions & 0 deletions src/features/order/dto/inputs/create-order-custom.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { Type } from 'class-transformer';
import {
IsArray,
IsDefined,
IsEnum,
IsIn,
IsInt,
IsNumber,
IsOptional,
IsString,
MaxLength,
ValidateNested,
} from 'class-validator';

import { CustomImageKind } from '@/generated/prisma/client';

// 저장 컬럼 길이. 개수·글자 수·좌표 범위는 상품 설정과 함께 봐야 해서 서비스가 도메인 코드로 판정한다.
const MAX_URL_LENGTH = 2048;

export class CreateOrderSlotTextInput {
@IsString()
tokenId!: string;

@IsOptional()
@IsString()
valueText?: string | null;
}

export class CreateOrderFreeEditInput {
@IsInt()
posX!: number;

@IsInt()
posY!: number;

@IsInt()
width!: number;

@IsInt()
height!: number;

@IsString()
descriptionText!: string;

@IsOptional()
@IsArray()
@IsString({ each: true })
@MaxLength(MAX_URL_LENGTH, { each: true })
referenceImageUrls?: string[] | null;
}

export class CreateOrderSlotCustomInput {
@IsInt()
templateRevision!: number;

@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateOrderSlotTextInput)
texts!: CreateOrderSlotTextInput[];

@IsString()
@MaxLength(MAX_URL_LENGTH)
compositeImageUrl!: string;

@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateOrderFreeEditInput)
freeEdits?: CreateOrderFreeEditInput[] | null;
}

export class ThreeDDesignBasicInput {
@IsString()
shape!: string;

@IsString()
size!: string;

@IsOptional()
@IsString()
design?: string | null;

@IsOptional()
@IsString()
flavor?: string | null;

@IsString()
sheetColor!: string;
}

export class ThreeDDesignEffectInput {
@IsString()
type!: string;

@IsInt()
intensity!: number;
}

export class ThreeDDesignItemInput {
@IsIn(['TEXT', 'DECO'])
kind!: 'TEXT' | 'DECO';

@IsNumber()
x!: number;

@IsNumber()
y!: number;

@IsNumber()
size!: number;

@IsDefined()
@ValidateNested()
@Type(() => ThreeDDesignEffectInput)
effect!: ThreeDDesignEffectInput;

@IsOptional()
@IsString()
text?: string | null;

@IsOptional()
@IsString()
color?: string | null;

@IsOptional()
@IsString()
decoId?: string | null;
}

export class ThreeDDesignInput {
@IsInt()
schemaVersion!: number;

@IsDefined()
@ValidateNested()
@Type(() => ThreeDDesignBasicInput)
basic!: ThreeDDesignBasicInput;

@IsArray()
@ValidateNested({ each: true })
@Type(() => ThreeDDesignItemInput)
top!: ThreeDDesignItemInput[];

@IsArray()
@ValidateNested({ each: true })
@Type(() => ThreeDDesignItemInput)
side!: ThreeDDesignItemInput[];
}

export class CreateOrderRenderImageInput {
@IsEnum(CustomImageKind)
kind!: CustomImageKind;

@IsString()
@MaxLength(MAX_URL_LENGTH)
imageUrl!: string;
}

export class CreateOrderThreeDCustomInput {
@IsDefined()
@ValidateNested()
@Type(() => ThreeDDesignInput)
design!: ThreeDDesignInput;

@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateOrderRenderImageInput)
renderImages!: CreateOrderRenderImageInput[];
}

/** 커스텀 상품이면 그 방식의 입력 하나만 보낸다. */
export class CreateOrderCustomInput {
@IsOptional()
@ValidateNested()
@Type(() => CreateOrderSlotCustomInput)
slot?: CreateOrderSlotCustomInput | null;

@IsOptional()
@ValidateNested()
@Type(() => CreateOrderThreeDCustomInput)
threeD?: CreateOrderThreeDCustomInput | null;
}
139 changes: 139 additions & 0 deletions src/features/order/dto/inputs/create-order.input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,143 @@ describe('CreateOrderInput', () => {
);
expect(errors.map((e) => e.property)).toEqual(['requestNote']);
});

describe('custom', () => {
// 전역 ValidationPipe와 같은 옵션 — 데코레이터가 빠진 중첩 필드는 여기서 거절된다
const STRICT = { whitelist: true, forbidNonWhitelisted: true };
const SLOT = {
templateRevision: 1,
texts: [{ tokenId: '1', valueText: '축하해' }, { tokenId: '2' }],
compositeImageUrl: 'https://img/c.png',
freeEdits: [
{
posX: 0,
posY: 0,
width: 10,
height: 10,
descriptionText: '꽃',
referenceImageUrls: ['https://img/r.png'],
},
],
};
const THREE_D = {
design: {
schemaVersion: 1,
basic: {
shape: 'heart',
size: 'mini',
design: null,
flavor: 'cream',
sheetColor: 'white',
},
top: [
{
kind: 'TEXT',
x: 0.5,
y: 0.5,
size: 8,
effect: { type: 'none', intensity: 50 },
text: '축하해',
color: '#000000',
},
],
side: [
{
kind: 'DECO',
x: 0.1,
y: 0.2,
size: 20,
effect: { type: 'soft', intensity: 0 },
decoId: 'number-1',
},
],
},
renderImages: [{ kind: 'THREE_D_TOP', imageUrl: 'https://img/t.png' }],
};

it.each([
['슬롯형', { slot: SLOT }],
['3D', { threeD: THREE_D }],
['자유 편집·참고 사진 생략', { slot: { ...SLOT, freeEdits: undefined } }],
])(
'%s 입력의 모든 필드가 화이트리스트를 통과한다',
async (_case, custom) => {
expect(
await validate(build({ ...VALID, custom }), STRICT),
).toHaveLength(0);
},
);

it.each<[string, object]>([
[
'문구 자리 tokenId가 숫자',
{ slot: { ...SLOT, texts: [{ tokenId: 1 }] } },
],
[
'모르는 필드',
{ slot: { ...SLOT, texts: [{ tokenId: '1', extra: 'x' }] } },
],
[
'자유 편집 좌표가 문자열',
{ slot: { ...SLOT, freeEdits: [{ ...SLOT.freeEdits[0], posX: '1' }] } },
],
[
'합성 이미지 URL 2049자',
{ slot: { ...SLOT, compositeImageUrl: 'h'.repeat(2049) } },
],
[
'렌더 이미지 종류가 enum 밖',
{
threeD: {
...THREE_D,
renderImages: [{ kind: 'SIDE', imageUrl: 'https://img/t.png' }],
},
},
],
[
'3D 항목 종류가 enum 밖',
{
threeD: {
...THREE_D,
design: {
...THREE_D.design,
top: [{ ...THREE_D.design.top[0], kind: 'IMAGE' }],
},
},
},
],
[
'효과 강도가 소수',
{
threeD: {
...THREE_D,
design: {
...THREE_D.design,
side: [
{
...THREE_D.design.side[0],
effect: { type: 'soft', intensity: 1.5 },
},
],
},
},
},
],
[
'디자인 basic 누락',
{
threeD: {
...THREE_D,
design: { ...THREE_D.design, basic: undefined },
},
},
],
])(
'중첩 입력의 형식 오류(%s)는 custom에서 거절한다',
async (_case, custom) => {
const errors = await validate(build({ ...VALID, custom }), STRICT);
expect(errors.map((e) => e.property)).toEqual(['custom']);
},
);
});
});
Loading
Loading