관리자(user_type='A') 가 본인 구독으로 테스트해도 알람 미수신이던 문제 — notifyItemSale 의 generalOnly 옵션을 해제. 관리자도 본인의 변경분으로 발송 확인 가능. items/save 와 bulk-sale-range 양쪽에 sent/failed/스킵 사유 로그 추가.
This commit is contained in:
@@ -69,13 +69,13 @@ export async function POST(req: NextRequest) {
|
||||
if (rows.length === 1) {
|
||||
const r = rows[0];
|
||||
const body = r.orderable_now ? r.item_name : `${r.item_name} (${r.start_txt ?? "곧"} 판매 예정)`;
|
||||
await sendPush({ title: "새 상품이 등록되었습니다", body, url: "/m/orders/new", tag: "item-bulk" }, undefined, { generalOnly: true });
|
||||
const sr = await sendPush({ title: "새 상품이 등록되었습니다", body, url: "/m/orders/new", tag: "item-bulk" });
|
||||
console.log(`[bulk-sale-range notify] item=${r.item_name} sent=${sr.sent} failed=${sr.failed}`);
|
||||
} else if (rows.length > 1) {
|
||||
await sendPush(
|
||||
{ title: "새 상품이 등록되었습니다", body: `${rows.length}개 상품이 등록되었습니다. 지금 확인해보세요.`, url: "/m/orders/new", tag: "item-bulk" },
|
||||
undefined,
|
||||
{ generalOnly: true }
|
||||
const sr = await sendPush(
|
||||
{ title: "새 상품이 등록되었습니다", body: `${rows.length}개 상품이 등록되었습니다. 지금 확인해보세요.`, url: "/m/orders/new", tag: "item-bulk" }
|
||||
);
|
||||
console.log(`[bulk-sale-range notify] count=${rows.length} sent=${sr.sent} failed=${sr.failed}`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[bulk-sale-range notify]", e);
|
||||
|
||||
@@ -73,17 +73,17 @@ async function getSaleInfo(objid: string): Promise<SaleInfo | null> {
|
||||
};
|
||||
}
|
||||
|
||||
// 판매 일정 등록/변경 시 일반 사용자(거래처) 전체에게 푸시 (실패해도 저장에는 영향 없음)
|
||||
// 판매 일정 등록/변경 시 모든 구독자(거래처 + 관리자 본인 포함) 에게 푸시.
|
||||
// 관리자 본인도 본인 변경분을 받아 새 상품 등록 사실/시점을 확인할 수 있게 함.
|
||||
async function notifyItemSale(itemName: string, objid: string, info: SaleInfo) {
|
||||
try {
|
||||
const body = info.orderableNow
|
||||
? itemName
|
||||
: `${itemName} (${info.startTxt ?? "곧"} 판매 예정)`;
|
||||
await sendPush(
|
||||
{ title: "새 상품이 등록되었습니다", body, url: "/m/orders/new", tag: `item-${objid}` },
|
||||
undefined,
|
||||
{ generalOnly: true }
|
||||
const res = await sendPush(
|
||||
{ title: "새 상품이 등록되었습니다", body, url: "/m/orders/new", tag: `item-${objid}` }
|
||||
);
|
||||
console.log(`[items/save notify] item=${itemName} sent=${res.sent} failed=${res.failed}`);
|
||||
} catch (err) {
|
||||
console.error("[items/save notify]", err);
|
||||
}
|
||||
@@ -191,8 +191,11 @@ export async function POST(req: NextRequest) {
|
||||
(beforeInfo?.startTxt ?? null) !== (afterInfo?.startTxt ?? null) ||
|
||||
(beforeInfo?.endTxt ?? null) !== (afterInfo?.endTxt ?? null) ||
|
||||
(beforeInfo?.alwaysSale ?? false) !== (afterInfo?.alwaysSale ?? false);
|
||||
console.log(`[items/save] update item=${cleanName} objid=${objid} datesChanged=${datesChanged} sellable=${afterInfo?.sellable} alwaysSale=${afterInfo?.alwaysSale} startBefore="${beforeInfo?.startTxt ?? ""}" startAfter="${afterInfo?.startTxt ?? ""}" endBefore="${beforeInfo?.endTxt ?? ""}" endAfter="${afterInfo?.endTxt ?? ""}"`);
|
||||
if (datesChanged && afterInfo?.sellable) {
|
||||
await notifyItemSale(cleanName, objid, afterInfo);
|
||||
} else {
|
||||
console.log(`[items/save] notify SKIPPED — datesChanged=${datesChanged} sellable=${afterInfo?.sellable}`);
|
||||
}
|
||||
return NextResponse.json({ success: true, objId: objid });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user