diff --git a/api/.aeria/aeria-sdk.d.ts b/api/.aeria/aeria-sdk.d.ts index c9c16c4..cd34936 100644 --- a/api/.aeria/aeria-sdk.d.ts +++ b/api/.aeria/aeria-sdk.d.ts @@ -873,6 +873,9 @@ declare type MirrorRouter = { "root" ] } + }, + "/equipmentEmployee/getEquipmentsBorrowedByUser": { + "POST": null } } diff --git a/api/contracts/getEquipmentsBorrowedByUser.ts b/api/contracts/getEquipmentsBorrowedByUser.ts new file mode 100644 index 0000000..1dd04b0 --- /dev/null +++ b/api/contracts/getEquipmentsBorrowedByUser.ts @@ -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' + } + } + } +}); diff --git a/api/src/routes/EquipmentsBorrowoedByUser.ts b/api/src/routes/EquipmentsBorrowedByUser.ts similarity index 59% rename from api/src/routes/EquipmentsBorrowoedByUser.ts rename to api/src/routes/EquipmentsBorrowedByUser.ts index 41edd08..a18f522 100644 --- a/api/src/routes/EquipmentsBorrowoedByUser.ts +++ b/api/src/routes/EquipmentsBorrowedByUser.ts @@ -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; @@ -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(); diff --git a/api/src/routes/index.ts b/api/src/routes/index.ts index fead532..c0f828d 100644 --- a/api/src/routes/index.ts +++ b/api/src/routes/index.ts @@ -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) \ No newline at end of file diff --git a/web/.aeria-ui/aeria-sdk.d.ts b/web/.aeria-ui/aeria-sdk.d.ts index c9c16c4..cd34936 100644 --- a/web/.aeria-ui/aeria-sdk.d.ts +++ b/web/.aeria-ui/aeria-sdk.d.ts @@ -873,6 +873,9 @@ declare type MirrorRouter = { "root" ] } + }, + "/equipmentEmployee/getEquipmentsBorrowedByUser": { + "POST": null } } diff --git a/web/src/pages/dashboard/equipmentRelease-[id].vue b/web/src/pages/dashboard/equipmentRelease-[id].vue index 625bb20..dc7d825 100644 --- a/web/src/pages/dashboard/equipmentRelease-[id].vue +++ b/web/src/pages/dashboard/equipmentRelease-[id].vue @@ -1,6 +1,7 @@ @@ -99,8 +102,7 @@ onMounted(async () => {
-