Skip to content

Commit

Permalink
Merge branch 'master' into bot-insensitive-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pallavi2209 committed Jul 20, 2017
2 parents 1cdee57 + ff6c166 commit 3b33e62
Show file tree
Hide file tree
Showing 7 changed files with 582 additions and 0 deletions.
60 changes: 60 additions & 0 deletions api/v1/controllers/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) 2017, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/

/**
* api/v1/controllers/events.js
*/
'use strict';

const helper = require('../helpers/nouns/events');
const doFind = require('../helpers/verbs/doFind');
const doGet = require('../helpers/verbs/doGet');
const doPost = require('../helpers/verbs/doPost');

module.exports = {

/**
* GET /events
*
* Finds zero or more events and sends them back in the response.
*
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
*/
findEvents(req, res, next) {
doFind(req, res, next, helper);
},

/**
* GET /events/{key}
*
* Retrieves the event and sends it back in the response.
*
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
*/
getEvent(req, res, next) {
doGet(req, res, next, helper);
},

/**
* POST /events
*
* Creates a new event and sends it back in the response.
*
* @param {IncomingMessage} req - The request object
* @param {ServerResponse} res - The response object
* @param {Function} next - The next middleware function in the stack
*/
postEvents(req, res, next) {
doPost(req, res, next, helper);
},

}; // exports
25 changes: 25 additions & 0 deletions api/v1/helpers/nouns/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2017, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/

/**
* api/v1/helpers/nouns/events.js
*/

const Events = require('../../../../db/index').Event;

const m = 'Events';

module.exports = {
apiLinks: {
GET: `Retrieve ${m}`,
POST: `Create a new ${m}`,
},
baseUrl: '/v1/events',
model: Events,
modelName: 'events',
}; // exports
4 changes: 4 additions & 0 deletions api/v1/helpers/verbs/findUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ function toSequelizeWhere(filter, props) {
const v = filter[key][j];
if (typeof v === 'boolean') {
values.push(v);
} else if (typeof v === 'number') {
values.push(v);
} else if (u.looksLikeId(v)) {
values.push(v);
} else if (typeof v === 'string') {
const arr = v.split(constants.COMMA);
for (let k = ZERO; k < arr.length; k++) {
Expand Down
184 changes: 184 additions & 0 deletions api/v1/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7571,6 +7571,161 @@ paths:
default:
$ref: "#/responses/genericError"

# =============================================================================
/events:
x-swagger-router-controller: events
get:
summary: Retrieve all events
tags: [ events ]
operationId: findEvents
description: >-
All events are retrieved using this route and using the paramaters as filters you can focus on rooms, bots, or users.
parameters:
-
name: roomId
description: Get events from specific room
in: query
required: false
type: integer
-
name: botId
description: Get events from specific bot
in: query
required: false
type: string
-
name: botDataId
description: Get events from specific botData
in: query
required: false
type: string
-
name: botActionId
description: Get events from specific botAction
in: query
required: false
type: string
-
name: userId
description: Get events from specific user
in: query
required: false
type: string
-
$ref: "#/parameters/limitParam"
-
$ref: "#/parameters/offsetParam"
responses:
200:
description: >-
Success, returns all Events
schema:
type: array
items:
$ref: "#/definitions/EventResponse"
400:
$ref: "#/responses/400"
401:
$ref: "#/responses/401"
404:
$ref: "#/responses/404"
default:
$ref: "#/responses/genericError"

post:
security:
- jwt: []
summary: Create a new event
tags: [ events ]
description: >-
Create a new event that can describe any action or information needed to be specifically logged,
typically used to activity in rooms.
operationId: postEvents
parameters:
-
name: queryBody
in: body
required: true
schema:
type: object
description: Create event properties
properties:
log:
type: string
description: Human readable log line to describe the context.
context:
type: object
description: Any object, typically JSON, used to describe to some infomration that needed to be logged.
roomId:
type: integer
description: Room that this event relates to.
botId:
type: string
description: Bot that this event relates to.
botDataId:
type: string
description: Bot Data that this event relates to.
botActionId:
type: string
description: Bot Action that this event relates to.
userId:
type: string
description: User that this event relates to.
required:
- log
responses:
201:
description: >-
Created event
schema:
$ref: "#/definitions/EventResponse"
400:
$ref: "#/responses/400"
401:
$ref: "#/responses/401"
403:
$ref: "#/responses/403"
default:
$ref: "#/responses/genericError"

# ---------------------------------------------------------------------------
/events/{key}:
x-swagger-router-controller: events
get:
summary: Retrieve an event
tags: [ events ]
description: >-
This route is used to retrieve a single event.
operationId: getEvent
parameters:
-
name: key
in: path
description: >-
The id the event to retrieve
required: true
type: string
-
$ref: "#/parameters/limitParam"
-
$ref: "#/parameters/offsetParam"
responses:
200:
description: >-
Success, returns specified event
schema:
type: array
items:
$ref: "#/definitions/EventResponse"
400:
$ref: "#/responses/400"
401:
$ref: "#/responses/401"
404:
$ref: "#/responses/404"
default:
$ref: "#/responses/genericError"

# =============================================================================
definitions:

Expand Down Expand Up @@ -8832,6 +8987,35 @@ definitions:
items:
type: object

EventResponse:
type: object
description: A response for information about a event
properties:
id:
type: string
description: The UUID of the specified event
log:
type: string
description: Human readable log line describing the event and its context it stores
context:
type: object
description: A object, typically JSON, that contains the information to describe an event
roomId:
type: integer
description: The room ID in which the event deals with
botId:
type: string
description: The bot ID in which the event deals with
botDataId:
type: string
description: The bot data ID in which the event deals with
botActionId:
type: string
description: The bot action ID in which the event deals with
userId:
type: string
description: The user ID in which the event deals with

CollectorResponse:
type: "object"
required:
Expand Down

0 comments on commit 3b33e62

Please sign in to comment.