Penerapaan ke database untuk token device

Add:
src/app/api/mobile/auth/device-tokens/[id]/

Fix:
modified:   src/app/api/mobile/auth/device-tokens/route.ts
modified:   src/app/api/mobile/notifications/route.ts

### No Issue
This commit is contained in:
2025-12-17 17:40:56 +08:00
parent 3e0d2743fb
commit 02b25ffc84
3 changed files with 95 additions and 18 deletions

View File

@@ -1,13 +1,14 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib";
export async function POST(request: NextRequest) {
export { POST, GET };
async function POST(request: NextRequest) {
const { data } = await request.json();
try {
console.log("Data >>", JSON.stringify(data, null, 2));
const { userId, platform, deviceId, model, appVersion, fcmToken } =
data;
const { userId, platform, deviceId, model, appVersion, fcmToken } = data;
if (!fcmToken) {
return NextResponse.json({ error: "Missing Token" }, { status: 400 });
@@ -62,3 +63,22 @@ export async function POST(request: NextRequest) {
);
}
}
async function GET(request: NextRequest) {
try {
const data = await prisma.tokenUserDevice.findMany({
where: {
isActive: true,
},
});
return NextResponse.json({ success: true, data });
} catch (error) {
return NextResponse.json(
{ error: (error as Error).message },
{ status: 500 }
);
}
}