ÿØÿà JFIF ` ` ÿþ
|
Server : Apache System : Linux cloud.heroica.com.br 4.18.0-553.36.1.el8_10.x86_64 #1 SMP Wed Jan 22 03:07:54 EST 2025 x86_64 User : farolpborg ( 1053) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /var/www/node_services/sebraevisitas/src/services/ |
Upload File : |
import prisma from "../prisma";
import convertDdMmYyyyToDate from "../utils/conversors/convertdate";
type ListFilters = {
startDate?: string;
endDate?: string;
agentId?: string;
userId?: string;
};
const VisitaServices = class VisitaServices {
static async create(data: any) {
return prisma.visita.create({ data });
}
static async list(filters?: ListFilters) {
const where: any = {};
// Agent filter (userId)
const agent = filters?.agentId || filters?.userId;
if (agent) where.userId = agent;
// Date filters on createdAt
function parseDate(value?: string): Date | undefined {
if (!value) return undefined;
let d: Date;
if (value.includes("/")) {
d = convertDdMmYyyyToDate(value);
} else {
d = new Date(value);
}
return isNaN(d.getTime()) ? undefined : d;
}
const start = parseDate(filters?.startDate);
const end = parseDate(filters?.endDate);
if (start || end) {
where.createdAt = {};
if (start) {
const s = new Date(start);
s.setHours(0, 0, 0, 0);
where.createdAt.gte = s;
}
if (end) {
const e = new Date(end);
e.setHours(23, 59, 59, 999);
where.createdAt.lte = e;
}
}
return prisma.checkinvisita.findMany({
where,
orderBy: { createdAt: "desc" },
include:{
cadastropf:true,
cadastropj:true,
entrevistaDiagnostico:true,
planoacao:true,
assinaturadigital:true,
checkout:true,
recordings:{
select:{
id:true
}
}
}
});
}
static async getById(id: string) {
return prisma.visita.findUnique({ where: { id } });
}
static async update(id: string, data: any) {
return prisma.visita.update({ where: { id }, data });
}
static async remove(id: string) {
await prisma.visita.delete({ where: { id } });
return { success: true };
}
static async getRecordingById(id: string) {
return prisma.recordings.findUnique({ where: { id } });
}
};
export default VisitaServices;