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

mozilla / blurts-server / #11898

pending completion
#11898

push

circleci

web-flow
Merge pull request #2770 from mozilla/license

Add license headers in source files

282 of 1138 branches covered (24.78%)

Branch coverage included in aggregate %.

959 of 3049 relevant lines covered (31.45%)

2.55 hits per line

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

0.0
/src/db/tables/breaches.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
import Knex from 'knex'
6
import knexConfig from '../knexfile.js'
7
import mozlog from '../../utils/log.js'
8
const knex = Knex(knexConfig)
×
9
const log = mozlog('DB.breaches')
×
10

11
/**
12
 * Get all records from "breaches" table
13
 * @returns Array of all records from "breaches" table
14
 */
15
async function getAllBreaches () {
16
  return knex('breaches')
×
17
    .returning()
18
}
19

20
/**
21
 * Upsert breaches into "breaches" table
22
 * Skip inserting when 'name' field (unique) has a conflict
23
 * @param {Array} hibpBreaches breaches array from HIBP API
24
 * @returns
25
 */
26
async function upsertBreaches (hibpBreaches) {
27
  log.debug('upsertBreaches', hibpBreaches[0])
×
28

29
  return knex.transaction(async trx => {
×
30
    const queries = hibpBreaches.map(breach =>
×
31
      knex('breaches')
×
32
        .insert({
33
          name: breach.Name,
34
          title: breach.Title,
35
          domain: breach.Domain,
36
          breach_date: breach.BreachDate,
37
          added_date: breach.AddedDate,
38
          modified_date: breach.ModifiedDate,
39
          pwn_count: breach.PwnCount,
40
          description: breach.Description,
41
          logo_path: breach.LogoPath,
42
          data_classes: breach.DataClasses,
43
          is_verified: breach.IsVerified,
44
          is_fabricated: breach.IsFabricated,
45
          is_sensitive: breach.IsSensitive,
46
          is_retired: breach.IsRetired,
47
          is_spam_list: breach.IsSpamList,
48
          is_malware: breach.IsMalware
49
        })
50
        .onConflict('name')
51
        .merge()
52
        .transacting(trx)
53
    )
54

55
    try {
×
56
      const value = await Promise.all(queries)
×
57
      return trx.commit(value)
×
58
    } catch (error) {
59
      return trx.rollback(error)
×
60
    }
61
  })
62
}
63

64
export {
65
  getAllBreaches,
66
  upsertBreaches
67
}
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