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 backendLogger from "@/util/backendLogger";
|
||||
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) {
|
||||
if (req.method !== "POST") {
|
||||
@@ -30,7 +30,7 @@ export async function POST(req: Request) {
|
||||
{ status: 400 },
|
||||
);
|
||||
|
||||
const resSendCode = await sendCodeOtp({
|
||||
const resSendCode = await funSendToWhatsApp({
|
||||
nomor,
|
||||
codeOtp: codeOtp.toString(),
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
||||
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) {
|
||||
try {
|
||||
@@ -35,7 +35,7 @@ export async function POST(req: Request) {
|
||||
{ status: 400 },
|
||||
);
|
||||
|
||||
const resSendCode = await sendCodeOtp({
|
||||
const resSendCode = await funSendToWhatsApp({
|
||||
nomor,
|
||||
codeOtp: codeOtp.toString(),
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} 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) {
|
||||
if (req.method !== "POST") {
|
||||
@@ -70,7 +70,7 @@ export async function POST(req: Request) {
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
const resSendCode = await sendCodeOtp({
|
||||
const resSendCode = await funSendToWhatsApp({
|
||||
nomor: data.nomor,
|
||||
codeOtp: codeOtp.toString(),
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import { prisma } from "@/lib";
|
||||
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
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) {
|
||||
if (req.method !== "POST") {
|
||||
@@ -17,7 +17,7 @@ export async function POST(req: Request) {
|
||||
const body = await req.json();
|
||||
const { nomor } = body;
|
||||
|
||||
const resSendCode = await sendCodeOtp({
|
||||
const resSendCode = await funSendToWhatsApp({
|
||||
nomor,
|
||||
codeOtp: codeOtp.toString(),
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { funSendToWhatsApp } from "@/lib/code-otp-sender";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
@@ -50,8 +51,25 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
data: {
|
||||
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);
|
||||
} else if (category === "role") {
|
||||
const fixName = _.startCase(data.role.replace(/_/g, " "));
|
||||
|
||||
@@ -5,8 +5,16 @@ export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
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({
|
||||
take: page ? takeData : undefined,
|
||||
skip: page ? skipData : undefined,
|
||||
orderBy: {
|
||||
username: "asc",
|
||||
},
|
||||
@@ -43,16 +51,12 @@ export async function GET(request: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: data,
|
||||
},
|
||||
{
|
||||
status: 200,
|
||||
}
|
||||
);
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
@@ -62,7 +66,7 @@ export async function GET(request: Request) {
|
||||
},
|
||||
{
|
||||
status: 500,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
const sendCodeOtp = async ({
|
||||
nomor,
|
||||
codeOtp,
|
||||
newMessage,
|
||||
}: {
|
||||
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(
|
||||
`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",
|
||||
headers: {
|
||||
@@ -25,4 +28,4 @@ const sendCodeOtp = async ({
|
||||
return res;
|
||||
};
|
||||
|
||||
export { sendCodeOtp };
|
||||
export { sendCodeOtp as funSendToWhatsApp };
|
||||
|
||||
Reference in New Issue
Block a user