Skip to content

Commit

Permalink
refactor: add contract to getEquipmentBorrowedByUser and fixes on equ…
Browse files Browse the repository at this point in the history
…ipmentRelease view
  • Loading branch information
Cephas369 committed Dec 30, 2024
1 parent f1abf8c commit f4a39d1
Show file tree
Hide file tree
Showing 17 changed files with 452 additions and 236 deletions.
18 changes: 0 additions & 18 deletions api/contracts/getEquipmentsBorrowedByUser.ts

This file was deleted.

4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"aeria": "^0.0.226",
"aeria-sdk": "^0.0.156"
"aeria": "^0.0.237",
"aeria-sdk": "^0.0.163"
}
}
34 changes: 17 additions & 17 deletions api/src/collections/employee.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { extendEmployeeCollection } from "../../.aeria/out/collections/employee.mjs";
import { extendEmployeeCollection } from '../../.aeria/out/collections/employee.mjs'

export const employee = extendEmployeeCollection({
description: {
formLayout: {
fields: {
exit_date: {
if: {
not: {
operator: "equal",
term1: "is_active",
term2: true
}
}
}
}
}
}
});
description: {
formLayout: {
fields: {
exit_date: {
if: {
not: {
operator: 'equal',
term1: 'is_active',
term2: true,
},
},
},
},
},
},
})
6 changes: 4 additions & 2 deletions api/src/collections/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from "../../.aeria/out/collections/index.mjs";
export { employee } from "./employee.js";
export * from '../../.aeria/out/collections/index.mjs'
export {
employee,
} from './employee.js'
22 changes: 22 additions & 0 deletions api/src/contracts/getEquipmentsBorrowedByUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineContract, genericEndpointErrorSchema, resultSchema } from 'aeria'

export const getEquipmentBorrowedByUserContract = defineContract({
payload: {
type: 'object',
properties: {
employeeId: {
type: 'string',
},
},
},
response: [
genericEndpointErrorSchema(),
resultSchema({
type: 'array',
items: {
type: 'object',
additionalProperties: true,
},
}),
],
})
1 change: 1 addition & 0 deletions api/src/contracts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './getEquipmentsBorrowedByUser.js'
82 changes: 41 additions & 41 deletions api/src/routes/EquipmentsBorrowedByUser.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import { createRouter, HTTPStatus, Result } from "aeria";
export const equipmentRouter = createRouter();
import { createRouter, HTTPStatus, ObjectId, Result } from 'aeria'
export const equipmentRouter = createRouter()
import { getEquipmentBorrowedByUserContract } from '../contracts/getEquipmentsBorrowedByUser.js'

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

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
}
},
{
$lookup: {
from: 'asset',
localField: 'equipments',
foreignField: '_id',
as: 'equipmentsArray'
}
},
{
$unwind: {
path: '$equipmentsArray'
}
},
{
$project: {
_id: 0,
equipmentsArray: 1
}
},
]).toArray();
if (!employeeId) {
return context.error(HTTPStatus.NotFound, {
code: 'USER_ID_NOT_FOUND',
})
}

if (!borrowedEquipments || borrowedEquipments.length === 0) {
return context.error(HTTPStatus.NotFound, { code: "NO_EQUIPMENTS_FOUND" });
}
// Simulação de dados emprestados armazenados na coleção EquipmentRelease
const borrowedEquipments = await context.collections.equipmentRelease.model.aggregate([
{
$match: {
delivered_to: new ObjectId(employeeId),
},
},
{
$lookup: {
from: 'asset',
localField: 'equipments',
foreignField: '_id',
as: 'equipmentsArray',
},
},
{
$project: {
_id: 0,
equipmentsArray: 1,
},
},
]).toArray()

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

return Result.result(borrowedEquipments)
}, getEquipmentBorrowedByUserContract,
)
2 changes: 1 addition & 1 deletion api/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { createRouter } from 'aeria'
import { equipmentRouter } from './EquipmentsBorrowedByUser.js'

export const router = createRouter()
router.group('/equipmentEmployee', equipmentRouter)
router.group('/equipmentEmployee', equipmentRouter)
2 changes: 1 addition & 1 deletion api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "@aeriajs/cli/config/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"preserveSymlinks": true
"sourceMap": true
},
"include": [
"@types/*.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@eslint-aeria/config": "^0.0.5",
"dualist": "^0.0.5",
"husky": "^9.0.11",
"typescript": "^5.4.5"
"husky": "^9.1.7",
"typescript": "^5.7.2"
},
"workspaces": [
"api",
Expand Down
16 changes: 8 additions & 8 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
"@aeria-ui/i18n-en": "^0.0.3",
"@eslint-aeria/config-ui": "^0.0.3",
"aeria-app-layout": "^0.0.46",
"aeria-sdk": "^0.0.156",
"aeria-ui": "^0.0.148"
"aeria-sdk": "^0.0.163",
"aeria-ui": "^0.0.150"
},
"devDependencies": {
"autoprefixer": "^10.4.19",
"autoprefixer": "^10.4.20",
"eslint-config-aeriaui": "^0.0.11",
"eslint-plugin-readable-tailwind": "^1.5.2",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.4",
"unplugin-vue-router": "^0.9.1",
"vue-tsc": "^2.0.21"
"eslint-plugin-readable-tailwind": "^1.8.2",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.17",
"unplugin-vue-router": "^0.10.9",
"vue-tsc": "^2.2.0"
}
}
6 changes: 3 additions & 3 deletions web/src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './en.js'

export const ptbr = {
welcome: "Bem-vindo",
welcome: 'Bem-vindo',
// Outras traduções
};
}

25 changes: 14 additions & 11 deletions web/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import { useApp, defineOptions } from 'aeria-ui'
import { routes } from './routes.js'
import { ptbr } from "./i18n/index.js";
import { ptbr } from './i18n/index.js'
import Main from './main.vue'
import NoResults from './components/no-results.vue'
import aeriaPtbr from "@aeria-ui/i18n-pt";
import aeriaPtbr from '@aeria-ui/i18n-pt'

import "@aeria-ui/ui/style.css";
import "aeria-app-layout/style.css";
import "./style/main.less";
import '@aeria-ui/ui/style.css'
import 'aeria-app-layout/style.css'
import './style/main.less'

const options = defineOptions({
component: Main,
routes,
i18n: {
current: "pt_BR",
current: 'pt_BR',
locales: {
pt_BR: [aeriaPtbr, ptbr],
pt_BR: [
aeriaPtbr,
ptbr,
],
},
},
menuSchema: [
"/dashboard/equipmentRelease",
"/dashboard/asset",
"/dashboard/employee",
"/dashboard/user"
'/dashboard/equipmentRelease',
'/dashboard/asset',
'/dashboard/employee',
'/dashboard/user',
],
})

Expand Down
7 changes: 3 additions & 4 deletions web/src/pages/dashboard/asset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ definePage({
title: 'Assets',
icon: 'desktop-tower',
},
});
})
</script>

<template>
<aeria-crud collection="asset">
</aeria-crud>
</template>
<aeria-crud collection="asset" />
</template>
7 changes: 3 additions & 4 deletions web/src/pages/dashboard/employee.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ definePage({
title: 'Employee',
icon: 'folder-user',
},
});
})
</script>

<template>
<aeria-crud collection="employee">
</aeria-crud>
</template>
<aeria-crud collection="employee" />
</template>
Loading

0 comments on commit f4a39d1

Please sign in to comment.