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

Fdawgs / ydh-myydh-crud-api / 4417510579

pending completion
4417510579

push

github

GitHub
chore(main): release 11.0.7 (#1221)

259 of 259 branches covered (100.0%)

Branch coverage included in aggregate %.

527 of 527 relevant lines covered (100.0%)

14.21 hits per line

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

100.0
/src/routes/admin/access/bearer-token/query.js
1
const escSq = require("../../../../utils/escape-single-quotes");
2✔
2

3
/**
4
 * @author Frazer Smith
5
 * @description Build SQL query string.
6
 * @param {object} options - Query string and database config values.
7
 * @param {string} options.id - Logical id of the artifact.
8
 * @returns {string} Query string.
9
 */
10
const accessDelete = ({ id }) => escSq`DELETE
6✔
11
 FROM access.tokens
12
 WHERE id = '${id}';`;
13

14
/**
15
 * @author Frazer Smith
16
 * @description Build SQL query string.
17
 * @param {object} options - Query string and database config values.
18
 * @param {string} options.id - Logical id of the artifact.
19
 * @returns {string} Query string.
20
 */
21
const accessGetRead = ({ id }) => escSq`SELECT
8✔
22
    id,
23
    name,
24
    email,
25
    scopes,
26
    hash,
27
    expires,
28
    created,
29
    last_updated
30
FROM access.tokens
31
WHERE id = '${id}';`;
32

33
/**
34
 * @author Frazer Smith
35
 * @description Build SQL query string.
36
 * @param {object} options - Query string and database config values.
37
 * @param {('mssql'|'postgresql')} options.client - Database client.
38
 * @param {string} options.whereClausePredicates - WHERE clause predicates.
39
 * @param {number} options.page - Page to retrieve.
40
 * @param {number} options.perPage - Number of bearer token records to return per page.
41
 * @returns {string} Query string.
42
 */
43

44
// DISTINCT SQL keyword not needed as PK constraints enforce unique values
45
const accessGetSearch = ({ client, whereClausePredicates, page, perPage }) => `
10✔
46
SELECT COUNT(id)${
47
        // Cast from string to int - https://node-postgres.com/features/types
48
        client === "postgresql" ? "::int" : ""
10✔
49
} AS total
50
FROM access.tokens
51
WHERE ${whereClausePredicates};
52

53
SELECT id,
54
    name,
55
    email,
56
    scopes,
57
    hash,
58
    expires,
59
    created,
60
    last_updated
61
FROM access.tokens
62
WHERE ${whereClausePredicates}
63
ORDER BY created ASC
64
OFFSET ${page * perPage} ROWS
65
FETCH NEXT ${perPage} ROWS ONLY;`;
66

67
/**
68
 * @author Frazer Smith
69
 * @description Build SQL query string.
70
 * @param {object} options - Query string and database config values.
71
 * @param {('mssql'|'postgresql')} options.client - Database client.
72
 * @param {string} options.name - Type of matching value.
73
 * @param {string} options.email - Matching Value.
74
 * @param {string} options.scopes - JSON string containing actions the bearer token can perform.
75
 * @param {string} options.hash - Bcrypt-hashed bearer token.
76
 * @param {string=} options.expires - Datetime the bearer token expires.
77
 * @returns {string} Query string.
78
 */
79
const accessPost = ({ client, name, email, scopes, hash, expires }) =>
2✔
80
        escSq`INSERT INTO access.tokens (name, email, scopes, hash, expires)
8✔
81
    ${client === "mssql" ? "OUTPUT Inserted.id, Inserted.scopes" : ""}
8✔
82
    VALUES ('${name}', '${email}', '${scopes}', '${hash}', '${expires}')
83
    ${client === "postgresql" ? "RETURNING id, scopes" : ""};`;
8✔
84

85
module.exports = {
2✔
86
        accessDelete,
87
        accessGetRead,
88
        accessGetSearch,
89
        accessPost,
90
};
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