Skip to content

Commit

Permalink
Merge pull request #43 from fga-eps-mds/151-gerar-relatorios-de-equip…
Browse files Browse the repository at this point in the history
…amentos-2

151 gerar relatorios de equipamentos 2
  • Loading branch information
JoaoVitorFarias authored Jul 10, 2023
2 parents 85a26af + c92e8f7 commit 5eececd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
49 changes: 38 additions & 11 deletions src/repository/equipamentRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import { MoreThanOrEqual, ILike } from 'typeorm'
import { MoreThanOrEqual, ILike, LessThanOrEqual, Between } from 'typeorm'
import { dataSource } from '../db/config'
import { Equipment } from '../db/entities/equipment'
import { EquipmentRepositoryProtocol, Query } from './protocol/equipmentRepositoryProtocol'
Expand Down Expand Up @@ -34,30 +34,60 @@ export class EquipmentRepository implements EquipmentRepositoryProtocol {
})
return equipment
}

async genericFind(query: Query): Promise<Equipment[]> {
const {
type,
storageType,
ram_size,
processador,
screenSize,
screenType,
power,
unit,
situation,
updatedAt,
brand,
model,
acquisition,
search,
searchTipping,
initialDate,
finalDate,
take,
skip,
acquisitionYear,
} = query;

const defaultConditions= {
type: type,
type: type ? { id: type } : undefined,
storageType: storageType,
situacao: situation,
screenSize: screenSize,
screenType: screenType,
processor: processador,
power: power,
unit: unit? {id: unit} : undefined,
brand: brand ? { id: brand } : undefined,
ram_size: ram_size,
model: model,
acquisition: acquisition ? {name: acquisition}: undefined,
updatedAt: updatedAt ? MoreThanOrEqual(updatedAt) : undefined,
createdAt: undefined,
acquisitionDate: acquisitionYear
? Between(new Date(Number(acquisitionYear), 0, 1), new Date(Number(acquisitionYear), 11, 31))
: undefined,
};

let searchConditions;

if(initialDate && finalDate) {
defaultConditions.createdAt = Between(initialDate, finalDate)
} else if (initialDate) {
defaultConditions.createdAt = MoreThanOrEqual(initialDate)
} else if (finalDate) {
defaultConditions.createdAt = LessThanOrEqual(finalDate)
}

let searchConditions;
if(typeof search !== 'undefined') {
searchConditions = [
{
Expand All @@ -80,9 +110,8 @@ export class EquipmentRepository implements EquipmentRepositoryProtocol {
}
]
} else
searchConditions = defaultConditions;


searchConditions = defaultConditions;

const queryResult = await this.equipmentRepository.find({
relations: {
brand: true,
Expand All @@ -95,11 +124,9 @@ export class EquipmentRepository implements EquipmentRepositoryProtocol {
take: take,
skip: skip
});

return queryResult;
}



async findByTippingNumberOrSerialNumber(
id: string
): Promise<Equipment | null> {
Expand Down
18 changes: 17 additions & 1 deletion src/repository/protocol/equipmentRepositoryProtocol.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Equipment } from '../../db/entities/equipment'

export type Query = {
userId?: string
id?: string
tippingNumber?: string
serialNumber?: string
acquisition?: string
type?: string
unit?: string
situation?: string
Expand All @@ -9,15 +14,26 @@ export type Query = {
search?: string
model?: string
searchTipping?: string
screenSize?: string
power?: string
screenType?: string
processador?: string
storageType?: string
ram_size?: string
storageAmount?: string
createdAt?: Date
initialDate?: Date
finalDate?: Date
take?: number
skip?: number
acquisitionYear?: string
}

export interface EquipmentRepositoryProtocol {
create(equipment: Equipment): Promise<Equipment>
updateOne(equipmentData: any): Promise<boolean>
findOne(equipmentId: string): Promise<Equipment | null>
genericFind(query: any): Promise<Equipment[]>
genericFind(query: Query): Promise<Equipment[]>
findByTippingNumberOrSerialNumber(id: string): Promise<Equipment | null>
findByTippingNumber(tippingNumber: string): Promise<Equipment | null>
deleteOne(id: string): Promise<boolean>
Expand Down
4 changes: 4 additions & 0 deletions src/useCases/getEquipment/getEquipmentUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export interface GetEquipmentInput {

createdAt?: Date

initialDate?: Date

finalDate?: Date

take?: number

skip?: number
Expand Down

0 comments on commit 5eececd

Please sign in to comment.