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 41bc250 commit f1abf8c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
3 changes: 3 additions & 0 deletions api/.aeria/aeria-sdk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ declare type MirrorRouter = {
"root"
]
}
},
"/equipmentEmployee/getEquipmentsBorrowedByUser": {
"POST": null
}
}

Expand Down
18 changes: 18 additions & 0 deletions api/contracts/getEquipmentsBorrowedByUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineContract, endpointErrorSchema, HTTPStatus, resultSchema } from "aeria";

export const getEquipmentBorrowedByUserContract = defineContract({
response: [
endpointErrorSchema({
httpStatus: [HTTPStatus.NotFound],
code: ["NO_EQUIPMENTS_FOUND"]
})
],
resultSchema: {
type: "object",
properties: {
equipmentsArray: {
$ref: 'asset'
}
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createRouter, HTTPStatus, Result } from "aeria";
export const equipmentRouter = createRouter();

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

Expand All @@ -13,18 +13,28 @@ equipmentRouter.POST(
// Simulação de dados emprestados armazenados na coleção EquipmentRelease
const borrowedEquipments = await context.collections.equipmentRelease.model.aggregate([
{
$match: { delivered_to: employeeId },
$match: {
delivered_to: employeeId
}
},
{
$lookup: {
from: 'asset',
localField: 'equipments',
foreignField: '_id',
as: 'equipmentsArray'
}
},
{
$unwind: {
path: '$equipmentsArray'
}
},
{
$project: {
equipments: {
$reduce: {
input: "$equipments",
initialValue: [],
in: { $concatArrays: ["$$value", "$$this"] },
},
},
},
_id: 0,
equipmentsArray: 1
}
},
]).toArray();

Expand Down
5 changes: 2 additions & 3 deletions api/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createRouter } from 'aeria'
import { equipmentRouter } from './EquipmentsBorrowoedByUser.js'
import { equipmentRouter } from './EquipmentsBorrowedByUser.js'

export const router = createRouter()
router.group('/getEquipmentsBorrowoedByUser', equipmentRouter)

router.group('/equipmentEmployee', equipmentRouter)
3 changes: 3 additions & 0 deletions web/.aeria-ui/aeria-sdk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ declare type MirrorRouter = {
"root"
]
}
},
"/equipmentEmployee/getEquipmentsBorrowedByUser": {
"POST": null
}
}

Expand Down
8 changes: 5 additions & 3 deletions web/src/pages/dashboard/equipmentRelease-[id].vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { type CollectionItemWithId } from '@aeriajs/types';
import { ref, onMounted } from 'vue';
import EquipmentRelease from './equipmentRelease.vue';
definePage({
Expand All @@ -13,7 +14,7 @@ const employeeProps = defineProps<Props>()
const employee = ref({} as CollectionItemWithId<'employee'>)
const equipments = ref<CollectionItemWithId<'equipmentRelease'>[]>([])
const { error, result } = await aeria().equipmentRelease.
const { error, result } = await aeria().equipmentEmployee.getEquipmentsBorrowedByUser.POST()
type Props = {
id: String
Expand All @@ -38,6 +39,8 @@ onMounted(async () => {
if (equipmentReleaseError) {
return;
}
EquipmentRelease.value = equipmentReleaseResult;
});
</script>
Expand Down Expand Up @@ -99,8 +102,7 @@ onMounted(async () => {
</tr>
</thead>
<tbody>
<tr v-for="equipment in equipments" :key="equipment._id"
class="tw-border-b tw-border-gray-700">
<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>
Expand Down

0 comments on commit f1abf8c

Please sign in to comment.