Skip to content

Commit

Permalink
feat: employee profile
Browse files Browse the repository at this point in the history
  • Loading branch information
bineenasc committed Dec 30, 2024
1 parent 72fdd13 commit 8233469
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 59 deletions.
3 changes: 1 addition & 2 deletions api/.aeria/aeria-sdk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ declare type MirrorDescriptions = {
"format": "date-time"
},
"collection_date": {
"type": "string",
"format": "date-time"
"type": "boolean"
},
"created_at": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion api/schemas/main.aeria
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ collection EquipmentRelease {
delivered_to Employee @populate([name, corporate_email, contact, is_active, picture_file, admission_date, exit_date])
delivered_by User @populate([name, email])
allocation_date str @format("date-time")
collection_date str @format("date-time")
collection_date bool
}
functions {
get @expose(true)
Expand Down
51 changes: 51 additions & 0 deletions api/src/routes/equipmentsBorrowoed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { createRouter, HTTPStatus, Result } from "aeria";
export const equipmentRouter = createRouter();

equipmentRouter.POST(
"/getEquipmentsBorrowoedByUser",
async (context) => {
const employeeId = context.token?.sub;

if (!employeeId) {
return context.error(HTTPStatus.NotFound, { code: "USER_ID_NOT_FOUND" });
}

try {
// Simulação de dados emprestados armazenados na coleção EquipmentRelease
const borrowedEquipments = await context.collections.equipmentRelease.model.aggregate([
{
$match: { "delivered_to._id": employeeId }, // Filtra lançamentos pelo ID do funcionário
},
{
$project: {
equipments: {
$reduce: {
input: "$equipments", // Campo contendo os equipamentos
initialValue: [],
in: { $concatArrays: ["$$value", "$$this"] },
},
},
},
},
]).toArray();

if (!borrowedEquipments || borrowedEquipments.length === 0) {
return context.error(HTTPStatus.NotFound, { code: "NO_EQUIPMENTS_FOUND" });
}

return Result.result(borrowedEquipments);
} catch (error) {
return context.error(HTTPStatus.InternalServerError, {
code: "ERROR_FETCHING_EQUIPMENTS",
message: "An unexpected error occurred",
});
}
},
{
roles: true,
payload: {
type: "object",
properties: {},
},
}
);
3 changes: 1 addition & 2 deletions web/.aeria-ui/aeria-sdk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ declare type MirrorDescriptions = {
"format": "date-time"
},
"collection_date": {
"type": "string",
"format": "date-time"
"type": "boolean"
},
"created_at": {
"type": "string",
Expand Down
75 changes: 47 additions & 28 deletions web/src/pages/dashboard/equipmentRelease-[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,37 @@ type Props = {
onMounted(async () => {
const { error: employeeError, result: employeeResult } = await aeria.employee.get.POST({
filters: {
_id: employeeProps.id
}
})
_id: employeeProps.id,
},
});
if (employeeError) {
return
return;
}
employee.value = employeeResult
employee.value = employeeResult;
const { error: equipmentReleaseError, result: equipmentReleaseResult } = await aeria.equipmentRelease.getAll.POST({
filters: {
delivered_to: employeeProps.id,
}
})
},
});
if (equipmentReleaseError) {
return
return;
}
equipments.value = equipmentReleaseResult.data
})
equipments.value = equipmentReleaseResult.data.flatMap((item: any) =>
item.equipments.map((equipment: any) => ({
name: equipment.name,
code: equipment.code,
allocation_date: item.allocation_date,
collection_date: item.collection_date,
}))
);
});
</script>

<template>

<div v-if="employee && equipments">
<div
class="tw-bg-[color:var(--theme-background-color-shade-5)] tw-shadow tw-rounded-lg tw-mx-auto tw-p-4 tw-flex tw-flex-col tw-space-y-4">
Expand All @@ -59,14 +67,27 @@ onMounted(async () => {
<!-- Informações principais -->
<div>
<p class="tw-font-bold">Nome: {{ employee.name }}</p>
<p>Email corporativo: [email protected]</p>
<p>Telefone Pessoal: 3443434343</p>
<p>Email corporativo: {{ employee.corporate_email }}</p>
<p>Telefone Pessoal: {{ employee.contact }}</p>
</div>
<!-- Status -->
<div>
<p>Status do Funcionário: <span class="tw-font-bold">Ativo ou Desativado</span></p>
<p>Data de Admissão: <span class="tw-font-bold">23/03/2033</span></p>
<p>Data de Demissão: <span class="tw-font-bold">23/03/2023</span></p>
<div v-if="employee.is_active == true">
<p>Status do Funcionário:
<span class="tw-font-bold">Ativo</span>
<p>Data de Admissão: <span class="tw-font-bold">{{
formatDateTime(employee.admission_date) }}</span></p>
</p>
</div>
<div v-else>
<p>Status do Funcionário:
<span class="tw-font-bold">Inativo</span>
<p>Data de Admissão: <span class="tw-font-bold">{{
formatDateTime(employee.admission_date) }}</span></p>
<p>Data de Demissão: <span class="tw-font-bold">{{ formatDateTime(employee.exit_date)
}}</span></p>
</p>
</div>
</div>
</div>
</div>
Expand All @@ -84,21 +105,19 @@ onMounted(async () => {
</tr>
</thead>
<tbody>
<tr class="tw-border-b tw-border-gray-700">
<td class="tw-py-2 tw-px-4">Notebook Nitro AN515-58</td>
<td class="tw-py-2 tw-px-4">000552</td>
<td class="tw-py-2 tw-px-4">22/12/2024</td>
<td class="tw-py-2 tw-px-4">23/12/2024</td>
</tr>
<tr>
<td class="tw-py-2 tw-px-4">Monitor Acer 324242</td>
<td class="tw-py-2 tw-px-4">034500</td>
<td class="tw-py-2 tw-px-4">11/12/2024</td>
<td class="tw-py-2 tw-px-4">Não recolhido</td>
<tr v-for="equipment in equipments" :key="equipment._id"
class="tw-border-b tw-border-gray-700">
<td class="tw-py-2 tw-px-4">{{ equipment.name }}</td>
<td class="tw-py-2 tw-px-4">{{ equipment.code }}</td>
<td class="tw-py-2 tw-px-4">{{ formatDateTime(equipment.allocation_date) }}</td>
<td class="tw-py-2 tw-px-4">
<span v-if="!equipment.collection_date">Não Recolhido</span>
<span v-else>{{ formatDateTime(equipment.collection_date) }}</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
</template>
31 changes: 5 additions & 26 deletions web/src/pages/dashboard/equipmentRelease.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,6 @@ const navigateToEquipment = (id: string) => {
router.push(`/dashboard/equipmentRelease-${id}`);
};
onMounted(async () => {
const { error: employeeError, result: employeeResult } = await aeria().employee.get.POST({
filters: {
_id: employeeProps.id
}
})
if (employeeError) {
return
}
employee.value = employeeResult
const { error: equipmentReleaseError, result: equipmentReleaseResult } = await aeria().equipmentRelease.getAll.POST({
filters: {
delivered_to: employeeProps.id,
}
})
if (equipmentReleaseError) {
return
}
equipments.value = equipmentReleaseResult.data
})
</script>

<template>
Expand All @@ -53,18 +32,18 @@ onMounted(async () => {
<template #row-delivered_to="{ row, column }">
<div class="tw-flex tw-flex-col tw-gap-1">
<div class="tw-cursor-pointer linked-text tw-w-min tw-whitespace-pre tw-flex "
@click="navigateToEquipment(row._id)" v-if="row[column]?.is_active == true">
@click="navigateToEquipment(row.delivered_to._id)" v-if="row[column]?.is_active == true">
<aeria-icon icon="check-circle" style="--icon-color: green; --icon-size: 1.2rem;"
class="tw-text-[12pt]">{{ row[column]?.name || "-" }}
</aeria-icon>
</div>
</aeria-icon>
</div>
<div class="tw-cursor-pointer linked-text tw-w-min tw-whitespace-pre"
@click="navigateToEquipment(row._id)" v-else>
@click="navigateToEquipment(row.delivered_to._id)" v-else>
<aeria-icon icon="x-circle" style="--icon-color: red; --icon-size: 1.2rem;"
class="tw-text-[12pt]">{{ row[column]?.name || "-" }}
</aeria-icon>
</div>
<div class="tw-text-[10pt] tw-opacity-60 tw-cursor-pointer linked-text" @click="navigateToEquipment(row._id)">
<div class="tw-text-[10pt] tw-opacity-60 tw-cursor-pointer linked-text" @click="navigateToEquipment(row.delivered_to._id)">
{{ row[column]?.contact || "-" }} -
{{ row[column]?.corporate_email }}
</div>
Expand Down

0 comments on commit 8233469

Please sign in to comment.