Skip to content
Merged
4 changes: 4 additions & 0 deletions src/common/errors/error-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ export const ERROR_CATALOG = {
status: HttpStatus.BAD_REQUEST,
message: '선택한 픽업 일시는 예약할 수 없습니다.',
},
NO_SHOW_NOT_ALLOWED: {
status: HttpStatus.BAD_REQUEST,
message: '노쇼는 픽업 시각부터 24시간 안에만 처리할 수 있습니다.',
},
ORDER_AMOUNT_OUT_OF_RANGE: {
status: HttpStatus.BAD_REQUEST,
message: '주문 금액이 처리 가능한 범위를 벗어났습니다.',
Expand Down
2 changes: 2 additions & 0 deletions src/features/notification/constants/notification-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const ORDER_STATUS_NOTIFICATION_TITLES: Partial<
[OrderStatus.CONFIRMED]: '주문확정',
[OrderStatus.MADE]: '제작완료',
[OrderStatus.PICKED_UP]: '픽업완료',
[OrderStatus.NO_SHOW]: '노쇼',
};

/** 주문번호 prefix는 식별 필요 가능성에 대비해 유지한다 — 표시 여부는 FE 판단. */
Expand All @@ -18,6 +19,7 @@ export const ORDER_STATUS_NOTIFICATION_BODIES: Partial<
[OrderStatus.CONFIRMED]: '주문이 확정되었어요.',
[OrderStatus.MADE]: '주문하신 케이크 제작이 완료되었어요.',
[OrderStatus.PICKED_UP]: '케이크 픽업이 완료되었어요.',
[OrderStatus.NO_SHOW]: '픽업 시간에 방문하지 않아 노쇼로 처리되었어요.',
};

/** 취소는 사유 라벨을 덧붙인다(판매자·운영자·자동 미확정 공통). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ describe('notification-payloads.helper', () => {
'픽업완료',
'케이크 픽업이 완료되었어요.',
],
[
'NO_SHOW',
'ORDER_NO_SHOW',
'노쇼',
'픽업 시간에 방문하지 않아 노쇼로 처리되었어요.',
],
] as const)('%s는 %s(주문번호 접두)', (toStatus, event, title, body) => {
expect(status(toStatus)).toEqual({
type: NotificationType.ORDER_STATUS,
Expand All @@ -59,12 +65,15 @@ describe('notification-payloads.helper', () => {
});
});

it.each(['PENDING_PAYMENT', 'NO_SHOW'] as const)(
'매핑이 없는 상태(%s)는 null',
(toStatus) => {
expect(status(toStatus)).toBeNull();
},
);
it('매핑이 없는 상태(PENDING_PAYMENT)는 null', () => {
expect(status('PENDING_PAYMENT')).toBeNull();
});

it('자동 픽업 완료(SYSTEM)도 픽업 완료 알림이다', () => {
expect(status('PICKED_UP', { actorType: 'SYSTEM' })).toMatchObject({
event: NotificationEvent.ORDER_PICKED_UP,
});
});

it.each(
Object.values(OrderCancelReason).filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const ORDER_STATUS_NOTIFICATION_EVENTS: Partial<
[OrderStatus.CONFIRMED]: NotificationEvent.ORDER_CONFIRMED,
[OrderStatus.MADE]: NotificationEvent.ORDER_MADE,
[OrderStatus.PICKED_UP]: NotificationEvent.ORDER_PICKED_UP,
[OrderStatus.NO_SHOW]: NotificationEvent.ORDER_NO_SHOW,
};

/** 매핑에 없는 상태와 구매자 본인 행위(취소)는 알림 없음(null). */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
buildBuyerMessagePush,
buildOrderCanceledPush,
buildOrderConfirmReminderPush,
buildOrderSubmittedPush,
formatKstPickupAt,
} from '@/features/notification/services/seller-push-messages.helper';
Expand Down Expand Up @@ -57,6 +58,22 @@ describe('seller-push-messages.helper', () => {
).toBe(`레터링 케이크 2개 · 픽업 10/5 12:05${suffix}`);
});

it('확정 마감 미리 알림: 상품명과 마감 시각(KST HH:mm), 딥링크 data는 kind·orderId', () => {
expect(
buildOrderConfirmReminderPush({
orderId: '42',
orderNumber: 'ORD-1',
storeId: '3',
productName: '레터링 케이크',
confirmDeadlineAt: '2026-10-05T03:00:00.000Z',
}),
).toEqual({
title: '확정 마감 임박',
body: '레터링 케이크 주문을 12:00까지 확정하지 않으면 자동 취소돼요',
data: { kind: 'ORDER_CONFIRM_REMINDER', orderId: '42' },
});
});

it('구매자 문의: 본문은 preview 그대로, data는 kind·conversationId', () => {
expect(
buildBuyerMessagePush({
Expand Down
16 changes: 16 additions & 0 deletions src/features/notification/services/seller-push-messages.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@/common/utils/kst-time';
import type { ConversationBuyerMessageSentPayload } from '@/features/conversation';
import type {
OrderConfirmReminderDuePayload,
OrderStatusChangedPayload,
OrderSubmittedPayload,
} from '@/features/order';
Expand All @@ -14,6 +15,7 @@ import { OrderActor, OrderStatus } from '@/generated/prisma/client';
const SELLER_PUSH_KIND = {
ORDER_SUBMITTED: 'ORDER_SUBMITTED',
ORDER_CANCELED: 'ORDER_CANCELED',
ORDER_CONFIRM_REMINDER: 'ORDER_CONFIRM_REMINDER',
BUYER_MESSAGE: 'BUYER_MESSAGE',
} as const;

Expand Down Expand Up @@ -85,6 +87,20 @@ export function buildOrderCanceledPush(
};
}

/** 확정 마감 2시간 전. 마감은 2시간 안이라 시각만 적는다. */
export function buildOrderConfirmReminderPush(
p: OrderConfirmReminderDuePayload,
): SellerPushContent {
const deadline = formatMinutesOfDay(
kstMinutesOfDay(new Date(p.confirmDeadlineAt)),
);
return {
title: '확정 마감 임박',
body: `${p.productName} 주문을 ${deadline}까지 확정하지 않으면 자동 취소돼요`,
data: { kind: SELLER_PUSH_KIND.ORDER_CONFIRM_REMINDER, orderId: p.orderId },
};
}

export function buildBuyerMessagePush(
p: ConversationBuyerMessageSentPayload,
): SellerPushContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,27 @@ describe('SellerPushOutboxConsumer (real DB)', () => {
});
});

it('order.confirm_reminder_due는 매장 디바이스에 확정 마감 미리 알림을 보낸다', async () => {
const { storeId } = await storeWithDevices(1);

await consumer.handle(
event('order.confirm_reminder_due', {
orderId: '42',
orderNumber: 'ORD-1',
storeId: storeId.toString(),
productName: '레터링 케이크',
confirmDeadlineAt: '2026-10-05T03:00:00.000Z',
}),
);

expect(send.mock.calls[0][0][0]).toMatchObject({
title: '확정 마감 임박',
body: '레터링 케이크 주문을 12:00까지 확정하지 않으면 자동 취소돼요',
data: { kind: 'ORDER_CONFIRM_REMINDER', orderId: '42' },
});
expect(await deliveries()).toHaveLength(1);
});

it('conversation.buyer_message_sent는 preview를 본문으로, 딥링크는 대화 id', async () => {
const { storeId, devices } = await storeWithDevices(1);

Expand Down
11 changes: 11 additions & 0 deletions src/features/notification/services/seller-push-outbox.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import { SellerPushDeviceRepository } from '@/features/notification/repositories
import {
buildBuyerMessagePush,
buildOrderCanceledPush,
buildOrderConfirmReminderPush,
buildOrderSubmittedPush,
SELLER_PUSH_CHANNEL_ID,
type SellerPushContent,
} from '@/features/notification/services/seller-push-messages.helper';
import {
ORDER_CONFIRM_REMINDER_DUE,
ORDER_STATUS_CHANGED,
ORDER_SUBMITTED,
parseOrderConfirmReminderDuePayload,
parseOrderStatusChangedPayload,
parseOrderSubmittedPayload,
} from '@/features/order';
Expand Down Expand Up @@ -55,6 +58,7 @@ import { MetricsService } from '@/global/metrics';
@SubscribeOutbox(
ORDER_SUBMITTED,
ORDER_STATUS_CHANGED,
ORDER_CONFIRM_REMINDER_DUE,
CONVERSATION_BUYER_MESSAGE_SENT,
)
export class SellerPushOutboxConsumer implements OutboxConsumer {
Expand Down Expand Up @@ -181,6 +185,13 @@ export class SellerPushOutboxConsumer implements OutboxConsumer {
? { storeId: parseId(push.storeId), content: push.content }
: null;
}
case ORDER_CONFIRM_REMINDER_DUE: {
const p = parseOrderConfirmReminderDuePayload(event.payload);
return {
storeId: parseId(p.storeId),
content: buildOrderConfirmReminderPush(p),
};
}
case CONVERSATION_BUYER_MESSAGE_SENT: {
const p = parseConversationBuyerMessageSentPayload(event.payload);
return {
Expand Down
10 changes: 10 additions & 0 deletions src/features/order/dto/inputs/admin-complete-order-pickup.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IsOptional, IsString } from 'class-validator';

export class AdminCompleteOrderPickupInput {
@IsString()
orderId!: string;

@IsOptional()
@IsString()
note?: string | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class SellerUpdateOrderStatusInput {
@IsString()
orderId!: string;

// 전이 가능 여부는 정책(assertSellerTransition)이 판정한다
// 전이 가능 여부는 정책(assertTransition)이 판정한다
@IsEnum(OrderStatus)
toStatus!: OrderStatus;

Expand Down
52 changes: 52 additions & 0 deletions src/features/order/events/order-confirm-reminder-due.event.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
ORDER_CONFIRM_REMINDER_DUE,
orderConfirmReminderDueEvent,
parseOrderConfirmReminderDuePayload,
} from '@/features/order/events/order-confirm-reminder-due.event';
import type { Prisma } from '@/generated/prisma/client';

const VALID = {
orderId: '7',
orderNumber: 'ORD-20261119-ABC234',
storeId: '5',
productName: '딸기 케이크',
confirmDeadlineAt: '2026-11-19T09:00:00.000Z',
};

describe('order.confirm_reminder_due 이벤트', () => {
it('bigint·Date를 문자열로 싣고 order aggregate에 묶는다(시스템 발행이라 행위자 없음)', () => {
const occurredAt = new Date('2026-11-19T07:00:00.000Z');
const event = orderConfirmReminderDueEvent({
orderId: 7n,
orderNumber: VALID.orderNumber,
storeId: 5n,
productName: VALID.productName,
confirmDeadlineAt: new Date(VALID.confirmDeadlineAt),
occurredAt,
});

expect(event).toEqual({
aggregateType: 'order',
aggregateId: '7',
eventType: ORDER_CONFIRM_REMINDER_DUE,
payload: VALID,
occurredAt,
actorAccountId: null,
});
expect(
parseOrderConfirmReminderDuePayload(event.payload as Prisma.JsonValue),
).toEqual(VALID);
});

it.each([
['배열', []],
['null', null],
['매장 누락', { ...VALID, storeId: undefined }],
['마감 비ISO', { ...VALID, confirmDeadlineAt: 'not-a-date' }],
['상품명 숫자', { ...VALID, productName: 3 }],
])('%s payload는 던진다', (_label, value) => {
expect(() =>
parseOrderConfirmReminderDuePayload(value as Prisma.JsonValue),
).toThrow('order.confirm_reminder_due payload 형식 오류');
});
});
68 changes: 68 additions & 0 deletions src/features/order/events/order-confirm-reminder-due.event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { OutboxEventInput } from '@/features/outbox';
import type { Prisma } from '@/generated/prisma/client';

/** 확정 마감 2시간 전 판매자 미리 알림. payload는 생산 시점 스냅샷이다. */
export const ORDER_CONFIRM_REMINDER_DUE = 'order.confirm_reminder_due';

export interface OrderConfirmReminderDuePayload {
orderId: string;
orderNumber: string;
storeId: string;
productName: string;
/** ISO 8601 */
confirmDeadlineAt: string;
}

export function orderConfirmReminderDueEvent(args: {
orderId: bigint;
orderNumber: string;
storeId: bigint;
productName: string;
confirmDeadlineAt: Date;
occurredAt: Date;
}): OutboxEventInput {
const payload: OrderConfirmReminderDuePayload = {
orderId: args.orderId.toString(),
orderNumber: args.orderNumber,
storeId: args.storeId.toString(),
productName: args.productName,
confirmDeadlineAt: args.confirmDeadlineAt.toISOString(),
};
return {
aggregateType: 'order',
aggregateId: payload.orderId,
eventType: ORDER_CONFIRM_REMINDER_DUE,
payload: { ...payload },
occurredAt: args.occurredAt,
actorAccountId: null,
};
}

/** 소비자용 방어적 파싱 — 형태가 어긋난 payload는 던져서 재시도·FAILED로 드러낸다. */
export function parseOrderConfirmReminderDuePayload(
value: Prisma.JsonValue,
): OrderConfirmReminderDuePayload {
const p = value as Partial<
Record<keyof OrderConfirmReminderDuePayload, unknown>
>;
if (
typeof value !== 'object' ||
value === null ||
Array.isArray(value) ||
typeof p.orderId !== 'string' ||
typeof p.orderNumber !== 'string' ||
typeof p.storeId !== 'string' ||
typeof p.productName !== 'string' ||
typeof p.confirmDeadlineAt !== 'string' ||
Number.isNaN(Date.parse(p.confirmDeadlineAt))
) {
throw new Error(`${ORDER_CONFIRM_REMINDER_DUE} payload 형식 오류`);
}
return {
orderId: p.orderId,
orderNumber: p.orderNumber,
storeId: p.storeId,
productName: p.productName,
confirmDeadlineAt: p.confirmDeadlineAt,
};
}
6 changes: 6 additions & 0 deletions src/features/order/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ export {
type OrderSubmittedPayload,
parseOrderSubmittedPayload,
} from '@/features/order/events/order-submitted.event';
// 확정 마감 미리 알림 이벤트 계약(outbox). 판매자 푸시 소비자(notification)가 읽는다.
export {
ORDER_CONFIRM_REMINDER_DUE,
type OrderConfirmReminderDuePayload,
parseOrderConfirmReminderDuePayload,
} from '@/features/order/events/order-confirm-reminder-due.event';
Loading
Loading