# fix
- PC: Loader chat - QC: Auth , Profile, portofolio & user search ## No Issuue git commit -m
This commit is contained in:
65
src/app_modules/colab/fun/chat/get_message_by_room_id.ts
Normal file
65
src/app_modules/colab/fun/chat/get_message_by_room_id.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import _, { ceil } from "lodash";
|
||||
|
||||
export default async function colab_V2getListMessageByRoomId({
|
||||
roomId,
|
||||
page,
|
||||
}: {
|
||||
roomId: string;
|
||||
page: number;
|
||||
}) {
|
||||
// console.log(page);
|
||||
|
||||
const lewat = page * 6 - 6;
|
||||
const ambil = 6;
|
||||
|
||||
const awal = await prisma.projectCollaboration_Message.count({
|
||||
where: {
|
||||
isActive: true,
|
||||
User: {
|
||||
active: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const getData = await prisma.projectCollaboration_Message.findMany({
|
||||
skip: lewat,
|
||||
take: ambil,
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
isActive: true,
|
||||
User: {
|
||||
active: true,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
createdAt: true,
|
||||
isActive: true,
|
||||
message: true,
|
||||
isFile: true,
|
||||
User: {
|
||||
select: {
|
||||
id: true,
|
||||
Profile: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
userId: true,
|
||||
},
|
||||
});
|
||||
|
||||
const allData = {
|
||||
data: _.reverse(getData),
|
||||
nPage: ceil(awal / ambil),
|
||||
};
|
||||
|
||||
return allData;
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterColab } from "@/app/lib/router_hipmi/router_colab";
|
||||
import { user_getOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export default async function colab_funCreateMessageByUserId(
|
||||
message: string,
|
||||
@@ -14,8 +16,28 @@ export default async function colab_funCreateMessageByUserId(
|
||||
message: message,
|
||||
projectCollaboration_RoomChatId: roomId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
createdAt: true,
|
||||
isActive: true,
|
||||
message: true,
|
||||
isFile: true,
|
||||
User: {
|
||||
select: {
|
||||
id: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!msg) return { status: 400, message: "Pesan Gagal Dikirim" };
|
||||
return { status: 200, message: "Pesan Berhasil Dikirim" };
|
||||
revalidatePath(RouterColab.group_chat + roomId);
|
||||
|
||||
return { data: msg, status: 200, message: "Pesan Berhasil Dikirim" };
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterColab } from "@/app/lib/router_hipmi/router_colab";
|
||||
import _ from "lodash";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export default async function colab_getMessageByRoomId({
|
||||
roomId,
|
||||
@@ -10,8 +12,9 @@ export default async function colab_getMessageByRoomId({
|
||||
roomId: string;
|
||||
page: number;
|
||||
}) {
|
||||
const lewat = page * 6 - 6;
|
||||
const ambil = 6;
|
||||
const lewat = page * 10 - 10;
|
||||
const ambil = 10;
|
||||
|
||||
const getList = await prisma.projectCollaboration_Message.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
@@ -41,8 +44,7 @@ export default async function colab_getMessageByRoomId({
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
const reverse = _.reverse(getList)
|
||||
const reverse = _.reverse(getList);
|
||||
|
||||
return reverse;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function colab_getOneMessageById({
|
||||
messageId,
|
||||
}: {
|
||||
messageId: string;
|
||||
}) {
|
||||
// console.log(messageId);
|
||||
const getOne = await prisma.projectCollaboration_Message.findFirst({
|
||||
where: {
|
||||
id: messageId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
createdAt: true,
|
||||
isActive: true,
|
||||
message: true,
|
||||
isFile: true,
|
||||
User: {
|
||||
select: {
|
||||
id: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return getOne;
|
||||
}
|
||||
Reference in New Issue
Block a user