nazar-salary 3.4.6 → 3.4.7

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 (3) hide show
  1. package/index.d.ts +68 -1
  2. package/index.js +39 -2
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -453,6 +453,71 @@ declare module 'nazar-salary' {
453
453
  prices: Price[];
454
454
  }
455
455
 
456
+ /** Price with aggregated student/revenue stats — returned by getPricesList() only */
457
+ export interface PriceWithStats extends Price {
458
+ /** Gross sales attributed to this tariff (purchase_amount, before bank commission, verified and not) */
459
+ total_amount: number;
460
+ /** Distinct students with at least one active course on this tariff */
461
+ active_students: number;
462
+ /** Distinct students whose courses on this tariff are all closed */
463
+ inactive_students: number;
464
+ }
465
+
466
+ export interface PricesListResponse {
467
+ prices: PriceWithStats[];
468
+ }
469
+
470
+ export interface PriceStudent {
471
+ price_id: number;
472
+ price_name: string;
473
+ student_id: number;
474
+ first_name: string;
475
+ last_name: string;
476
+ phone: string;
477
+ completed_lessons: number;
478
+ total_lessons: number;
479
+ remaining_lessons: number;
480
+ /** Enrollment length in months */
481
+ enrollment_months: number;
482
+ /** Current tariff rate per lesson */
483
+ rate_per_lesson: number;
484
+ /** Gross payments attributed to this student on this tariff */
485
+ purchase_amount: number;
486
+ teacher_id: number | null;
487
+ teacher_name: string | null;
488
+ /** Owner of the student (student_history.owned_by) */
489
+ manager_id: number | null;
490
+ manager_name: string | null;
491
+ manager_role: 'manager' | 'admin' | null;
492
+ /** Whether the course itself is active */
493
+ is_active: boolean;
494
+ /** Student-level status, independent of the course */
495
+ student_status: 'active' | 'waiting' | 'cancelled';
496
+ group_name: string | null;
497
+ main_course: string;
498
+ student_history_id: number;
499
+ created_at: number;
500
+ }
501
+
502
+ export interface PriceStudentsResponse {
503
+ price: {
504
+ id: number;
505
+ name: string;
506
+ format: PriceFormat;
507
+ lesson_type: LessonType;
508
+ lessons_per_month: number;
509
+ duration_minutes: number;
510
+ rate_per_lesson: number;
511
+ };
512
+ pagination: {
513
+ page: number;
514
+ limit: number;
515
+ total: number;
516
+ pages: number;
517
+ };
518
+ students: PriceStudent[];
519
+ }
520
+
456
521
  export interface PriceHistoryItem {
457
522
  id: number;
458
523
  format: PriceFormat;
@@ -1703,7 +1768,9 @@ declare module 'nazar-salary' {
1703
1768
  updatePrice(priceId: number, data: UpdatePriceData): Promise<Price>;
1704
1769
  getPriceHistory(priceId: number): Promise<PriceHistoryResponse>;
1705
1770
  deletePrice(priceId: number): Promise<void>;
1706
- getPricesList(): Promise<PricesResponse>;
1771
+ getPricesList(): Promise<PricesListResponse>;
1772
+ getPriceStudents(priceId: number, params?: { status?: 'active' | 'inactive'; page?: number; limit?: number }): Promise<PriceStudentsResponse>;
1773
+ exportPriceStudents(prices?: number[] | string, options?: { status?: 'active' | 'inactive' }): Promise<ArrayBuffer>;
1707
1774
 
1708
1775
  // Student endpoints
1709
1776
  createStudent(data: CreateStudentData): Promise<CreateStudentResponse>;
package/index.js CHANGED
@@ -527,13 +527,30 @@ class SalaryAPI {
527
527
 
528
528
  /**
529
529
  * Get list of all prices (requireAuth - for managers)
530
- * Returns prices with latest history data
531
- * @returns {Promise<{prices: array}>}
530
+ * Returns prices with latest history data plus per-tariff stats:
531
+ * total_amount (gross sales), active_students, inactive_students
532
+ * @returns {Promise<PricesListResponse>}
532
533
  */
533
534
  async getPricesList() {
534
535
  return await this.client.get("/api/v1/price/");
535
536
  }
536
537
 
538
+ /**
539
+ * Get students of a tariff (requireAuth - for managers)
540
+ * One row per student — their latest course on that tariff
541
+ * @param {number} priceId - Price/tariff ID
542
+ * @param {object} [params]
543
+ * @param {'active'|'inactive'} [params.status] - Filter by course state
544
+ * @param {number} [params.page=1]
545
+ * @param {number} [params.limit=30] - Max 200
546
+ * @returns {Promise<PriceStudentsResponse>}
547
+ */
548
+ async getPriceStudents(priceId, params = {}) {
549
+ return await this.client.get(`/api/v1/price/${priceId}/students`, {
550
+ params,
551
+ });
552
+ }
553
+
537
554
  // ===== STUDENT ENDPOINTS =====
538
555
 
539
556
  /**
@@ -1050,6 +1067,26 @@ class SalaryAPI {
1050
1067
  });
1051
1068
  }
1052
1069
 
1070
+ /**
1071
+ * Export students of selected tariffs as an Excel file (requireAuth)
1072
+ * Single sheet, one row per student, with a tariff name column
1073
+ * @param {number[]|string} [prices] - Tariff IDs, e.g. [1,2,3] or "1,2,3". Omit for all tariffs
1074
+ * @param {object} [options]
1075
+ * @param {'active'|'inactive'} [options.status] - Filter by course state
1076
+ * @returns {Promise<ArrayBuffer>} Excel file
1077
+ */
1078
+ async exportPriceStudents(prices, options = {}) {
1079
+ const params = {};
1080
+ if (prices !== undefined && prices !== null) {
1081
+ params.prices = Array.isArray(prices) ? prices.join(",") : prices;
1082
+ }
1083
+ if (options.status !== undefined) params.status = options.status;
1084
+ return await this.client.get("/api/v1/price/students/export", {
1085
+ params,
1086
+ responseType: "arraybuffer",
1087
+ });
1088
+ }
1089
+
1053
1090
  /**
1054
1091
  * Export students by manager as Excel file (Admin only)
1055
1092
  * @param {number} managerId - Manager (МЗК) ID (required)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nazar-salary",
3
- "version": "3.4.6",
3
+ "version": "3.4.7",
4
4
  "description": "Frontend library for Nazar Salary API",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",