My service does not receive the parameters using typeORM

Viewed 31

i have a problem when creating an insertion in my purchase model I will explain the issue to you:

When I pass the body to the create method that receives the controller (if the data arrives) but when I call the service and pass (body) in the invocation of create, at that point only comes quantity_product foreign keys do not reach me ... I do not know what I'm doing wrong o.O thanks in advance I share the code.

Postman:

{
    "quantity_product": 30,
    "purchase_id": "91f2c6dc-2663-4f0c-85c1-829a2030d1f6",
    "product_id": "103b9d3c-de0a-463a-acaa-43b03636acd7"
}

Controller:

async createPurchaseProduct(req: Request, res: Response) {
    try {
         const data = await this.purchaseProductService.createPurchaseProduct(req.body);
         return this.httpResponse.Ok(res, data);
    } catch (e) {
        return this.httpResponse.InternalServerError(res, e);
    }
}

Service

async createPurchaseProduct(body: PurchaseProductDTO): Promise<PurchaseProductEntity> {
    const new_purchase_product = ( await this.execRepository).create(body);
    const find_product = await this.productService.findProductById(JSON.stringify(new_purchase_product.product.id));

    new_purchase_product.total_price = find_product!.price * new_purchase_product.quantity_product;
        return (await this.execRepository).save(new_purchase_product);
    }
0 Answers
Related