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
6 changes: 5 additions & 1 deletion src/models/base/kakao/bms/bmsButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export const bmsAppButtonSchema = Schema.Struct({
targetOut: Schema.optional(Schema.Boolean),
}).pipe(
Schema.filter(button => {
const hasLink = button.linkMobile || button.linkAndroid || button.linkIos;
// present-but-empty 문자열을 "제공됨"으로 간주해서는 안 되므로 trim 후 길이로 판단
const hasLink =
(button.linkMobile !== undefined && button.linkMobile.trim() !== '') ||
(button.linkAndroid !== undefined && button.linkAndroid.trim() !== '') ||
(button.linkIos !== undefined && button.linkIos.trim() !== '');
return hasLink
? true
: 'AL 타입 버튼은 linkMobile, linkAndroid, linkIos 중 하나 이상 필수입니다.';
Expand Down
12 changes: 11 additions & 1 deletion src/models/base/kakao/bms/bmsCarousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ export const bmsCarouselHeadSchema = Schema.Struct({
linkPc: Schema.optional(Schema.String),
linkAndroid: Schema.optional(Schema.String),
linkIos: Schema.optional(Schema.String),
});
}).pipe(
Schema.filter(head => {
const hasOther =
head.linkPc !== undefined ||
head.linkAndroid !== undefined ||
head.linkIos !== undefined;
return hasOther && head.linkMobile === undefined
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

linkMobile의 존재 여부를 확인할 때 undefined만 체크하고 있습니다. bmsButton.tsbmsAppButtonSchema 필터(61-65라인)와 동일하게, 빈 문자열("")이나 공백만 있는 경우도 "값이 없는 것"으로 간주하도록 trim() !== '' 체크를 추가하는 것이 일관성 및 정확성 측면에서 좋습니다.

Suggested change
return hasOther && head.linkMobile === undefined
return hasOther && (head.linkMobile === undefined || head.linkMobile.trim() === '')

? 'linkPc, linkAndroid, linkIos 중 하나라도 있으면 linkMobile 값이 필수입니다.'
: true;
}),
);

export type BmsCarouselHeadSchema = Schema.Schema.Type<
typeof bmsCarouselHeadSchema
Expand Down
16 changes: 16 additions & 0 deletions src/models/base/kakao/bms/bmsChatBubbleType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Schema} from 'effect';

export const bmsChatBubbleTypeSchema = Schema.Literal(
'TEXT',
'IMAGE',
'WIDE',
'WIDE_ITEM_LIST',
'COMMERCE',
'CAROUSEL_FEED',
'CAROUSEL_COMMERCE',
'PREMIUM_VIDEO',
);

export type BmsChatBubbleType = Schema.Schema.Type<
typeof bmsChatBubbleTypeSchema
>;
32 changes: 28 additions & 4 deletions src/models/base/kakao/bms/bmsCommerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ const NumberOrNumericString: Schema.Schema<number, number> =
},
) as Schema.Schema<number, number>;

/**
* 커머스 가격 필드 범위 제약 (서버 검증 규칙과 일치)
*/
const COMMERCE_PRICE_MAX = 99_999_999;
const DISCOUNT_RATE_MAX = 100;

const numberInRange = (
fieldName: string,
min: number,
max: number,
): Schema.Schema<number, number> =>
NumberOrNumericString.pipe(
Schema.filter(n => n >= min && n <= max, {
message: () =>
`${fieldName} 값이 잘못되었습니다. ${min} 이상 ${max} 이하의 숫자여야 합니다.`,
}),
) as Schema.Schema<number, number>;

/**
* BMS 커머스 가격 조합 검증
*
Expand Down Expand Up @@ -119,10 +137,16 @@ const validateCommercePricingCombination = (commerce: {
*/
export const bmsCommerceSchema = Schema.Struct({
title: Schema.String,
regularPrice: NumberOrNumericString,
discountPrice: Schema.optional(NumberOrNumericString),
discountRate: Schema.optional(NumberOrNumericString),
discountFixed: Schema.optional(NumberOrNumericString),
regularPrice: numberInRange('regularPrice', 0, COMMERCE_PRICE_MAX),
discountPrice: Schema.optional(
numberInRange('discountPrice', 0, COMMERCE_PRICE_MAX),
),
discountRate: Schema.optional(
numberInRange('discountRate', 0, DISCOUNT_RATE_MAX),
),
discountFixed: Schema.optional(
numberInRange('discountFixed', 0, COMMERCE_PRICE_MAX),
),
}).pipe(Schema.filter(validateCommercePricingCombination));

export type BmsCommerceSchema = Schema.Schema.Type<typeof bmsCommerceSchema>;
Loading