1 | /**
|
2 | * @file Defines the ReadOneResponse 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 | ;
|
12 |
|
13 | const SuccessResponse = require( "./SuccessResponse" );
|
14 |
|
15 | /**
|
16 | * This response class represents an API response for a 'ReadOne' endpoint.
|
17 | *
|
18 | * @memberOf Response
|
19 | * @extends Response.SuccessResponse
|
20 | */
|
21 | module.exports = class ReadOneResponse 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 | if ( me.data ) {
|
38 |
|
39 | sBody.data = me.data._serializeToJsonApiObject();
|
40 |
|
41 | } else {
|
42 |
|
43 | sBody.data = null;
|
44 | }
|
45 |
|
46 | return sBody;
|
47 | }
|
48 | };
|