forked from moduwa-aac/moduwa-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwords.dto.js
More file actions
137 lines (122 loc) · 2.92 KB
/
words.dto.js
File metadata and controls
137 lines (122 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* Words DTO
*/
/**
* PartOfSpeech Enum
*/
export const PartOfSpeech = {
NOUN: 'NOUN',
VERB: 'VERB',
ADJECTIVE: 'ADJECTIVE',
MODIFIER: 'MODIFIER',
EMOTION: 'EMOTION',
ENDING: 'ENDING',
NONE: 'NONE'
};
/**
* GET /api/words - Query DTO
*/
export class GetWordsQueryDto {
constructor({ categoryId, onlyFavorite }) {
this.categoryId = categoryId ? String(categoryId) : null; // String으로 변환
this.onlyFavorite = onlyFavorite === 'true' || onlyFavorite === true;
}
}
/**
* POST /api/words - Create Word Request DTO
*/
export class CreateWordDto {
constructor({ categoryId, word, imageUrl }) {
this.categoryId = String(categoryId); // String으로 변환
this.word = word;
this.imageUrl = imageUrl;
}
validate() {
const errors = [];
if (!this.categoryId) {
errors.push('categoryId는 필수입니다');
}
if (!this.word) {
errors.push('word는 필수입니다');
}
// imageUrl은 선택사항
if (errors.length > 0) {
throw new Error(errors.join(', '));
}
}
}
/**
* PATCH /api/words/:cardId/favorite - Update Favorite Request DTO
*/
export class UpdateFavoriteDto {
constructor({ isFavorite }) {
this.isFavorite = isFavorite;
}
validate() {
if (typeof this.isFavorite !== 'boolean') {
throw new Error('isFavorite는 boolean 타입이어야 합니다');
}
}
}
/**
* PATCH /api/words/:cardId - Update Word Request DTO
*/
export class UpdateWordDto {
constructor({ word, imageUrl, userCategoryId }) {
this.word = word;
this.imageUrl = imageUrl;
this.userCategoryId = userCategoryId ? String(userCategoryId) : null;
}
validate() {
if (!this.word && !this.imageUrl && !this.userCategoryId) {
throw new Error('word, imageUrl, categoryId 중 하나는 필수입니다');
}
}
}
/**
* PATCH /api/words/reorder - Reorder Words Request DTO
*/
export class ReorderWordsDto {
constructor({ categoryId, orderedCardIds }) {
this.categoryId = String(categoryId);
this.orderedCardIds = orderedCardIds || [];
}
validate() {
const errors = [];
if (!this.categoryId) {
errors.push('categoryId는 필수입니다');
}
if (!Array.isArray(this.orderedCardIds) || this.orderedCardIds.length === 0) {
errors.push('orderedCardIds는 필수 배열입니다');
}
if (errors.length > 0) {
throw new Error(errors.join(', '));
}
}
}
/**
* 낱말 카드 응답 DTO
*/
export class WordCardResponseDto {
constructor({
cardId,
categoryId,
categoryName,
partOfSpeech,
word,
imageUrl,
isDefault,
isFavorite,
displayOrder
}) {
this.cardId = cardId;
this.categoryId = categoryId;
this.categoryName = categoryName;
this.partOfSpeech = partOfSpeech;
this.word = word;
this.imageUrl = imageUrl;
this.isDefault = isDefault;
this.isFavorite = isFavorite;
this.displayOrder = displayOrder;
}
}