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

atlp-rwanda / champs-ec-be / 3830ef7e-e46a-4c27-8d28-dc6765443b01

08 May 2024 07:43AM UTC coverage: 86.615% (-0.3%) from 86.928%
3830ef7e-e46a-4c27-8d28-dc6765443b01

Pull #60

circleci

RwigimbaP-dev
ft(feature):admin should be able to feature/unfeature a product
Pull Request #60: #187527339 Feature Product

295 of 416 branches covered (70.91%)

Branch coverage included in aggregate %.

54 of 60 new or added lines in 4 files covered. (90.0%)

2 existing lines in 2 files now uncovered.

1478 of 1631 relevant lines covered (90.62%)

3.48 hits per line

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

80.95
/src/utils/finders.ts
1
import { Request } from "express";
2
import User from "../models/user";
1✔
3
import Product from "../models/Product";
1✔
4

5
/*
6
    This function 'findUserByEmail' finds a user by provided email
7
    and returns either a user or an error object. It can be reused across 
8
    the whole application.
9
*/
10

11
export const findUserByEmail = async (req: Request) => {
1✔
12
  const user = await User.findOne({
2✔
13
    where: {
14
      email: req.body.email
15
    }
16
  });
17
  return user;
2✔
18
};
19

20
/*
21
    This function below fetches all products from the database it 
22
    either returns an array or an error object. it can also be reused 
23
    across the whole app
24
*/
25

26
export const findAllProducts = async (): Promise<Product[] | object[]> => {
1✔
27
  try {
13✔
28
    const products = await Product.findAll();
13✔
29
    return products;
11✔
30
  } catch (err) {
31
    console.error(err);
2✔
32
    throw new Error("Couldn't Perform task at the moment");
2✔
33
  }
34
};
35

36
export const checkExpiredProducts = async (): Promise<void> => {
1✔
37
  const products = await findAllProducts();
10✔
38
  if (!products.length) {
10✔
39
    console.error("No Products found");
4✔
40
    return;
4✔
41
  }
42
  const checkProduct = async (index: number): Promise<number | undefined> => {
6✔
43
    if (index < 0) return; // Base case
12✔
44
    const currentItem = products[index] as Product;
6✔
45
    const expiryDate = new Date(currentItem.dataValues.expireDate as Date);
6✔
46
    if (expiryDate <= new Date()) {
6!
47
      await currentItem.update({ isExpired: true });
×
NEW
48
      if (new Date() > expiryDate && currentItem.dataValues.isFeatured) {
×
NEW
49
        await currentItem.update({ isFeatured: false });
×
50
      }
51
    }
52
    checkProduct(index - 1);
6✔
53
  };
54
  checkProduct(products.length - 1);
6✔
55
  console.log("SUCCESS: ALL PRODUCTS EXPIRATION DATES HAVE BEEN CHECKED");
6✔
56
};
57

58
export const findAllUsers = async (): Promise<User[] | object[]> => {
1✔
59
  try {
5✔
60
    const users = await User.findAll();
5✔
61
    return users;
3✔
62
  } catch (err) {
63
    throw new Error("Couldn't Perform task at the moment");
2✔
64
  }
65
};
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

© 2025 Coveralls, Inc