@ahhaohho/response-dto 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/ResponseDTO.js +34 -37
  2. package/package.json +1 -1
package/ResponseDTO.js CHANGED
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * ResponseDTO 클래스
3
3
  * API 응답을 표준화하기 위한 클래스입니다.
4
4
  * 성공 응답, 클라이언트 오류, 시스템 오류 등 모든 API 응답에 대해 일관된 구조를 제공합니다.
@@ -9,111 +9,111 @@ class ResponseDTO {
9
9
  * @param {string} type - 응답 유형 ('success', 'client', 또는 'system')
10
10
  * @param {number} status - HTTP 상태 코드
11
11
  * @param {object|null} data - 응답 데이터 (항상 포함, 없을 경우 null)
12
- * @param {string|null} message - 추가 메시지 (주로 오류에 사용)
12
+ * @param {string|null} message - 추가 메시지 (주로 오류에 사용, 없을 경우 null)
13
13
  */
14
14
  constructor(type, status, data = null, message = null) {
15
- this.type = type;
16
- this.status = status;
17
- this.data = data; // 항상 data 필드를 포함, 값이 없으면 null
18
- if (message !== null) this.message = message;
15
+ this.type = type;
16
+ this.status = status;
17
+ this.data = data; // 항상 data 필드를 포함, 값이 없으면 null
18
+ this.message = message; // 항상 message 필드를 포함, 값이 없으면 null
19
19
  }
20
20
 
21
- /**
21
+ /**
22
22
  * 상태 코드 200의 성공 응답을 생성합니다.
23
23
  * @param {object|null} data - 응답에 포함될 데이터
24
24
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
25
25
  */
26
26
  static success(data = null) {
27
- return new ResponseDTO('success', 200, data);
27
+ return new ResponseDTO('success', 200, data);
28
28
  }
29
29
 
30
- /**
30
+ /**
31
31
  * 리소스 생성 성공을 나타내는 상태 코드 201의 응답을 생성합니다.
32
32
  * @param {object|null} data - 생성된 리소스의 데이터
33
33
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
34
34
  */
35
35
  static created(data = null) {
36
- return new ResponseDTO('success', 201, data);
36
+ return new ResponseDTO('success', 201, data);
37
37
  }
38
38
 
39
- /**
39
+ /**
40
40
  * 콘텐츠가 없는 성공 응답 (상태 코드 204)을 생성합니다.
41
41
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
42
42
  */
43
43
  static noContent() {
44
- return new ResponseDTO('success', 204, null);
44
+ return new ResponseDTO('success', 204, null);
45
45
  }
46
46
 
47
- /**
47
+ /**
48
48
  * 잘못된 요청에 대한 클라이언트 오류 응답 (상태 코드 400)을 생성합니다.
49
49
  * @param {string} message - 오류 메시지
50
50
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
51
51
  */
52
52
  static badRequest(message) {
53
- return new ResponseDTO('client', 400, null, message);
53
+ return new ResponseDTO('client', 400, null, message);
54
54
  }
55
55
 
56
- /**
56
+ /**
57
57
  * 인증되지 않은 접근에 대한 클라이언트 오류 응답 (상태 코드 401)을 생성합니다.
58
58
  * @param {string} message - 오류 메시지
59
59
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
60
60
  */
61
61
  static unauthorized(message) {
62
- return new ResponseDTO('client', 401, null, message);
62
+ return new ResponseDTO('client', 401, null, message);
63
63
  }
64
64
 
65
- /**
65
+ /**
66
66
  * 금지된 접근에 대한 클라이언트 오류 응답 (상태 코드 403)을 생성합니다.
67
67
  * @param {string} message - 오류 메시지
68
68
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
69
69
  */
70
70
  static forbidden(message) {
71
- return new ResponseDTO('client', 403, null, message);
71
+ return new ResponseDTO('client', 403, null, message);
72
72
  }
73
73
 
74
- /**
74
+ /**
75
75
  * 리소스를 찾을 수 없는 경우의 클라이언트 오류 응답 (상태 코드 404)을 생성합니다.
76
76
  * @param {string} message - 오류 메시지
77
77
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
78
78
  */
79
79
  static notFound(message) {
80
- return new ResponseDTO('client', 404, null, message);
80
+ return new ResponseDTO('client', 404, null, message);
81
81
  }
82
82
 
83
- /**
83
+ /**
84
84
  * 충돌 상황에 대한 클라이언트 오류 응답 (상태 코드 409)을 생성합니다.
85
85
  * @param {string} message - 오류 메시지
86
86
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
87
87
  */
88
88
  static conflict(message) {
89
- return new ResponseDTO('client', 409, null, message);
89
+ return new ResponseDTO('client', 409, null, message);
90
90
  }
91
91
 
92
- /**
92
+ /**
93
93
  * 유효성 검사 오류에 대한 클라이언트 오류 응답 (상태 코드 422)을 생성합니다.
94
94
  * @param {string} message - 오류 메시지
95
95
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
96
96
  */
97
97
  static validationError(message) {
98
- return new ResponseDTO('client', 422, null, message);
98
+ return new ResponseDTO('client', 422, null, message);
99
99
  }
100
100
 
101
- /**
101
+ /**
102
102
  * 시스템 오류 응답 (상태 코드 500)을 생성합니다.
103
103
  * @param {string} message - 오류 메시지
104
104
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
105
105
  */
106
106
  static systemError(message) {
107
- return new ResponseDTO('system', 500, null, message);
107
+ return new ResponseDTO('system', 500, null, message);
108
108
  }
109
109
 
110
- /**
110
+ /**
111
111
  * 서비스 이용 불가 상황에 대한 시스템 오류 응답 (상태 코드 503)을 생성합니다.
112
112
  * @param {string} message - 오류 메시지
113
113
  * @returns {ResponseDTO} 새로운 ResponseDTO 인스턴스
114
114
  */
115
115
  static serviceUnavailable(message) {
116
- return new ResponseDTO('system', 503, null, message);
116
+ return new ResponseDTO('system', 503, null, message);
117
117
  }
118
118
 
119
119
  /**
@@ -121,15 +121,12 @@ class ResponseDTO {
121
121
  * @returns {object} ResponseDTO의 일반 JavaScript 객체 표현
122
122
  */
123
123
  toJSON() {
124
- const json = {
125
- type: this.type,
126
- status: this.status,
127
- data: this.data
128
- };
129
- if (this.message !== undefined) {
130
- json.message = this.message;
131
- }
132
- return json;
124
+ return {
125
+ type: this.type,
126
+ status: this.status,
127
+ data: this.data,
128
+ message: this.message
129
+ };
133
130
  }
134
131
  }
135
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahhaohho/response-dto",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "AhhaOhho API 응답을 위한 DTO 클래스",
5
5
  "main": "index.js",
6
6
  "scripts": {