-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add contract to getEquipmentBorrowedByUser and fixes on equ…
…ipmentRelease view
- Loading branch information
Showing
17 changed files
with
452 additions
and
236 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}), | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './getEquipmentsBorrowedByUser.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.