student-help 2.0.0
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.
- package/LICENSE +15 -0
- package/README.md +44 -0
- package/bin/student-help.js +14 -0
- package/cli.mjs +1415 -0
- package/commands/db.ts +59 -0
- package/commands/dev.ts +23 -0
- package/commands/generate/auth.ts +31 -0
- package/commands/generate/install.ts +34 -0
- package/commands/generate/resource.ts +184 -0
- package/commands/new.ts +179 -0
- package/package.json +62 -0
- package/templates/backend/controller.ts +41 -0
- package/templates/backend/dto.ts +20 -0
- package/templates/backend/module.ts +16 -0
- package/templates/backend/service.ts +52 -0
- package/templates/backend/student-help.controller.ts +332 -0
- package/templates/backend/student-help.module.ts +9 -0
- package/templates/backend/student-help.service.ts +697 -0
- package/templates/frontend/page.tsx +13 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ResourceService
|
|
3
|
+
* ================================
|
|
4
|
+
* Serviço que contém a lógica de negócio para o recurso Resource.
|
|
5
|
+
* Expansão:
|
|
6
|
+
* - Adicione validação de regras de negócio
|
|
7
|
+
* - Adicione paginação
|
|
8
|
+
* - Adicione filtros avançados
|
|
9
|
+
*/
|
|
10
|
+
import { Injectable } from '@nestjs/common';
|
|
11
|
+
import { CreateResourceDto, UpdateResourceDto } from './resource.dto';
|
|
12
|
+
|
|
13
|
+
@Injectable()
|
|
14
|
+
export class ResourceService {
|
|
15
|
+
private data: any[] = [];
|
|
16
|
+
private id = 1;
|
|
17
|
+
|
|
18
|
+
create(createResourceDto: CreateResourceDto) {
|
|
19
|
+
const resource = {
|
|
20
|
+
id: this.id++,
|
|
21
|
+
...createResourceDto,
|
|
22
|
+
createdAt: new Date(),
|
|
23
|
+
};
|
|
24
|
+
this.data.push(resource);
|
|
25
|
+
return resource;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
findAll() {
|
|
29
|
+
return this.data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
findOne(id: number) {
|
|
33
|
+
return this.data.find(item => item.id === id);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
update(id: number, updateResourceDto: UpdateResourceDto) {
|
|
37
|
+
const index = this.data.findIndex(item => item.id === id);
|
|
38
|
+
if (index !== -1) {
|
|
39
|
+
this.data[index] = { ...this.data[index], ...updateResourceDto, updatedAt: new Date() };
|
|
40
|
+
return this.data[index];
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
remove(id: number) {
|
|
46
|
+
const index = this.data.findIndex(item => item.id === id);
|
|
47
|
+
if (index !== -1) {
|
|
48
|
+
return this.data.splice(index, 1);
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { Controller, Post, Get, Body, Param, Query } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
StudentHelpService,
|
|
4
|
+
AuthResponse,
|
|
5
|
+
ValidationResult,
|
|
6
|
+
ExportResult,
|
|
7
|
+
FileUploadResult,
|
|
8
|
+
EmailNotification
|
|
9
|
+
} from './student-help.service';
|
|
10
|
+
|
|
11
|
+
@Controller('student-help')
|
|
12
|
+
export class StudentHelpController {
|
|
13
|
+
constructor(private studentHelpService: StudentHelpService) {}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* ========================================
|
|
17
|
+
* 🔐 AUTHENTICATION ENDPOINTS
|
|
18
|
+
* ========================================
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
@Post('register')
|
|
22
|
+
async register(@Body() body: { email: string; name: string; password: string }): Promise<AuthResponse> {
|
|
23
|
+
return this.studentHelpService.register(body.email, body.name, body.password);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Post('login')
|
|
27
|
+
async login(@Body() body: { email: string; password: string }): Promise<AuthResponse> {
|
|
28
|
+
return this.studentHelpService.login(body.email, body.password);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Post('logout/:userId')
|
|
32
|
+
async logout(@Param('userId') userId: string): Promise<AuthResponse> {
|
|
33
|
+
return this.studentHelpService.logout(userId);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* ========================================
|
|
38
|
+
* 🔐 SECURITY ENDPOINTS
|
|
39
|
+
* ========================================
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
@Post('hash-password')
|
|
43
|
+
async hashPassword(@Body() body: { password: string; rounds?: number }): Promise<{ hash: string }> {
|
|
44
|
+
const hash = await this.studentHelpService.hashPassword(body.password, body.rounds);
|
|
45
|
+
return { hash };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Post('compare-password')
|
|
49
|
+
async comparePassword(
|
|
50
|
+
@Body() body: { password: string; hash: string }
|
|
51
|
+
): Promise<{ match: boolean }> {
|
|
52
|
+
const match = await this.studentHelpService.comparePassword(body.password, body.hash);
|
|
53
|
+
return { match };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@Post('generate-token')
|
|
57
|
+
generateToken(
|
|
58
|
+
@Body() body: { payload: any; secret?: string }
|
|
59
|
+
): Promise<{ token: string }> {
|
|
60
|
+
const token = this.studentHelpService.generateToken(body.payload, body.secret);
|
|
61
|
+
return Promise.resolve({ token });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Get('generate-random-token')
|
|
65
|
+
generateRandomToken(@Query('length') length?: string): Promise<{ token: string }> {
|
|
66
|
+
const token = this.studentHelpService.generateRandomToken(length ? parseInt(length) : undefined);
|
|
67
|
+
return Promise.resolve({ token });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Post('encrypt')
|
|
71
|
+
encrypt(@Body() body: { text: string; key?: string }): Promise<{ encrypted: string }> {
|
|
72
|
+
const encrypted = this.studentHelpService.encryptText(body.text, body.key);
|
|
73
|
+
return Promise.resolve({ encrypted });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Post('decrypt')
|
|
77
|
+
decrypt(@Body() body: { encrypted: string; key?: string }): Promise<{ text: string }> {
|
|
78
|
+
const text = this.studentHelpService.decryptText(body.encrypted, body.key);
|
|
79
|
+
return Promise.resolve({ text });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Get('generate-api-key')
|
|
83
|
+
generateApiKey(): Promise<{ apiKey: string }> {
|
|
84
|
+
const apiKey = this.studentHelpService.generateApiKey();
|
|
85
|
+
return Promise.resolve({ apiKey });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* ========================================
|
|
90
|
+
* 📧 NOTIFICATION ENDPOINTS
|
|
91
|
+
* ========================================
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
@Post('send-email')
|
|
95
|
+
async sendEmail(@Body() notification: EmailNotification) {
|
|
96
|
+
return this.studentHelpService.sendEmail(notification);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@Post('send-sms')
|
|
100
|
+
async sendSMS(@Body() body: { phoneNumber: string; message: string }) {
|
|
101
|
+
return this.studentHelpService.sendSMS(body.phoneNumber, body.message);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Post('send-webhook')
|
|
105
|
+
async sendWebhook(@Body() body: { url: string; data: any }) {
|
|
106
|
+
return this.studentHelpService.sendWebhook(body.url, body.data);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* ========================================
|
|
111
|
+
* 📄 VALIDATION ENDPOINTS
|
|
112
|
+
* ========================================
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
@Post('validate-email')
|
|
116
|
+
validateEmail(@Body() body: { email: string }): ValidationResult {
|
|
117
|
+
return this.studentHelpService.validateEmail(body.email);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Post('validate-password')
|
|
121
|
+
validatePasswordStrength(@Body() body: { password: string }): ValidationResult {
|
|
122
|
+
return this.studentHelpService.validatePasswordStrength(body.password);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@Post('validate-cpf')
|
|
126
|
+
validateCPF(@Body() body: { cpf: string }): ValidationResult {
|
|
127
|
+
return this.studentHelpService.validateCPF(body.cpf);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@Post('validate-phone')
|
|
131
|
+
validatePhoneNumber(@Body() body: { phone: string }): ValidationResult {
|
|
132
|
+
return this.studentHelpService.validatePhoneNumber(body.phone);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@Post('validate-url')
|
|
136
|
+
validateURL(@Body() body: { url: string }): ValidationResult {
|
|
137
|
+
return this.studentHelpService.validateURL(body.url);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* ========================================
|
|
142
|
+
* 📝 TRANSFORMATION ENDPOINTS
|
|
143
|
+
* ========================================
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
@Post('sanitize')
|
|
147
|
+
sanitizeString(@Body() body: { text: string }): Promise<{ sanitized: string }> {
|
|
148
|
+
const sanitized = this.studentHelpService.sanitizeString(body.text);
|
|
149
|
+
return Promise.resolve({ sanitized });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@Post('capitalize')
|
|
153
|
+
capitalize(@Body() body: { text: string }): Promise<{ result: string }> {
|
|
154
|
+
const result = this.studentHelpService.capitalize(body.text);
|
|
155
|
+
return Promise.resolve({ result });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@Post('to-slug')
|
|
159
|
+
toSlug(@Body() body: { text: string }): Promise<{ slug: string }> {
|
|
160
|
+
const slug = this.studentHelpService.toSlug(body.text);
|
|
161
|
+
return Promise.resolve({ slug });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@Post('format-currency')
|
|
165
|
+
formatCurrency(@Body() body: { amount: number; currency?: string }): Promise<{ formatted: string }> {
|
|
166
|
+
const formatted = this.studentHelpService.formatCurrency(body.amount, body.currency);
|
|
167
|
+
return Promise.resolve({ formatted });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@Post('format-date')
|
|
171
|
+
formatDate(@Body() body: { date: string; format?: string }): Promise<{ formatted: string }> {
|
|
172
|
+
const formatted = this.studentHelpService.formatDate(new Date(body.date), body.format);
|
|
173
|
+
return Promise.resolve({ formatted });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@Post('parse-json')
|
|
177
|
+
safeParseJSON(@Body() body: { json: string; defaultValue?: any }): Promise<{ result: any }> {
|
|
178
|
+
const result = this.studentHelpService.safeParseJSON(body.json, body.defaultValue);
|
|
179
|
+
return Promise.resolve({ result });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* ========================================
|
|
184
|
+
* 📊 EXPORT ENDPOINTS
|
|
185
|
+
* ========================================
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
@Post('export-csv')
|
|
189
|
+
generateCSV(@Body() body: { data: any[]; filename?: string }): ExportResult {
|
|
190
|
+
return this.studentHelpService.generateCSV(body.data, body.filename);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@Post('export-json')
|
|
194
|
+
generateJSON(@Body() body: { data: any; filename?: string }): ExportResult {
|
|
195
|
+
return this.studentHelpService.generateJSON(body.data, body.filename);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
@Post('generate-report')
|
|
199
|
+
generateReport(@Body() body: { title: string; content: any }): ExportResult {
|
|
200
|
+
return this.studentHelpService.generateReport(body.title, body.content);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* ========================================
|
|
205
|
+
* 📁 FILE UPLOAD ENDPOINTS
|
|
206
|
+
* ========================================
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
@Post('validate-file')
|
|
210
|
+
validateFileUpload(
|
|
211
|
+
@Body() body: { filename: string; size: number; allowedTypes?: string[] }
|
|
212
|
+
): FileUploadResult {
|
|
213
|
+
return this.studentHelpService.validateFileUpload(body.filename, body.size, body.allowedTypes);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@Post('safe-filename')
|
|
217
|
+
generateSafeFilename(@Body() body: { filename: string }): Promise<{ safeFilename: string }> {
|
|
218
|
+
const safeFilename = this.studentHelpService.generateSafeFilename(body.filename);
|
|
219
|
+
return Promise.resolve({ safeFilename });
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
@Post('process-image')
|
|
223
|
+
async processImage(
|
|
224
|
+
@Body() body: { filename: string; width?: number; height?: number }
|
|
225
|
+
): Promise<FileUploadResult> {
|
|
226
|
+
return this.studentHelpService.processImage(body.filename, body.width, body.height);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* ========================================
|
|
231
|
+
* 🧮 MATH & CONVERSION ENDPOINTS
|
|
232
|
+
* ========================================
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
@Post('calculate-percentage')
|
|
236
|
+
calculatePercentage(@Body() body: { value: number; total: number }): Promise<{ percentage: number }> {
|
|
237
|
+
const percentage = this.studentHelpService.calculatePercentage(body.value, body.total);
|
|
238
|
+
return Promise.resolve({ percentage });
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
@Post('calculate-discount')
|
|
242
|
+
calculateDiscount(
|
|
243
|
+
@Body() body: { originalPrice: number; discountPercent: number }
|
|
244
|
+
): Promise<{ finalPrice: number }> {
|
|
245
|
+
const finalPrice = this.studentHelpService.calculateDiscount(body.originalPrice, body.discountPercent);
|
|
246
|
+
return Promise.resolve({ finalPrice });
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
@Post('calculate-interest')
|
|
250
|
+
calculateCompoundInterest(
|
|
251
|
+
@Body() body: { principal: number; rate: number; time: number; compounds?: number }
|
|
252
|
+
): Promise<{ finalAmount: number }> {
|
|
253
|
+
const finalAmount = this.studentHelpService.calculateCompoundInterest(
|
|
254
|
+
body.principal,
|
|
255
|
+
body.rate,
|
|
256
|
+
body.time,
|
|
257
|
+
body.compounds
|
|
258
|
+
);
|
|
259
|
+
return Promise.resolve({ finalAmount });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
@Post('convert-temperature')
|
|
263
|
+
convertTemperature(
|
|
264
|
+
@Body() body: { value: number; from: 'C' | 'F' | 'K'; to: 'C' | 'F' | 'K' }
|
|
265
|
+
): Promise<{ result: number }> {
|
|
266
|
+
const result = this.studentHelpService.convertTemperature(body.value, body.from, body.to);
|
|
267
|
+
return Promise.resolve({ result });
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
@Post('convert-distance')
|
|
271
|
+
convertDistance(
|
|
272
|
+
@Body() body: { value: number; from: 'mm' | 'cm' | 'm' | 'km'; to: 'mm' | 'cm' | 'm' | 'km' }
|
|
273
|
+
): Promise<{ result: number }> {
|
|
274
|
+
const result = this.studentHelpService.convertDistance(body.value, body.from, body.to);
|
|
275
|
+
return Promise.resolve({ result });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
@Post('random-number')
|
|
279
|
+
randomNumber(@Body() body: { min: number; max: number }): Promise<{ number: number }> {
|
|
280
|
+
const number = this.studentHelpService.randomNumber(body.min, body.max);
|
|
281
|
+
return Promise.resolve({ number });
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
@Get('random-string')
|
|
285
|
+
randomString(@Query('length') length?: string): Promise<{ string: string }> {
|
|
286
|
+
const randomStr = this.studentHelpService.randomString(length ? parseInt(length) : undefined);
|
|
287
|
+
return Promise.resolve({ string: randomStr });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* ========================================
|
|
292
|
+
* 📋 USER MANAGEMENT ENDPOINTS
|
|
293
|
+
* ========================================
|
|
294
|
+
*/
|
|
295
|
+
|
|
296
|
+
@Get('user/:userId')
|
|
297
|
+
getUser(@Param('userId') userId: string) {
|
|
298
|
+
return this.studentHelpService.getUser(userId);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@Get('users')
|
|
302
|
+
getAllUsers() {
|
|
303
|
+
return this.studentHelpService.getAllUsers();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@Put('user/:userId')
|
|
307
|
+
async updateUser(@Param('userId') userId: string, @Body() body: any): Promise<AuthResponse> {
|
|
308
|
+
return this.studentHelpService.updateUser(userId, body);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@Delete('user/:userId')
|
|
312
|
+
async deleteUser(@Param('userId') userId: string): Promise<AuthResponse> {
|
|
313
|
+
return this.studentHelpService.deleteUser(userId);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* ========================================
|
|
318
|
+
* 🛠️ UTILITY ENDPOINTS
|
|
319
|
+
* ========================================
|
|
320
|
+
*/
|
|
321
|
+
|
|
322
|
+
@Post('sleep')
|
|
323
|
+
async sleep(@Body() body: { milliseconds: number }): Promise<{ message: string }> {
|
|
324
|
+
await this.studentHelpService.sleep(body.milliseconds);
|
|
325
|
+
return { message: 'Done waiting' };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
@Get('info')
|
|
329
|
+
getInfo() {
|
|
330
|
+
return this.studentHelpService.getInfo();
|
|
331
|
+
}
|
|
332
|
+
}
|