Skip to content

Commit 2703333

Browse files
fix: newSellOrder service output
1 parent 438f31d commit 2703333

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

src/controllers/investments.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ investmentController
1414
const brokerAsset = await assetService.getByCodeAsset(order.codAtivo);
1515

1616
if (brokerAsset.qtdeAtivo < order.qtdeAtivo) {
17-
return res.status(StatusCodes.BAD_REQUEST).json({ message: 'Quantidade indisponível!' });
17+
return res.status(StatusCodes.BAD_REQUEST).json({ message: 'Quantidade indisponível na Corretora!' });
1818
}
1919

2020
const investment = await investmentsService.newBuyOrder(order);

src/interfaces/order.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ export default interface IOrderBody {
44
codAtivo: number,
55
qtdeAtivo: number,
66
valor?: number,
7-
message?: string;
7+
message?: string
88
}

src/interfaces/updateOrder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export default interface IUpdateOrder {
33
codCliente: number,
44
qtdeAtivo: number,
55
valor?: number,
6+
message?: string,
67
}

src/services/asset.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ const updateSellOrder = async (codAtivo: number, order: IUpdateOrder): Promise<I
6161
if (asset.codAtivo === codAtivo) {
6262

6363
if (asset.qtdeAtivo <= order.qtdeAtivo) {
64-
throw new HttpException(StatusCodes.BAD_REQUEST, "Valor da venda é maior que a quantia sob custódia.");
64+
return order.message = "Valor da venda é maior que a quantia sob custódia.";
6565
}
6666

6767
assetModel.updateSell(clientAsset); // Atualiza a quantia sob custodia
6868

6969
} else {
70-
throw new HttpException(StatusCodes.NOT_FOUND, `Ativo ${codAtivo} não encontrado para o cliente ${order.codCliente}.`);
70+
return order.message =`Ativo ${codAtivo} não encontrado para o cliente ${order.codCliente}.`
7171
}
7272

7373
})

src/services/investments.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import investmentsModel from "../models/investments.model";
55
import HttpException from "../shared/http.exception";
66

77
const isValid = (order: IOrderBody) => {
8-
if (!order.codAtivo || typeof order.codAtivo !== "number") return false;
8+
if (!order.codCliente || typeof order.codCliente !== "number") return false;
99
if (!order.codAtivo || typeof order.codAtivo !== "number") return false;
1010
if (!order.qtdeAtivo || typeof order.qtdeAtivo !== "number") return false;
1111

@@ -58,7 +58,7 @@ const newSellOrder = async (order: IOrderBody): Promise<IOrderBody>=> {
5858

5959
if (asset.qtdeAtivo <= order.qtdeAtivo) {
6060
// throw new HttpException(StatusCodes.BAD_REQUEST, "Valor da venda é maior que a quantia sob custódia.");
61-
order.message = "Valor da venda é maior que a quantia sob custódia.";
61+
return order.message = "Valor da venda é maior que a quantia sob custódia.";
6262
}
6363

6464
assetModel.updateSell(clientAsset); // Atualiza a quantia sob custodia
@@ -70,7 +70,7 @@ const newSellOrder = async (order: IOrderBody): Promise<IOrderBody>=> {
7070

7171
} else {
7272
//throw new HttpException(StatusCodes.NOT_FOUND, `Ativo ${order.codAtivo} não encontrado para o cliente ${order.codCliente}.`);
73-
order.message =`Ativo ${order.codAtivo} não encontrado para o cliente ${order.codCliente}.`
73+
return order.message =`Ativo ${order.codAtivo} não encontrado para o cliente ${order.codCliente}.`
7474
}
7575
})
7676
}

0 commit comments

Comments
 (0)