Skip to content

Commit

Permalink
Add empresas table
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Alvarenga committed Aug 8, 2024
1 parent e8f4d0f commit 6fd368c
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 3 deletions.
5 changes: 5 additions & 0 deletions client/src/components/admin/AsideDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<p v-if="showPs">Estágios</p>
</router-link>
</li>
<li>
<router-link to="/admin/table/empresa">
<p v-if="showPs">Empresas</p>
</router-link>
</li>
</ul>
<li>
<router-link to="/admin">
Expand Down
9 changes: 9 additions & 0 deletions client/src/router/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import TableFuncionarios from '../../views/admin/TableFuncionario.vue';
import TableProfessores from '../../views/admin/TableProfessor.vue';
import TableTurmas from '../../views/admin/TableTurma.vue';
import TableEstagio from '../../views/admin/TableEstagio.vue';
import TableEmpresas from '../../views/admin/TableEmpresa.vue';

import {
isAuthAdmin
Expand Down Expand Up @@ -118,4 +119,12 @@ export const adminRoutes = [
(await isAuthAdmin()) ? next() : next({path: "/admin/login"});
}
},
{
path: '/admin/table/empresa',
name: 'TableEmpresa',
component: TableEmpresas,
beforeEnter: async (to, from, next) => {
(await isAuthAdmin()) ? next() : next({path: "/admin/login"});
}
},
]
64 changes: 64 additions & 0 deletions client/src/scss/pages/admin/_tableEmpresa.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
main {
height: calc(100vh - 80px);
background-color: $primary-color-dark;
@include flex-center;
}

.path {
width: 100%;
@include flex(row, flex-start, center);

font-size: 0.9rem;
@include font-inter(300);
margin-bottom: 20px;
> p {
@include flex(column, center, center);
@include font-inter(400);

&:after {
width: 100%;
height: 3px;
margin-top: 3px;
background-color: $secondary-color-orange;
}

&:hover::after {
animation: none;
}
}

img {
@include flex(column, center, center);
width: 15px;
transform: rotate(180deg);
filter: invert(100%);
margin-inline: 20px;
}
}

.table {
display: flex;
flex-direction: column;
width: 100%;

.table-header {
border-left: 3px solid $secondary-color-orange;
.table-cell {
@include font-inter(600);
}
}

.table-row {
display: flex;
flex-direction: row;
}

.table-cell {
flex: 1;
padding: 8px;
border-right: 1px solid #ddd;
font-size: 1rem;
@include font-inter(300);
color: $font-color-dark;
}
}
13 changes: 13 additions & 0 deletions client/src/services/api/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,16 @@ export const getFullProfessores = async(token) => {
}
}

export const getFullEmpresas = async(token) => {
try {
const response = await api.get('admin/table/empresas', {
headers: {
authorization: `${token}`
}
});
return response;
} catch (error) {
return error.response.data;
}
}

119 changes: 119 additions & 0 deletions client/src/views/admin/TableEmpresa.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<template>
<Header />
<div id="app">
<main>
<AsideDashboard pageName='home' />
<div class="content">
<div class="path">
<p>Dashboard</p>
<img :src="anguloIcon" alt="">
<p>Tabelas</p>
<img :src="anguloIcon" alt="">
<p>Empresas</p>
</div>
<div class="table">
<div class="table-header">
<div class="table-row">
<div class="table-cell">Empresas Registradas</div>
</div>
</div>
<div class="table-body">
<div class="table-row" v-for="empresa in empresas" :key="empresa.id">
<div class="table-cell">
<p>{{ empresa.name }}</p>
<p>CNPJ: {{ empresa.cnpj }}</p>
<p>Email: {{ empresa.email }}</p>
<p>Registro: {{ formatarData(empresa.createdAt) }}</p>
<p>Apoiadora: {{ empresa.patrocinador }}</p>
<div v-if="(empresa.estagios).length > 0">
<p>{{ (empresa.estagios).length }} estágios:</p>
<ul>
<li v-for="estagio in empresa.estagios" :key="estagio">{{ estagio }}</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
</template>

<script>
import Header from '../../components/Header.vue';
import AsideDashboard from '../../components/admin/AsideDashboard.vue';
import anguloIcon from '../../assets/icons/angulo.png';
import { mixinAdmin } from '../../util/authMixins.js';
import { getFullEmpresas } from '../../services/api/admin';
export default {
name: 'TableEmpresas',
components: {
Header,
AsideDashboard,
},
data() {
return {
anguloIcon,
empresas: [],
}
},
methods: {
async fetchEmpresas() {
const data = await getFullEmpresas(this.admin.token);
this.empresas = data.data;
},
formatarData(data) {
const dataAtual = new Date();
const dataMensagem = new Date(data);
if (dataMensagem.toDateString() === dataAtual.toDateString()) {
return dataMensagem.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
} else {
const diff = Math.floor((dataAtual - dataMensagem) / (1000 * 60 * 60 * 24));
if (diff === 1) {
return `Ontem, ${dataMensagem.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`;
} else if (diff <= 7) {
return `${dataMensagem.toLocaleDateString('pt-BR', { weekday: 'long' })}, ${dataMensagem.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`;
} else {
return dataMensagem.toLocaleString();
}
}
}
},
mixins: [mixinAdmin],
async created() {
this.getToken();
await this.fetchEmpresas();
}
}
</script>

<style lang="scss" scoped>
@import "../../scss/pages/admin/_tableEmpresa.scss";
#app {
display: flex;
flex-direction: column;
min-height: calc(100vh - 80px);
main {
display: flex;
overflow: hidden;
.content {
flex: 1;
padding: 20px;
overflow-y: auto;
height: 100%;
@media (max-width: 1000px) {
width: calc(100% - 100px);
}
}
}
}
</style>
12 changes: 12 additions & 0 deletions server/src/modules/controllers/adminControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { GetFullCursosUseCase } from "../services/admin/Get/Cursos";
import { GetCoordenadorUseCase } from "../services/admin/Get/Coordenadores";
import { GetAllProfessoresNamesUseCase } from "../services/admin/Get/ProfessorNames";
import { GetCoordenadoresNamesUseCase } from "../services/admin/Get/CoordenasdoresNames";
import { GetEmpresasWithEstagiosUseCase } from "../services/admin/Get/Empresas";

export class GetAllProfessoresController {
async handle(req: Request, res: Response) {
Expand Down Expand Up @@ -183,6 +184,17 @@ export class GetFullCursosController {

const result = await getFullCursosUseCase.execute();

return res.status(201).json(result);
}
}

export class GetFullEmpresasController {
async handle(req: Request, res: Response) {

const getEmpresasWithEstagiosUseCase = new GetEmpresasWithEstagiosUseCase();

const result = await getEmpresasWithEstagiosUseCase.execute();

return res.status(201).json(result);
}
}
24 changes: 24 additions & 0 deletions server/src/modules/services/admin/Get/Empresas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { prisma } from "../../../../prisma/client";

interface EmpresaWithEstagios {
id: string;
name: string;
estagios: string[];
}

export class GetEmpresasWithEstagiosUseCase {
async execute(): Promise<EmpresaWithEstagios[]> {
const empresas = await prisma.empresa.findMany({
include: {
vaga: true,
},
});

const empresasWithEstagios: EmpresaWithEstagios[] = empresas.map((empresa) => ({
...empresa,
estagios: empresa.vaga.map((vaga) => vaga.titulo),
}));

return empresasWithEstagios;
}
}
1 change: 1 addition & 0 deletions server/src/router/routes/admin.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ adminRoutes.get("/table/cursos", controllers.getFullCursosController.handle);
adminRoutes.get("/table/estagios", controllers.getFullEstagiosController.handle);
adminRoutes.get("/table/funcionarios", controllers.getFullFuncionariosController.handle);
adminRoutes.get("/table/turmas", controllers.getFullTurmasController.handle);
adminRoutes.get("/table/empresas", controllers.getFullEmpresasController.handle);

export { adminRoutes };
7 changes: 4 additions & 3 deletions server/src/router/routes/imports/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
GetFullCursosController,
GetFullEstagiosController,
GetFullFuncionariosController,
GetFullTurmasController
GetFullTurmasController,
GetFullEmpresasController
} from "../../../modules/controllers/adminControllers";

export const createControllers = () => ({
Expand All @@ -35,6 +36,6 @@ export const createControllers = () => ({
getFullCursosController: new GetFullCursosController(),
getFullEstagiosController: new GetFullEstagiosController(),
getFullFuncionariosController: new GetFullFuncionariosController(),
getFullTurmasController: new GetFullTurmasController()

getFullTurmasController: new GetFullTurmasController(),
getFullEmpresasController: new GetFullEmpresasController(),
});

0 comments on commit 6fd368c

Please sign in to comment.