Fix send whatsapp
Auth API - src/app/api/auth/login/route.ts - src/app/api/auth/mobile-login/route.ts - src/app/api/auth/mobile-register/route.ts - src/app/api/auth/resend/route.ts User API (Mobile) - src/app/api/mobile/user/route.ts - src/app/api/mobile/admin/user/[id]/route.ts Utility - src/lib/code-otp-sender.ts ### No issue
This commit is contained in:
@@ -2,7 +2,7 @@ import { prisma } from "@/lib";
|
|||||||
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
||||||
import backendLogger from "@/util/backendLogger";
|
import backendLogger from "@/util/backendLogger";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { sendCodeOtp } from "@/lib/code-otp-sender";
|
import { funSendToWhatsApp } from "@/lib/code-otp-sender";
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
if (req.method !== "POST") {
|
if (req.method !== "POST") {
|
||||||
@@ -30,7 +30,7 @@ export async function POST(req: Request) {
|
|||||||
{ status: 400 },
|
{ status: 400 },
|
||||||
);
|
);
|
||||||
|
|
||||||
const resSendCode = await sendCodeOtp({
|
const resSendCode = await funSendToWhatsApp({
|
||||||
nomor,
|
nomor,
|
||||||
codeOtp: codeOtp.toString(),
|
codeOtp: codeOtp.toString(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { sendCodeOtp } from "@/lib/code-otp-sender";
|
import { funSendToWhatsApp } from "@/lib/code-otp-sender";
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
try {
|
try {
|
||||||
@@ -35,7 +35,7 @@ export async function POST(req: Request) {
|
|||||||
{ status: 400 },
|
{ status: 400 },
|
||||||
);
|
);
|
||||||
|
|
||||||
const resSendCode = await sendCodeOtp({
|
const resSendCode = await funSendToWhatsApp({
|
||||||
nomor,
|
nomor,
|
||||||
codeOtp: codeOtp.toString(),
|
codeOtp: codeOtp.toString(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
NotificationMobileBodyType,
|
NotificationMobileBodyType,
|
||||||
NotificationMobileTitleType,
|
NotificationMobileTitleType,
|
||||||
} from "../../../../../types/type-mobile-notification";
|
} from "../../../../../types/type-mobile-notification";
|
||||||
import { sendCodeOtp } from "@/lib/code-otp-sender";
|
import { funSendToWhatsApp } from "@/lib/code-otp-sender";
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
if (req.method !== "POST") {
|
if (req.method !== "POST") {
|
||||||
@@ -70,7 +70,7 @@ export async function POST(req: Request) {
|
|||||||
{ status: 400 }
|
{ status: 400 }
|
||||||
);
|
);
|
||||||
|
|
||||||
const resSendCode = await sendCodeOtp({
|
const resSendCode = await funSendToWhatsApp({
|
||||||
nomor: data.nomor,
|
nomor: data.nomor,
|
||||||
codeOtp: codeOtp.toString(),
|
codeOtp: codeOtp.toString(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { prisma } from "@/lib";
|
|||||||
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
||||||
import backendLogger from "@/util/backendLogger";
|
import backendLogger from "@/util/backendLogger";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { sendCodeOtp } from "@/lib/code-otp-sender";
|
import { funSendToWhatsApp } from "@/lib/code-otp-sender";
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
if (req.method !== "POST") {
|
if (req.method !== "POST") {
|
||||||
@@ -17,7 +17,7 @@ export async function POST(req: Request) {
|
|||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
const { nomor } = body;
|
const { nomor } = body;
|
||||||
|
|
||||||
const resSendCode = await sendCodeOtp({
|
const resSendCode = await funSendToWhatsApp({
|
||||||
nomor,
|
nomor,
|
||||||
codeOtp: codeOtp.toString(),
|
codeOtp: codeOtp.toString(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import { funSendToWhatsApp } from "@/lib/code-otp-sender";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
@@ -50,8 +51,25 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
|||||||
data: {
|
data: {
|
||||||
active: data.active,
|
active: data.active,
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
nomor: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (data.active) {
|
||||||
|
const resSendCode = await funSendToWhatsApp({
|
||||||
|
nomor: updateData.nomor,
|
||||||
|
newMessage:
|
||||||
|
"Halo sahabat HIConnect, \nSelamat akun anda telah aktif ! \n\n*Pesan ini di kirim secara otomatis, tidak perlu di balas.",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const resSendCode = await funSendToWhatsApp({
|
||||||
|
nomor: updateData.nomor,
|
||||||
|
newMessage:
|
||||||
|
"Halo sahabat HIConnect, \nMohon maaf akun anda telah dinonaktifkan ! Hubungi admin untuk informasi lebih lanjut. \n\n*Pesan ini di kirim secara otomatis, tidak perlu di balas.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
console.log("[Update Active Berhasil]", updateData);
|
console.log("[Update Active Berhasil]", updateData);
|
||||||
} else if (category === "role") {
|
} else if (category === "role") {
|
||||||
const fixName = _.startCase(data.role.replace(/_/g, " "));
|
const fixName = _.startCase(data.role.replace(/_/g, " "));
|
||||||
|
|||||||
@@ -5,8 +5,16 @@ export async function GET(request: Request) {
|
|||||||
try {
|
try {
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const search = searchParams.get("search");
|
const search = searchParams.get("search");
|
||||||
|
const page = Number(searchParams.get("page"));
|
||||||
|
const takeData = 10;
|
||||||
|
const skipData = page * takeData - takeData;
|
||||||
|
|
||||||
|
console.log("SEARCH", search);
|
||||||
|
console.log("PAGE", page);
|
||||||
|
|
||||||
const data = await prisma.user.findMany({
|
const data = await prisma.user.findMany({
|
||||||
|
take: page ? takeData : undefined,
|
||||||
|
skip: page ? skipData : undefined,
|
||||||
orderBy: {
|
orderBy: {
|
||||||
username: "asc",
|
username: "asc",
|
||||||
},
|
},
|
||||||
@@ -43,16 +51,12 @@ export async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json({
|
||||||
{
|
status: 200,
|
||||||
success: true,
|
success: true,
|
||||||
message: "Berhasil mendapatkan data",
|
message: "Berhasil mendapatkan data",
|
||||||
data: data,
|
data: data,
|
||||||
},
|
});
|
||||||
{
|
|
||||||
status: 200,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
@@ -62,7 +66,7 @@ export async function GET(request: Request) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
status: 500,
|
status: 500,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
const sendCodeOtp = async ({
|
const sendCodeOtp = async ({
|
||||||
nomor,
|
nomor,
|
||||||
codeOtp,
|
codeOtp,
|
||||||
|
newMessage,
|
||||||
}: {
|
}: {
|
||||||
nomor: string;
|
nomor: string;
|
||||||
codeOtp: string;
|
codeOtp?: string;
|
||||||
|
newMessage?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const msg = `HIPMI%20-%20Kode%20ini%20bersifat%20RAHASIA%20dan%20JANGAN%20DI%20BAGIKAN%20KEPADA%20SIAPAPUN%2C%20termasuk%20anggota%20ataupun%20pengurus%20HIPMI%20lainnya.%20Kode%20OTP%20anda%3A%20${codeOtp}.`;
|
const msg = newMessage || `HIPMI - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun pengurus HIPMI lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`;
|
||||||
|
const enCode = encodeURIComponent(msg);
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=${nomor}&text=${msg}`,
|
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=${nomor}&text=${enCode}`,
|
||||||
{
|
{
|
||||||
cache: "no-cache",
|
cache: "no-cache",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -25,4 +28,4 @@ const sendCodeOtp = async ({
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { sendCodeOtp };
|
export { sendCodeOtp as funSendToWhatsApp };
|
||||||
|
|||||||
Reference in New Issue
Block a user