• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atlp-rwanda / vikings-ec-bn / 0bb86fc9-af79-4335-8e8b-b161b5535cdf

pending completion
0bb86fc9-af79-4335-8e8b-b161b5535cdf

Pull #79

circleci

Txny
fix: sales and orders
Pull Request #79: Fix sales and orders

342 of 364 branches covered (93.96%)

Branch coverage included in aggregate %.

11 of 11 new or added lines in 3 files covered. (100.0%)

1600 of 1645 relevant lines covered (97.26%)

19.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.84
/src/controllers/sales.controller.js
1
import { SalesService } from '../services/sales.service';
2
import { ProductService } from '../services/product.service';
3
import { OrderService } from '../services/order.service';
4
import {NotificationController as notify} from './notification.controller';
5
export class SalesController {
6
    static async getOrderSales(req, res) {
7
        try {
2✔
8
            const orderId = req.order.id;
2✔
9
            const sales = await SalesService.getOrderSales(orderId);
2✔
10
            let buyerSales = [];
1✔
11
            for (const sale of sales) {
1✔
12
                buyerSales.push(sale);
2✔
13
            }
14
            return res.status(200).json({ message: 'All order sales retrieved successfully', buyerSales: buyerSales});
1✔
15
        } catch (error) {
16
            return res.status(500).json({
1✔
17
                error: error.message,
18
                message: 'Could not retrieve sales, try again',
19
            });
20
        }
21
    }
22

23
    static async getSales(req, res) {
24
        try {
2✔
25
            const { limit, page } = req.query;
2✔
26
            const sellerId = req.user.id;
2✔
27
            const sales = await SalesService.getAllSales(limit, page);
2✔
28
            let sellerSales = [];
1✔
29
            for (const sale of sales.items) {
1✔
30
                const productId = sale.productId;
1✔
31
                const product = await ProductService.getProductById(productId);
1✔
32
                if (sellerId === product.userId) {
1!
33
                    sellerSales.push(sale);
×
34
                }
35
            }
36
            return res.status(200).json({ message: 'All seller sales retrieved successfully', sales: sellerSales, meta: sales.meta });
1✔
37
        } catch (error) {
38
            return res.status(500).json({
1✔
39
                error: error.message,
40
                message: 'Could not retrieve sales, try again',
41
            });
42
        }
43
    }
44

45

46
    static async getSale(req, res) {
47
        try {
1✔
48
            const sale = req.sale;
1✔
49
            return res.status(200).json({ message: 'Sale retrieved successfully', sale: sale });
1✔
50
        } catch (error) {
51
            return res.status(500).json({
×
52
                error: error.message,
53
                message: 'Could not retrieve sale, try again',
54
            });
55
        }
56
    }
57
  static async updateSaleStatus(req, res) {
58
    try {
8✔
59
      const { status } = req.body;
8✔
60
      const { saleId } = req.params;
8✔
61
      const updateOrderStatus = await SalesService.updateSaleStatusById(
8✔
62
        status,
63
        saleId
64
      );
65

66
      const { orderId } = req.sale;
7✔
67
      const sales = await SalesService.getOrderSales(orderId);
7✔
68
      const checkSameStatus = sales.every((sale) => sale.status === status);
11✔
69
      if (checkSameStatus) {
7✔
70
          {
71
              await OrderService.updateOrderStatusById(status, orderId);
4✔
72
              await notify.notifySellersAboutOrder(sales, status);
4✔
73
              await notify.notifyBuyerAboutOrder(orderId,status);
4✔
74
          }
75
      }
76
      sales.map((sale) => {
7✔
77
        if (sale.status === 'declined')
14✔
78
          OrderService.updateOrderStatusById('declined', orderId);
1✔
79
      });
80
      if (updateOrderStatus)
7!
81
        return res.status(200).json({
7✔
82
          message: 'Product order status has been changed successfully',
83
        });
84
    } catch (err) {
85
      return res.status(500).json({
1✔
86
        error: err.message,
87
        message: 'Failed to update product order status, try again',
88
      });
89
    }
90
  }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc