The-Bugger-Ducks / owl-partners-back

API do projeto "Owl Partners" (5º DSM - 2023, FATEC Profº Jessen Vidal - SJC)
https://owlpartners.onrender.com/api
2 stars 0 forks source link

[#0613] Listagem de reuniões na tela de detalhes da parceria #33

Closed drisabelles closed 1 year ago

drisabelles commented 1 year ago

📄 Descrição da atividade

Na aba "Reuniões" da tela de parcerias deve ser exibida a listagem de reuniões da parceria ordenada pela data mais recente para mais antiga.

🛠 Protótipo

Image

🚀 Etapas do desenvolvimento

DoR: Definition of Ready

Critérios de aceite

DoD: Definition of Done

gioliveirass commented 1 year ago

@GabrielCamargoL protótipo atualizado de acordo com o que conversamos na sexta dia 04/04

GabrielCamargoL commented 1 year ago

Documentação

Tecnologias

NestJS, Prisma, PostgresSQL, Insomnia, VSCODE, beekeeper Studio portable

Listagem de Reuniões

image


URL: domain.api.com.br/meetings URL: domain.api.com.br/meetings/partner/:id Method: GET

@Get()
    @UseGuards(AuthGuard('jwt'))
    async meetings() {
        return this.meetingService.findAll();
    }

    @Get('partner/:partnerId')
    @UseGuards(AuthGuard('jwt'))
    async meetingsByPartner(@Param('partnerId') partnerId: string) {
        return this.meetingService.findByPartnerId(partnerId);
    }
    async findAll() {
        const upcomingMeetings = await this.prismaService.meeting.findMany({
            select: {
                id: true,
                title: true,
                description: true,
                meetingDateTime: true,
                Partner: {
                    select: {
                        id: true,
                        name: true,
                    }
                }
            },
            where: {
                meetingDateTime: {
                    gt: getCurrentBrDateTimeISO()
                }
            },
            orderBy: { meetingDateTime: 'asc' }
        });

        const pastMeetings = await this.prismaService.meeting.findMany({
            select: {
                id: true,
                title: true,
                description: true,
                meetingDateTime: true,
                Partner: {
                    select: {
                        id: true,
                        name: true,
                    }
                }
            },
            where: {
                meetingDateTime: {
                    lt: getCurrentBrDateTimeISO()
                }
            },
            orderBy: { meetingDateTime: 'asc' }
        });

        return { upcomingMeetings, pastMeetings }
    }

função de comparação de datas para separação entre reuniões futuras e passadas:

export function getCurrentBrDateTimeISO(): string {
    const now = new Date()
    const offset = -180 // offset em minutos (-180 equivale a -3 horas, ou seja, horário de Brasília)
    const localTimestamp = now.getTime() + offset * 60 * 1000 // adiciona o offset em milissegundos

    const localDate = new Date(localTimestamp)
    const formattedDate = localDate.toISOString()

    console.log(formattedDate);

    return formattedDate
}
gioliveirass commented 1 year ago

@GabrielCamargoL @drisabelles showww