API Docs for:
Show:

models.server.Ticket Class

Server Ticket model

Methods

addComment

(
  • comment
  • user
  • [opts]
)
Bluebird.Promise

Add comment to the ticket

Parameters:

  • comment String
  • user models.server.User | Number

    Creator of the tag

  • [opts] Boolean optional
    • [silent=false] Boolean optional

      Set to true to disable update notifications

Returns:

Bluebird.Promise:

with models.server.Comment

addDevice

(
  • device
  • addedBy
)
Bluebird.Promise

Add device relation

Parameters:

Returns:

Bluebird.Promise:

with models.server.Device

addFollower

(
  • follower
  • addedBy
)
Bluebird.Promise

Add follower to a ticket. Also adds a visibility for the follower.

Parameters:

Returns:

Bluebird.Promise:

with models.server.Handler

addHandler

(
  • handler
  • addedBy
)
Bluebird.Promise

Add handler to a ticket

Parameters:

Returns:

Bluebird.Promise:

with models.server.Handler

addRelatedUser

(
  • user
  • addedBy
)
Bluebird.Promise

Add related user to the ticket

Parameters:

Returns:

Bluebird.Promise:

with models.server.RelatedUser

addTag

(
  • tag
  • user
)
Bluebird.Promise

Add Tag to the ticket

Parameters:

Returns:

Bluebird.Promise:

with models.server.Tag

addTitle

(
  • title
  • user
  • [opts]
)
Bluebird.Promise

Add title to the ticket

Parameters:

  • title String
  • user models.server.User | Number

    Creator of the tag

  • [opts] Boolean optional
    • [silent=false] Boolean optional

      Set to true to disable update notifications

Returns:

Bluebird.Promise:

with models.server.Title

addVisibility

(
  • visibility
  • addedBy
  • [comment]
)
Bluebird.Promise

Add visibility to the ticket. If the visibility already exists for the ticket the existing visibility is returned.

Visibility strings can be accessed for example from User#getVisibilities()

Parameters:

  • visibility String

    Visibility string

  • addedBy models.server.User | Number

    User model or id of user who adds the visibility

  • [comment] String optional

    Optional comment for the visibility

Returns:

Bluebird.Promise:

with models.server.Visibility

byVisibilities

(
  • visibilities
)
models.server.Base.Collection static

Fetch tickets by given visibilities.

Parameters:

  • visibilities Array

    Array of visibility strings. Strings are in the form of organisation|school|user:<entity id>.

    Example: "school:2"

Returns:

models.server.Base.Collection:

with models.server.Ticket models

comments

() Bookshelf.Collection

Returns:

Bookshelf.Collection:

Bookshelf.Collection of Ticket comment models

create

(
  • title
  • description
  • createdBy
  • [options]
)
Bluebird.Promise

Shortcut for creating ticket with a title and description.

Parameters:

  • title String
  • description String
  • createdBy models.server.User | Number
  • [options] Object optional
    • [mailTransport] optional

      custom mail transport

Returns:

Bluebird.Promise:

with models.server.Ticket

createdAt

() Date

Inherited from models.BaseMixin but overwritten in models/BaseMixin.js:12

Returns:

Date:

deletedAt

() Date

Inherited from models.BaseMixin but overwritten in models/BaseMixin.js:36

Returns:

Date:

devices

() Bookshelf.Collection

Returns:

Bookshelf.Collection:

Bookshelf.Collection of Ticket devices

ensureNotification

(
  • user
)
Bluebird.Promise

Ensure notification relation for a user

Parameters:

Returns:

Bluebird.Promise:

with models.server.Notification

fetchByIdConstrained

(
  • user
  • ticketId
  • options
)
Bluebird.Promise static

Fetch the ticket by id with visibilities of the user

Parameters:

  • user models.server.User
  • ticketId Number

    Ticket id

  • options Object

    Options passed to Bookshelf fetchOne method

Returns:

Bluebird.Promise:

With models.server.Ticket

fetchOrCreate

(
  • identifier
)
Bluebird.Promise

Fetch or create a model uniquely identified by the columns defined in the identifier

Parameters:

  • identifier Object

    Object of table columns

Returns:

Bluebird.Promise:

with the model instance

followers

() Bookshelf.Collection

Returns:

Bookshelf.Collection:

Bookshelf.Collection of Ticket followers relations

generateSecret

() String

Generate secure random secret for email replies

Returns:

String:

getCurrentTitle

() String

Return the current title. Requires titles relation

Returns:

String:

getDescription

() String

Get description ie. the first comment

Returns:

String:

getReplyEmailAddress

() String

Returns:

String:

getSocketIORoom

() String

Returns:

String:

handlers

() Bookshelf.Collection

Returns:

Bookshelf.Collection:

Bookshelf.Collection of Ticket handlers

hasVisibility

(
  • visibility
  • models
)

Visibility assertion helper

Parameters:

  • visibility String
  • models Array

    Array of models.server.Visibility models

Returns:

Boolean

initialize

(
  • attrs
  • [options.mailTransport]
)

Parameters:

  • attrs Object

    Model attributes

  • [options.mailTransport] Object optional

    custom mail transport

(
  • user
)
static

Query tickets with visibilities of the user

Parameters:

isHandler

(
  • UNKNOWN
)
Boolean

Returns true if the user is handler for this ticket

'handlerUsers' relation must be loaded with 'withRelated' in fetch or with Ticket#load("handlerUsers")

Parameters:

Returns:

Boolean:

isSame

(
  • other
)

Inherited from models.BaseMixin but overwritten in models/BaseMixin.js:48

Return true if the other object is built using the same constructor and they have the same id

Parameters:

Returns:

Boolean

isSoftDeleted

() Boolean

Inherited from models.BaseMixin but overwritten in models/BaseMixin.js:28

Returns:

Boolean:

markAsRead

(
  • user
  • [options]
)
Bluebird.Promise

Mark ticket as read

Parameters:

  • user models.server.User | Number

    User model or id of the user

  • [options] Object optional
    • [emailOnly] Object optional

      Set to true to mark as read from email

Returns:

Bluebird.Promise:

with models.server.Notification

relatedUsers

() Bookshelf.Collection

Returns:

Bookshelf.Collection:

Bookshelf.Collection of Ticket related users

removeFollower

(
  • user
  • removedBy
)
Bluebird.Promise

Remove user from followers

Parameters:

Returns:

removeTag

(
  • tag
  • removedBy
  • [options]
)
Bluebird.Promise

Soft delete given tag

Parameters:

  • tag String
  • removedBy models.server.User | Number
  • [options] Object optional
    • [require=false] Boolean optional

      When true the promise is rejected if the tag is missing

Returns:

renderEmailBufferedTemplate

(
  • context
)
String private static

Render buffered email update

Parameters:

  • context Object

Returns:

String:

sendBufferedEmailNotifications

(
  • user
)
Bluebird.Promise

Parameters:

Returns:

sendMail

(
  • options
)
Bluebird.Promise

Parameters:

  • options Object

Returns:

setStatus

(
  • status
  • user
  • [options.force=false]
)
Bluebird.Promise

Set status of the ticket

Parameters:

  • status String
  • user models.server.User

    Creator of the status

  • [options.force=false] Boolean optional

    Set to true to skip manager validation

Returns:

Bluebird.Promise:

models.server.Tag representing the status

softDelete

(
  • byUser
)
Bluebird.Promise

Set timestamp to deletedAt

Parameters:

Returns:

status

() Bookshelf.Collection

Return collection containing only one models.server.Tag representing the status of the ticket. When serialized as JSON this field will appear as a simple string field. Example: status: "open".

tags

() Bookshelf.Collection

Get all tags for this ticket

Returns:

Bookshelf.Collection:

Bookshelf.Collection of tag models

titles

() Bookshelf.Collection

Returns:

Bookshelf.Collection:

Bookshelf.Collection of Ticket title models

triggerUpdate

(
  • model
)
Bluebird.Promise

Parameters:

Returns:

uniqueId

() String

Returns:

String:

unreadComments

(
  • user
  • [options]
)
Bookshelf.Collection

Get unread comments for given user. Use options.byEmail to get those comments that have not been sent out as email.

Parameters:

  • user models.server.User | Number

    or user id

  • [options] Options optional
    • [byEmail] Options optional

      get comments that are not emailed

updatedAt

() Date

Inherited from models.BaseMixin but overwritten in models/BaseMixin.js:20

Returns:

Date:

updateTimestamp

() Bluebird.Promise

Update updatedAt column to current time. Should be called when ever a update relation is added to the ticket

Returns:

visibilities

() models.server.Visibility

Returns:

models.server.Visibility:

withUnreadComments

(
  • user
  • [options]
)
Bookshelf.Collection static

Return collection of tickets that have unread comments by the user

Parameters:

  • user models.client.User | Number
  • [options] Object optional
    • [byEmail=false] Object optional

      Get tickets by unsent email notifications

Returns:

Bookshelf.Collection:

of models.server.Ticket

Properties

_mailTransport

Object private

nodemailer email transport object

https://github.com/andris9/Nodemailer

type

String

The database table name

Virtual database field. Use .get("type") to access it.

unique_id

String

Unique id between tables.

Virtual database field. Use .get("unique_id") to access it.