-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtransaction.js
More file actions
43 lines (38 loc) · 1.07 KB
/
transaction.js
File metadata and controls
43 lines (38 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const { httpBody } = require('../response-transforms');
const attachTransactionId = transactionId => res => ({ ...res, transactionId });
const begin = (conn, database, params = {}) => {
const headers = conn.headers();
headers.set('Accept', '*/*');
return fetch(conn.request(database, 'transaction', 'begin'), {
method: 'POST',
headers,
})
.then(httpBody)
.then(res => ({ ...res, transactionId: res.body }));
};
const rollback = (conn, database, transactionId, params = {}) => {
const headers = conn.headers();
return fetch(
conn.request(database, 'transaction', 'rollback', transactionId),
{
method: 'POST',
headers,
}
)
.then(httpBody)
.then(attachTransactionId(transactionId));
};
const commit = (conn, database, transactionId, params = {}) => {
const headers = conn.headers();
return fetch(conn.request(database, 'transaction', 'commit', transactionId), {
method: 'POST',
headers,
})
.then(httpBody)
.then(attachTransactionId(transactionId));
};
module.exports = {
begin,
rollback,
commit,
};