-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from andela/ft-chat-feature-167727342
#167727342 Chat feature
- Loading branch information
Showing
22 changed files
with
884 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
service_name: travis-pro | ||
repo_token: XNKnyASxAKlbHCdtkGZtyK9fQCHum5Rho | ||
repo_token: XNKnyASxAKlbHCdtkGZtyK9fQCHum5Rho |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,4 @@ | |
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { chatEmitter, getChatsEmitter } from '../helpers/notificationHandler'; | ||
import { getChats, postChat } from '../services/chatServices'; | ||
import { respondWithSuccess, respondWithWarning } from '../helpers/responseHandler'; | ||
import statusCode from '../helpers/statusCode'; | ||
|
||
export const createChat = async (req, res) => { | ||
const payload = { ...req.body, userId: req.auth.id }; | ||
try { | ||
const chat = await postChat(payload); | ||
chatEmitter(chat.toJSON()); | ||
return respondWithSuccess(res, statusCode.created, 'Chat created successfully', chat.toJSON()); | ||
} catch (error) { | ||
return respondWithWarning(res, statusCode.internalServerError, 'Oops something bad happened'); | ||
} | ||
}; | ||
|
||
export const getChatMessages = async (req, res) => { | ||
try { | ||
const chats = await getChats(req.query.sender, req.query.recipient); | ||
if (!chats.length) { | ||
return respondWithWarning(res, statusCode.resourceNotFound, 'Chats not found'); | ||
} | ||
const payload = { ...chats, sender: req.query.sender, recipient: req.query.recipient }; | ||
getChatsEmitter(payload); | ||
return respondWithSuccess(res, statusCode.success, 'Chat was retrieved successfully', chats); | ||
} catch (error) { | ||
return respondWithWarning(res, statusCode.internalServerError, 'Oops something bad happened'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export default { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Chats', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
}, | ||
recipient: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
sender: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
}, | ||
message: { | ||
type: Sequelize.TEXT, | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: new Date() | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE, | ||
defaultValue: new Date() | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('Chats') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
export default { | ||
up: (queryInterface) => queryInterface.bulkInsert('Chats', [ | ||
{ | ||
userId: 3, | ||
recipient: 'alexiwobi@nomad.com', | ||
sender: 'lionelmessi@nomad.com', | ||
message: 'Hello there ...', | ||
}, | ||
{ | ||
userId: 4, | ||
recipient: 'lionelmessi@nomad.com', | ||
sender: 'alexiwobi@nomad.com', | ||
message: 'Hello messi, how are you doing?', | ||
}, | ||
{ | ||
userId: 4, | ||
recipient: 'lionelmessi@nomad.com', | ||
sender: 'alexiwobi@nomad.com', | ||
message: 'I just saw your trip request, i think i need to give you some information on how this whole process goes.', | ||
}, | ||
{ | ||
userId: 3, | ||
recipient: 'alexiwobi@nomad.com', | ||
sender: 'lionelmessi@nomad.com', | ||
message: 'Ok. I would love you to clarify me on the whole process. What are the things involved for me to have a smooth trip?', | ||
}, | ||
{ | ||
userId: 4, | ||
recipient: 'lionelmessi@nomad.com', | ||
sender: 'alexiwobi@nomad.com', | ||
message: 'I will be sending you a link. study the information there in and let me know if there are any other things you are not clear about.', | ||
}, | ||
{ | ||
userId: 3, | ||
recipient: 'alexiwobi@nomad.com', | ||
sender: 'lionelmessi@nomad.com', | ||
message: 'Ok. Thanks. I will look in to it and get back to you.', | ||
}, | ||
{ | ||
userId: 3, | ||
recipient: 'johndoe@nomad.com', | ||
sender: 'lionelmessi@nomad.com', | ||
message: 'Hello there ...', | ||
}, | ||
{ | ||
userId: 2, | ||
recipient: 'lionelmessi@nomad.com', | ||
sender: 'johndoe@nomad.com', | ||
message: 'Hello messi, how are you doing?', | ||
}, | ||
{ | ||
userId: 2, | ||
recipient: 'lionelmessi@nomad.com', | ||
sender: 'johndoe@nomad.com', | ||
message: 'I just saw your trip request, i think i need to give you some information on how this whole process goes.', | ||
}, | ||
{ | ||
userId: 3, | ||
recipient: 'johndoe@nomad.com', | ||
sender: 'lionelmessi@nomad.com', | ||
message: 'Ok. I would love you to clarify me on the whole process. What are the things involved for me to have a smooth trip?', | ||
}, | ||
{ | ||
userId: 2, | ||
recipient: 'lionelmessi@nomad.com', | ||
sender: 'johndoe@nomad.com', | ||
message: 'I will be sending you a link. study the information there in and let me know if there are any other things you are not clear about.', | ||
}, | ||
{ | ||
userId: 3, | ||
recipient: 'alexiwobi@nomad.com', | ||
sender: 'lionelmessi@nomad.com', | ||
message: 'Ok. Thanks. I will look in to it and get back to you.', | ||
}, | ||
]), | ||
|
||
down: queryInterface => queryInterface.bulkDelete('Chats', null, {}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const createChat = { | ||
type: 'object', | ||
properties: { | ||
sender: { | ||
type: 'string', | ||
format: 'email', | ||
example: 'jammjones@nomad.com', | ||
}, | ||
recipient: { | ||
type: 'string', | ||
format: 'email', | ||
example: 'alexiwobi@nomad.com', | ||
}, | ||
message: { | ||
type: 'string', | ||
example: 'Hello, i go your comment on my trip request' | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
export const postChatPath = { | ||
post: { | ||
tags: [ | ||
'chats' | ||
], | ||
security: [ | ||
{ | ||
BearerToken: [] | ||
} | ||
], | ||
summary: 'Manager, Requester or anyone with the permission should be able to chat on the platform', | ||
description: 'A manager, requester or any other person with the permission should be able to chat on the platform', | ||
parameters: [ | ||
{ | ||
name: 'body', | ||
in: 'body', | ||
description: 'Chat request object', | ||
required: true, | ||
schema: { | ||
$ref: '#/definitions/createChat' | ||
} | ||
} | ||
], | ||
responses: { | ||
201: { | ||
description: 'Chat has been created successfully', | ||
schema: { | ||
$ref: '#/definitions/created' | ||
} | ||
}, | ||
400: { | ||
description: 'Invalid request details', | ||
schema: { | ||
$ref: '#/definitions/badRequest' | ||
} | ||
}, | ||
401: { | ||
description: 'Unauthorized', | ||
schema: { | ||
$ref: '#/definitions/notAuthorized' | ||
} | ||
}, | ||
403: { | ||
description: 'Access forbidden', | ||
schema: { | ||
$ref: '#/definitions/accessForbidden' | ||
} | ||
}, | ||
500: { | ||
description: 'Server error', | ||
schema: { | ||
$ref: '#/definitions/serverError' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export const getChatsPath = { | ||
get: { | ||
tags: [ | ||
'chats' | ||
], | ||
security: [ | ||
{ | ||
BearerToken: [] | ||
} | ||
], | ||
summary: 'Manager, Requester or anyone with the permission should be able to get private chats on the platform', | ||
description: 'Manager, Requester or anyone with the permission should be able to get private chats on the platform', | ||
parameters: [ | ||
{ | ||
in: 'query', | ||
name: 'sender', | ||
description: 'Chat sender query string', | ||
required: true, | ||
type: 'string', | ||
example: 'jammjones@nomad.com' | ||
}, | ||
{ | ||
in: 'query', | ||
name: 'recipient', | ||
description: 'Chat recipient query string', | ||
required: true, | ||
type: 'string', | ||
example: 'alexiwobi@nomad.com' | ||
} | ||
], | ||
responses: { | ||
200: { | ||
description: 'Chat was retrieved successfully', | ||
schema: { | ||
$ref: '#/definitions/successful' | ||
} | ||
}, | ||
400: { | ||
description: 'Invalid request details', | ||
schema: { | ||
$ref: '#/definitions/badRequest' | ||
} | ||
}, | ||
401: { | ||
description: 'Unauthorized', | ||
schema: { | ||
$ref: '#/definitions/notAuthorized' | ||
} | ||
}, | ||
403: { | ||
description: 'Access forbidden', | ||
schema: { | ||
$ref: '#/definitions/accessForbidden' | ||
} | ||
}, | ||
404: { | ||
description: 'Chats not found', | ||
schema: { | ||
$ref: '#/definitions/notFound' | ||
} | ||
}, | ||
500: { | ||
description: 'Server error', | ||
schema: { | ||
$ref: '#/definitions/serverError' | ||
} | ||
} | ||
} | ||
} | ||
}; |
Oops, something went wrong.