Merge pull request 'amalia/21-agustus-25' (#16) from amalia/21-agustus-25 into join
Reviewed-on: bip/sistem-desa-mandiri#16
This commit is contained in:
@@ -212,6 +212,36 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
})
|
||||
}
|
||||
|
||||
// const cek progress
|
||||
const dataTask = await prisma.projectTask.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idProject: id,
|
||||
}
|
||||
})
|
||||
|
||||
const semua = dataTask.length
|
||||
const selesai = dataTask.filter((item) => item.status == 1).length
|
||||
const prosess = Math.ceil((selesai / semua) * 100)
|
||||
let statusProject = 1
|
||||
|
||||
if (prosess == 100) {
|
||||
statusProject = 2
|
||||
} else if (prosess == 0) {
|
||||
statusProject = 0
|
||||
}
|
||||
|
||||
|
||||
const update = await prisma.project.update({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
data: {
|
||||
status: statusProject
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User membuat data tahapan kegiatan', table: 'projectTask', data: String(dataCreate.id), user: userMobile.id })
|
||||
|
||||
|
||||
@@ -206,6 +206,36 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
})
|
||||
}
|
||||
|
||||
// const cek progress
|
||||
const dataTask = await prisma.projectTask.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idProject: id,
|
||||
}
|
||||
})
|
||||
|
||||
const semua = dataTask.length
|
||||
const selesai = dataTask.filter((item) => item.status == 1).length
|
||||
const prosess = Math.ceil((selesai / semua) * 100)
|
||||
let statusProject = 1
|
||||
|
||||
if (prosess == 100) {
|
||||
statusProject = 2
|
||||
} else if (prosess == 0) {
|
||||
statusProject = 0
|
||||
}
|
||||
|
||||
|
||||
const update = await prisma.project.update({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
data: {
|
||||
status: statusProject
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// create log user
|
||||
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data tahapan kegiatan', table: 'projectTask', data: String(dataCreate.id) })
|
||||
|
||||
|
||||
26
xsendMany.ts
26
xsendMany.ts
@@ -22,7 +22,7 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
||||
title,
|
||||
body,
|
||||
},
|
||||
tokens:token,
|
||||
tokens: token,
|
||||
data,
|
||||
android: {
|
||||
priority: "high",
|
||||
@@ -44,18 +44,22 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
||||
},
|
||||
};
|
||||
|
||||
// Kirim pesan
|
||||
const response = await getMessaging().sendEachForMulticast(message as any);
|
||||
if (response.failureCount > 0) {
|
||||
const failedTokens: any[] = [];
|
||||
response.responses.forEach((resp, idx) => {
|
||||
if (!resp.success) {
|
||||
failedTokens.push(token[idx]);
|
||||
}
|
||||
});
|
||||
const del = await deleteDeviceError({ device: failedTokens });
|
||||
if (token.length > 0) {
|
||||
// Kirim pesan
|
||||
const response = await getMessaging().sendEachForMulticast(message as any);
|
||||
if (response.failureCount > 0) {
|
||||
const failedTokens: any[] = [];
|
||||
response.responses.forEach((resp, idx) => {
|
||||
if (!resp.success) {
|
||||
failedTokens.push(token[idx]);
|
||||
}
|
||||
});
|
||||
const del = await deleteDeviceError({ device: failedTokens });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return { success: true, message: "Notifikasi berhasil dikirim", };
|
||||
} catch (error) {
|
||||
console.error("Error mengirim notifikasi:", error);
|
||||
|
||||
Reference in New Issue
Block a user