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

atlp-rwanda / e-commerce-bitcrafters-bn / 11b859bc-f27f-4137-a9ac-aac05d5ec4bd

18 Jun 2024 09:07AM UTC coverage: 92.684% (-0.1%) from 92.783%
11b859bc-f27f-4137-a9ac-aac05d5ec4bd

push

circleci

web-flow
fix(product Orders): implement endpoint for admin able to get all orders [Delivers #187764392] (#102)

Co-authored-by: UwizeyimamaFurahaJustine <137182672+UwizeyimamaFurahaJustine@users.noreply.github.com>

473 of 529 branches covered (89.41%)

Branch coverage included in aggregate %.

13 of 15 new or added lines in 2 files covered. (86.67%)

1516 of 1617 relevant lines covered (93.75%)

5.16 hits per line

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

92.73
/src/controllers/orderController.ts
1
import { Request, Response } from 'express'
2
import Order from '../database/models/orderModel';
2✔
3
import eventEmitter from '../services/notificationServices';
2✔
4
import OrderService from '../services/orderService';
2✔
5

6
/**
7
 * Get notifications for the authenticated user
8
 * @param {Request} req - Express request object
9
 * @param {Response} res - Express response object
10
 * @returns {Promise<Response>} Promise that resolves to an Express response
11
 */
12
export const getorder = async (req: Request, res: Response) => {
6✔
13
    const { id } = req.user;
6✔
14
    try {
6✔
15
      const order = await Order.findOne({
6✔
16
        where: { userId: id },
17
      });
18
      if (!order) {
4✔
19
        return res.status(404).json({message: 'Order not found'})
2✔
20
      }
21
      return res.status(200).json({message: 'Order retrieved successful', order})
2✔
22
    } catch (err: unknown) {
23
      const errors = err as Error;
2✔
24
      return res.status(500).json( errors.message)
2✔
25
    }
26
  };
27

28
/**
29
 * Get all orders as an admin
30
 * @param {Request} req - Express request object
31
 * @param {Response} res - Express response object
32
 * @returns {Promise<Response>} Promise that resolves to an Express response
33
 */
34
export const getAllorders = async (req: Request, res: Response) => {
6✔
35
    try {
6✔
36
      const page: number =
37
      Number.parseInt(req.query.page as unknown as string, 10) || 1
6✔
38
    const limit: number =
39
      Number.parseInt(req.query.limit as unknown as string, 10) || 5
6✔
40

41
    if (
6!
42
      Number.isNaN(page) ||
24✔
43
      Number.isNaN(limit) ||
44
      page <= 0 ||
45
      limit <= 0
46
    ) {
NEW
47
      return res
×
48
        .status(400)
49
        .json({ message: 'Invalid pagination parameters' })
50
    }
51

52
      const offset = (page - 1) * limit
6✔
53

54
      const orders = await Order.findAll({offset, limit});
6✔
55
      if (!orders) {
4!
56
        return res.status(404).json({message: 'no orders found'})
4✔
57
      }
NEW
58
      return res.status(200).json({message: 'Orders retrieved successful', orders})
×
59
    } catch (err: unknown) {
60
      const errors = err as Error;
2✔
61
      return res.status(500).json( errors.message)
2✔
62
    }
63
  };
64

65
  /**
66
   * Get notifications for the authenticated user
67
   * @param {Request} req - Express request object
68
   * @param {Response} res - Express response object
69
   * @returns {Promise<Response>} Promise that resolves to an Express response
70
   */
71
  export const updateproductorder = async (req: Request, res: Response) => {
6✔
72
    const { orderId } = req.params;
6✔
73
    const { status } = req.body;
6✔
74
  
75
    try {
6✔
76
      const order = await Order.findByPk(orderId);
6✔
77
      if (!order) {
4✔
78
        return res.status(404).json({message: 'Order not found'})
2✔
79
      }
80
      await OrderService.updateOrderStatus(orderId as string, status);
2✔
81
      const updatedOrder = await Order.findByPk(orderId);
2✔
82
      const statu = updatedOrder.status
2✔
83
      eventEmitter.emit('order:updatedStatus', updatedOrder)
2✔
84
      return res.status(200).json({message: 'Order status updated successfully', statu})
2✔
85
    } catch (err: unknown) {
86
      const errors = err as Error;
2✔
87
      return res.status(500).json( errors.message)
2✔
88
    }
89
  };
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