-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunctionContext.js
More file actions
48 lines (39 loc) · 900 Bytes
/
FunctionContext.js
File metadata and controls
48 lines (39 loc) · 900 Bytes
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
44
45
46
47
48
class FunctionContext {
constructor(cb) {
this.value = 200;
this.cb = cb(this);
this.headerValues = {};
}
status(value) {
if(!value) {
return this.value;
}
this.value = value;
return this;
}
headers(value) {
if(!value) {
return this.headerValues;
}
this.headerValues = value;
return this;
}
succeed(value) {
let err;
this.cb(err, value);
}
fail(value) {
let message;
this.cb(value, message);
}
attachment(fileName, writeStream) {
let err;
// Creating a tagged data type here, to be able to choose a proper action in handler (cb).
this.cb(err, {
type: 'attachment',
fileName,
writeStream
})
}
}
module.exports = FunctionContext;