UNPKG

1.27 kBJavaScriptView Raw
1/**
2 * @file Defines the ReadManyResponse class.
3 *
4 * @author Luke Chavers <luke@c2cschools.com>
5 * @author Kevin Sanders <kevin@c2cschools.com>
6 * @since 5.0.0
7 * @license See LICENSE.md for details about licensing.
8 * @copyright 2017 C2C Schools, LLC
9 */
10
11"use strict";
12
13const SuccessResponse = require( "./SuccessResponse" );
14
15/**
16 * This response class represents an API response for a 'ReadMany' endpoint.
17 *
18 * @memberOf Response
19 * @extends Response.SuccessResponse
20 */
21module.exports = class ReadManyResponse extends SuccessResponse {
22
23 /**
24 * Creates a JSON-API compatible scaffold for the response body [object].
25 *
26 * This method extends the `BaseResponse` scaffold by adding the data.
27 *
28 * @private
29 * @returns {Object} Response body.
30 */
31 _createResponseBody() {
32
33 const me = this;
34
35 let sBody = super._createResponseBody();
36
37 sBody.data = me.data._serializeToJsonApiObject();
38 sBody.meta.pagination = me.pagination;
39
40 return sBody;
41 }
42
43 /**
44 * The pagination portion of the response.
45 *
46 * @public
47 * @type {Object}
48 * @default {}
49 */
50 get pagination() {
51
52 const me = this;
53
54 return me.getConfigValue( "pagination", {} );
55 }
56
57 set pagination( /** Object */ val ) {
58
59 const me = this;
60
61 me.setConfigValue( "pagination", val );
62 }
63};