Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/#177 Endpoint soma do dia #180

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/bank-statements/bank-statements-repository.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IBankStatement } from './interfaces/bank-statement.interface';
import { IBSCounts } from './interfaces/bs-counts.interface';
import { IBSGetMePreviousDaysValidArgs } from './interfaces/bs-get-me-previous-days-args.interface';
import { IBSGetMePreviousDaysResponse } from './interfaces/bs-get-me-previous-days-response.interface';
import { IBSGetMeDayValidArgs } from './interfaces/bs-get-me-day-args.interface';

/**
* Get weekly statements
Expand Down Expand Up @@ -122,4 +123,18 @@ export class BankStatementsRepositoryService {
}
return statusCounts;
}

async getMeDay(validArgs: IBSGetMeDayValidArgs): Promise<number> {
const revenues = await this.ticketRevenuesService.getMe(
{
startDate: validArgs.endDate,
endDate: validArgs.endDate,
userId: validArgs.user.id,
groupBy: 'day',
},
{ limit: 9999, page: 1 },
'ticket-revenues',
);
return revenues.amountSum;
}
}
27 changes: 12 additions & 15 deletions src/bank-statements/bank-statements.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { Pagination } from 'src/utils/types/pagination.type';
import { BankStatementsRepositoryService } from './bank-statements-repository.service';
import { IBankStatement } from './interfaces/bank-statement.interface';
import { IBSGetMeArgs } from './interfaces/bs-get-me-args.interface';
import { IBSGetMeDayArgs } from './interfaces/bs-get-me-day-args.interface';
import {
IBSGetMeDayArgs,
IBSGetMeDayValidArgs,
} from './interfaces/bs-get-me-day-args.interface';
import { IBSGetMeDayResponse } from './interfaces/bs-get-me-day-response.interface';
import {
IBSGetMePreviousDaysArgs,
Expand All @@ -29,7 +32,7 @@ import { IGetBSResponse } from './interfaces/get-bs-response.interface';
export class BankStatementsService {
constructor(
private readonly usersService: UsersService,
private readonly bankStatementsRepositoryService: BankStatementsRepositoryService,
private readonly bankStatementsRepository: BankStatementsRepositoryService,
private readonly ticketRevenuesService: TicketRevenuesService,
) {}

Expand Down Expand Up @@ -192,17 +195,16 @@ export class BankStatementsService {
}

public async getMeDay(args: IBSGetMeDayArgs): Promise<IBSGetMeDayResponse> {
await this.validateGetMeDay(args);
// This data is mocked for development
const validArgs = await this.validateGetMeDay(args);
const amount = await this.bankStatementsRepository.getMeDay(validArgs);
return {
valueToReceive: 4.9,
valueToReceive: amount,
};
}

private async validateGetMeDay(args: IBSGetMeDayArgs): Promise<{
endDate: string;
user: User;
}> {
private async validateGetMeDay(
args: IBSGetMeDayArgs,
): Promise<IBSGetMeDayValidArgs> {
if (isNaN(args?.userId as number)) {
throw CommonHttpException.argNotType('userId', 'number', args?.userId);
}
Expand All @@ -213,17 +215,12 @@ export class BankStatementsService {
};
}

/**
* TODO: refactor
*
* Service: previous-days
*/
public async getMePreviousDays(
args: IBSGetMePreviousDaysArgs,
paginationOptions: PaginationOptions,
): Promise<Pagination<IBSGetMePreviousDaysResponse>> {
const validArgs = await this.validateGetMePreviousDays(args);
return await this.bankStatementsRepositoryService.getPreviousDays(
return await this.bankStatementsRepository.getPreviousDays(
validArgs,
paginationOptions,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { User } from 'src/users/entities/user.entity';

export class IBSGetMeDayArgs {
endDate: string;
userId?: number;
}

export class IBSGetMeDayValidArgs {
endDate: string;
user: User;
}
Loading