Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10361542
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/bin/prometheus-modules/chat/chat.js b/bin/prometheus-modules/chat/chat.js
index 5b69b0ba..05edb5c0 100644
--- a/bin/prometheus-modules/chat/chat.js
+++ b/bin/prometheus-modules/chat/chat.js
@@ -1,75 +1,75 @@
module.exports.prepare_resource_type_chat_message = function(chat_message){
chat_message.add_fields([
- {name: "from", type: "text", required:true},//should be an association to User
+ {name: "from", type: "text" },//should be an association to User | was "required: true"
{name: "message", type: "text", required: true},
{name: "date", type: "date"},
{name: "order_in_conversation", type: "int"},
{name: "conversation_id", type: "int"},
]);
}
module.exports.prepare_resource_type_chat_conversation = function(chat_conversation){
chat_conversation.add_fields([
{name: "title", type: "text", required: true},
{name: "random_number", type: "int"},
{name: "user1", type: "Reference"},
{name: "user2", type: "Reference"}
]);
}
//ten kod nie jest wykorzystywany
module.exports.construct_associations = function(AssocInterface){
AssocInterface.create({
left_type: "chat-message",
right_type: "chat-conversation",
bidirectional: true,
name_ltr: "is_in_conversation",
name_rtl: "contains_messages",
left_required: true
});
}
module.exports.prepare_channel_rest = function(rest){
rest.add_path("/api/v1/chat/message", "chat_message");
rest.add_path("/api/v1/chat/conversation", "chat_conversation");
}
module.exports.prepare_channel_www_server = function(www_server, dispatcher, dependencies){
var Promise = require("bluebird");
www_server.route({
method: "GET",
path: "/api/v1/chat/conversation/{id}/messages",
handler: function(request, reply){
dispatcher.resources_find({conversation_id: parseInt(request.params.id)}, "chat_message")
.then(function(resources){
reply(resources);
})
}
});
www_server.route({
method: "GET",
path: "/api/v1/chat/conversation/mine",
handler: function(request, reply){
var me = www_server.get_user_id(request.state.PrometheusSession);
me = me.toString();
console.log(me);
var p1 = dispatcher.resources_find({user2: me}, "chat_conversation");
var p2 = dispatcher.resources_find({user1: me}, "chat_conversation");
var p3 = dispatcher.resources_search_by_mode("chat_conversation", "public");
Promise.all([p1,p2,p3]).then(function(response){
console.log(response);
reply(response);
})
/* dispatcher.resources_find({user2: me}, "chat_conversation").then(function(response){
reply(response);
});
*/
}
});
}
\ No newline at end of file
diff --git a/bin/prometheus-modules/contact-list/contact-list.js b/bin/prometheus-modules/contact-list/contact-list.js
index 6e1189f9..f0883539 100644
--- a/bin/prometheus-modules/contact-list/contact-list.js
+++ b/bin/prometheus-modules/contact-list/contact-list.js
@@ -1,31 +1,31 @@
var path = require("path");
module.exports.prepare_resource_type_contact = function(chat_conversation){
chat_conversation.add_fields([
{name: "name", type: "text", required: true},
- {name: "email", type: "text", required: true},
+ {name: "email", type: "email", required: true},
{name: "phone_number", type:"text"}
]);
}
module.exports.prepare_channel_rest = function(rest){
rest.add_path("/api/v1/chat/contacts", "contact");
// rest wie, żeby powiązać ten url z tym typem zasobu i na nim wywoływać GET i POST
}
module.exports.prepare_channel_www_server = function(channel){
var public_dir = path.resolve(module.filename, "../../../../public");
channel.static_route(public_dir, "");
}
/*
1. contact-list.js
2. rest.js
3. www-server.js
4. dispatcher-web
5. dispatcher-biz
6. dispatcher-db
*/
\ No newline at end of file
diff --git a/bin/prometheus-modules/rest/rest.js b/bin/prometheus-modules/rest/rest.js
index bb225e0f..7bbaa91c 100644
--- a/bin/prometheus-modules/rest/rest.js
+++ b/bin/prometheus-modules/rest/rest.js
@@ -1,98 +1,102 @@
module.exports.prepare_channel_rest = function(channel, dispatcher, dependencies){
//console.log("\nREST dependencies:", dependencies);
var www_server = dependencies["channel.www_server"];
channel.add_path = function(url, resource_type_name){
www_server.route({
method: "GET",
path: url,
handler: function(request, reply){
dispatcher.resources_list_by_type(resource_type_name)
.then(function(resources){ // wywołanie metody z dispatchera webowego
//console.log("GOT RESPONSE FROM DISPATCHER");
//var resources_arr = resources.map(function(resource){return resource.getData()});
reply(resources);
});
}
// hanlder GET ma wypisać wszystkie zasoby o podanym typie
});
www_server.route({
method: "POST",
path: url,
handler: function(request, reply){
var id_by_session = www_server.get_user_id(request.state.PrometheusSession);
if(id_by_session){
- dispatcher.resources_create(resource_type_name, request.payload, id_by_session).then(function(response){
+ dispatcher.resources_create(resource_type_name, request.payload, id_by_session)
+ .then(function(response){
reply(response.toString());
+ })
+ .catch(function(error) {
+ reply(error).statusCode = 422;
});
} else {
reply("not logged in");
}
}
// handler POST ma stworzyć zasób z podanymi wartościami
});
www_server.route({
method: "DELETE",
path: url,
handler: function(request, reply){
//console.log("rest.js DELETE", request.payload)
dispatcher.resources_delete(resource_type_name, request.payload).then(function(response){
reply();
});
}
// handler POST ma stworzyć zasób z podanymi wartościami
});
www_server.route({
method: "GET",
path: url+"/{id}",
handler: function(request, reply){
//console.log("rest.js get_resource_by_id", request.params.id);
dispatcher.resources_get_by_id(request.params.id).then(function(response){
reply(response);
}).catch(function(error){
reply().statusCode = 409;
});
}
});
www_server.route({
method: "PUT",
path: url+"/{id}/access_mode",
handler: function(request, reply){
//console.log("rest.js get_resource_by_id", request.params.id, request.payload.access_mode, request.payload.access_mode_args);
dispatcher.resources_edit_resource_access_mode(request.params.id, request.payload.access_mode, request.payload.access_mode_args).then(function(response){
reply(response);
});
}
});
www_server.route({
method: "PUT",
path: url+"/{id}",
handler: function(request, reply){
//console.log("rest.js get_resource_by_id", request.params.id, request.payload.access_mode, request.payload.access_mode_args);
dispatcher.resources_update(request.params.id, request.payload).then(function(response){
reply(response);
});
}
});
www_server.route({
method: "GET",
path: url+"/{id}/access_mode",
handler: function(request, reply){
//console.log("rest.js get_resource_access_mode_by_id");
dispatcher.resources_get_access_mode(request.params.id).then(function(response){
reply(response);
});
}
});
}
}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 8, 14:24 (7 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034665
Default Alt Text
(7 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment