Skip to content

Commit

Permalink
fix: employee profile
Browse files Browse the repository at this point in the history
  • Loading branch information
bineenasc committed Dec 30, 2024
1 parent 8233469 commit 72b676c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 61 deletions.
37 changes: 37 additions & 0 deletions api/src/routes/EquipmentsBorrowoedByUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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" });
}

// Simulação de dados emprestados armazenados na coleção EquipmentRelease
const borrowedEquipments = await context.collections.equipmentRelease.model.aggregate([
{
$match: { delivered_to: employeeId },
},
{
$project: {
equipments: {
$reduce: {
input: "$equipments",
initialValue: [],
in: { $concatArrays: ["$$value", "$$this"] },
},
},
},
},
]).toArray();

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

return Result.result(borrowedEquipments);
}
);
51 changes: 0 additions & 51 deletions api/src/routes/equipmentsBorrowoed.ts

This file was deleted.

14 changes: 4 additions & 10 deletions web/src/pages/dashboard/equipmentRelease-[id].vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="ts">
import { type CollectionItemWithId } from '@aeriajs/types';
import { ref, onMounted } from 'vue';
definePage({
props: true,
Expand All @@ -11,6 +13,8 @@ const employeeProps = defineProps<Props>()
const employee = ref({} as CollectionItemWithId<'employee'>)
const equipments = ref<CollectionItemWithId<'equipmentRelease'>[]>([])
const { error, result } = await aeria().getEquipmentsBorrowedByUser()
type Props = {
id: String
}
Expand All @@ -34,16 +38,6 @@ onMounted(async () => {
if (equipmentReleaseError) {
return;
}
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>
Expand Down

0 comments on commit 72b676c

Please sign in to comment.