123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import prisma from '../../prisma/PrismaClient';
- import { Prisma } from '@prisma/client';
- import { ScheduleVisitationDTO } from '../../types/admin/schedule_visitation/ScheduleVisitationDTO';
- interface FindAllParams {
- skip: number;
- take: number;
- where?: Prisma.ScheduleVisitationWhereInput;
- orderBy?: Prisma.ScheduleVisitationOrderByWithRelationInput;
- }
- const ScheduleVisitationRepository = {
- findAll: async ({ skip, take, where, orderBy }: FindAllParams) => {
- return prisma.scheduleVisitation.findMany({
- where,
- skip,
- take,
- orderBy,
- include: {
- hospital: {
- select: {
- id: true,
- name: true,
- hospital_code: true,
- type: true,
- ownership: true,
- address: true,
- contact: true,
- email: true,
- image: true,
- progress_status: true,
- note: true,
- latitude: true,
- longitude: true,
- gmaps_url: true,
- province: {
- select: {
- id: true,
- name: true,
- },
- },
- city: {
- select: {
- id: true,
- name: true,
- },
- },
- }
- },
- user_created: { select: { id: true, fullname: true } },
- sales_visit: { select: { id: true, fullname: true } },
- },
- });
- },
- countAll: async (where?: Prisma.ScheduleVisitationWhereInput) => {
- return prisma.scheduleVisitation.count({ where });
- },
- findById: async (id: string) => {
- return await prisma.scheduleVisitation.findFirst({
- where: { id, deletedAt: null },
- select: {
- id: true,
- date_visit: true,
- notes: true,
- hospital: {
- select: {
- id: true,
- name: true,
- hospital_code: true,
- type: true,
- ownership: true,
- address: true,
- contact: true,
- email: true,
- image: true,
- progress_status: true,
- note: true,
- latitude: true,
- longitude: true,
- gmaps_url: true,
- province: {
- select: {
- id: true,
- name: true,
- },
- },
- city: {
- select: {
- id: true,
- name: true,
- },
- },
- vendor_experiences: {
- where: {
- // status: "active",
- deletedAt: null
- },
- select: {
- id: true,
- vendor: {
- select: { id: true, name: true }
- },
- category: {
- select: { id: true, name: true }
- },
- user: {
- select: { id: true, fullname: true }
- },
- content: true
- // contract_start_date: true,
- // contract_expired_date: true,
- // simrs_type: true,
- }
- },
- executives_histories: {
- where: { status: "active", deletedAt: null },
- select: {
- id: true,
- executive_name: true,
- contact: true,
- start_term: true,
- end_term: true,
- }
- }
- },
- },
- user_created: { select: { id: true, fullname: true } },
- sales_visit: { select: { id: true, fullname: true } },
- createdAt: true,
- updatedAt: true,
- },
- });
- },
- create: async (data: Prisma.ScheduleVisitationCreateInput) => {
- return prisma.scheduleVisitation.create({ data });
- },
- update: async (id: string, data: Prisma.ScheduleVisitationUpdateInput) => {
- return prisma.scheduleVisitation.update({
- where: { id },
- data,
- });
- },
- };
- export default ScheduleVisitationRepository;
|