forked from rtorr/newww
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collaborator.js
63 lines (56 loc) · 1.54 KB
/
collaborator.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var Collaborator = require("../models/collaborator")
var decorate = require("../presenters/collaborator")
var collaborator = module.exports = {};
collaborator.list = function(request, reply) {
Collaborator.new(request)
.list(request.packageName, function(err, collaborators) {
if (err) {
request.logger.error(err);
return reply(err)
}
return reply({
collaborators: collaborators
});
});
};
collaborator.add = function(request, reply) {
Collaborator.new(request)
.add(request.packageName, request.payload.collaborator, function(err, collab) {
if (err) {
request.logger.error(err);
if (err.statusCode === 404) {
return reply({
statusCode: 404,
message: "user not found: "+request.payload.collaborator.name
}).code(404)
} else {
return reply(err)
}
}
return reply({
collaborator: decorate(collab, request.packageName)
});
});
};
collaborator.update = function(request, reply) {
Collaborator.new(request)
.update(request.packageName, request.payload.collaborator, function(err, collaborator) {
if (err) {
request.logger.error(err);
return reply(err)
}
return reply({
collaborator: decorate(collaborator, request.packageName)
});
});
};
collaborator.del = function(request, reply) {
Collaborator.new(request)
.del(request.packageName, request.params.username, function(err, result) {
if (err) {
request.logger.error(err);
return reply(err)
}
return reply(result)
});
};